Changeset 274

Show
Ignore:
Timestamp:
02/03/08 12:46:18 (10 months ago)
Author:
ingy
Message:
More refactoring and tests.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/ingy/Document-Tools/lib/Document/AST.pm

    r253 r274  
    11package Document::AST; 
     2use strict; 
     3use warnings; 
    24 
    35sub new { 
  • trunk/src/ingy/Document-Tools/lib/Document/AST/Tree.pm

    r231 r274  
    1111} 
    1212 
     13# XXX We changed $_[1] to be a hash instead of a tag. Just FYI... 
    1314sub begin_node { 
    1415    push @{$_[0]->{output}}, [$_[1], []]; 
  • trunk/src/ingy/Document-Tools/lib/Document/AST/Wikibyte.pm

    r254 r274  
    2626sub begin_node { 
    2727    my $self = shift; 
    28     my $tag = shift; 
     28    my $node = shift; 
     29    my $tag = $node->{type}; 
    2930    $tag =~ s/-.*//; 
    30     $self->{output} .= "+$tag\n"; 
     31    my $attributes = _get_attributes($node); 
     32    $self->{output} .= "+$tag$attributes\n"; 
    3133} 
    3234 
    3335sub end_node { 
    3436    my $self = shift; 
    35     my $tag = shift; 
     37    my $node = shift; 
     38    my $tag = $node->{type}; 
    3639    $tag =~ s/-.*//; 
    3740    $self->{output} .= "-$tag\n"; 
     
    4548} 
    4649 
     50sub _get_attributes { 
     51    my $node = shift; 
     52    return "" unless exists $node->{attributes}; 
     53    return join "", map { 
     54        qq{ $_="${\ $node->{attributes}->{$_}}"} 
     55    } sort keys %{$node->{attributes}}; 
     56} 
     57 
    47581; 
  • trunk/src/ingy/Document-Tools/lib/Document/Parser.pm

    r273 r274  
    167167sub subparse { 
    168168    my ($self, $func, $match, $type, $filter) = @_; 
    169     my $node_type =  
     169    $match->{type} =  
    170170        exists $self->{grammar}{$type}{type}  
    171171        ? $self->{grammar}{$type}{type} 
     
    178178    # attributes are passed as fields in $match. 
    179179 
    180     # TODO: Modify Makefile.PL to indicate change in API 
    181180    my $parser = $self->new( 
    182181        grammar => $self->{grammar}, 
     
    186185        : $match->{text}, 
    187186    ); 
    188     $self->{receiver}->begin_node($node_type, $match) 
    189       if $node_type
     187    $self->{receiver}->begin_node($match) 
     188      if $match->{type}
    190189    $parser->$func($type); 
    191190    $self->{receiver}->insert($parser->{receiver}); 
    192     $self->{receiver}->end_node($node_type
    193       if $node_type
     191    $self->{receiver}->end_node($match
     192      if $match->{type}
    194193} 
    195194 
  • trunk/src/ingy/Document-Tools/lib/Document/Parser/Creole.pm

    r273 r274  
    11package Document::Parser::Creole; 
    22use base 'Document::Parser'; 
    3 use XXX; 
    43 
    54sub create_grammar { 
     
    113112        }, 
    114113        wikilink => { 
    115             type => 'a', 
     114#            type => 'a', 
    116115            match => qr/\[\[(.*?)\]\]/, 
    117116            filter => sub { 
    118                 my $match = shift; 
    119                 if (s/(.*?)\s*\|\s*(.*)/$2/) { 
    120                     $match->{href} = $1; 
    121                 } 
     117                $_[0]->{attributes}{target} = 
     118                    s/(.*?)\s*\|\s*(.*)/$2/ ? $1 : $_; 
    122119            }, 
    123120        }, 
  • trunk/src/ingy/Document-Tools/lib/Document/Viewer/HTML.pm

    r273 r274  
    3939sub begin_node { 
    4040    my $self = shift; 
    41     my $tag = shift; 
    4241    my $node = shift; 
    43     if ($tag eq "a") { 
     42    my $tag = $node->{type}; 
     43    if ($tag eq "wikilink") { 
    4444        $self->{output} .= 
    4545            '<a href="' . 
    46             CGI::Util::escape($node->{href}) . 
     46            CGI::Util::escape($node->{attributes}{target}) . 
    4747            '">'; 
    4848        return; 
     
    5757sub end_node { 
    5858    my $self = shift; 
    59     my $tag = shift; 
     59    my $node = shift; 
     60    my $tag = $node->{type}; 
    6061    $tag =~ s/-.*//; 
    6162    return if ($tag =~ /^(br|hr)$/); 
     63    if ($tag eq "wikilink") { 
     64        $self->{output} .= '</a>'; 
     65        return; 
     66    } 
    6267    $self->{output} .= "</$tag>" . 
    6368        ($tag =~ /^(p|hr|table|ul|ol|h\d)$/ ? "\n" : ""); 
  • trunk/src/ingy/Document-Tools/t/data/links

    r273 r274  
    11=== Simple Wiki Link 
     2--- creole 
     3This is a [[Foo Bar]]. 
     4 
     5--- html 
     6<p>This is a <a href="Foo%20Bar">Foo Bar</a>.</p> 
     7 
     8--- wikibyte 
     9+p 
     10 This is a  
     11+wikilink target="Foo Bar" 
     12 Foo Bar 
     13-wikilink 
     14 . 
     15-p 
     16 
     17 
     18=== Simple Wiki Link With Label 
    219--- creole 
    320This is a [[Link Name|Link Text]]. 
     
    926+p 
    1027 This is a  
    11 +wikilink href="Link%20Name" 
     28+wikilink target="Link Name" 
    1229 Link Text 
    1330-wikilink 
     31 . 
    1432-p 
     33 
     34 
  • trunk/src/ingy/Document-Tools/t/links_html.t

    r273 r274  
    1 use t::TestDocumentTools tests => 1
     1use t::TestDocumentTools tests => 2
    22 
    33#no_diff;