Changeset 223

Show
Ignore:
Timestamp:
04/08/07 01:10:15 (2 years ago)
Author:
ingy
Message:
 r3795@dhcp199:  ingy | 2007-04-08 10:10:59 +0900
 Refactor Doc::Parser
 
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/core/Spork/lib/Spork/Emitter/HTML.pm

    r203 r223  
    11package Spork::Emitter::HTML; 
    22use strict; 
    3 # use XXX; 
     3use XXX; 
    44 
    55sub new { bless { output => '' }, shift } 
     
    3535    for my $node (@$ast) { 
    3636        if (ref $node) { 
    37             my ($key) = keys %$node; 
     37            my ($key, $value) = @$node; 
    3838            $self->{output} .= $tags{"+$key"}; 
    3939            $self->{parent} = $key; 
    40             $self->emit($node->{$key}); 
     40            $self->emit($value); 
    4141            $self->{output} .= $tags{"-$key"}; 
    4242            next; 
     
    4444        my $text = $node; 
    4545        unless ($self->{parent} eq 'pre') { 
    46             $text =~ s/^( *)/" " x length($1)/gem; 
     46            $text =~ s/^( +)/" " x length($1)/gem; 
    4747            $text =~ s/\n/<br \/>\n/g; 
    4848        } 
  • trunk/src/plugins/ingy/Document-Formatter/lib/Document/AST.pm

    r218 r223  
    33sub new { 
    44    my $class = shift; 
    5     return bless { output => [], @_ }, ref($class) || $class; 
     5    my $self = bless { @_ }, ref($class) || $class; 
     6
     7 
     8sub init { 
     9    my $self = shift; 
     10    die "You need to override Document::AST::insert"; 
     11    # $self->{output} = []; 
    612} 
    713 
     
    1420    my $self = shift; 
    1521    my $ast = shift; 
    16     die
     22    die "You need to override Document::AST::insert"
    1723    # $self->{output} .= $ast->{output}; 
    1824} 
     
    2127    my $self = shift; 
    2228    my $tag = shift; 
    23     die
     29    die "You need to override Document::AST::begin_node"
    2430    # $self->{output} .= "+$tag\n"; 
    2531} 
     
    2834    my $self = shift; 
    2935    my $tag = shift; 
    30     die
     36    die "You need to override Document::AST::end_node"
    3137    # $self->{output} .= "-$tag\n"; 
    3238} 
  • trunk/src/plugins/ingy/Document-Formatter/lib/Document/AST/Tree.pm

    r218 r223  
    22use base 'Document::AST'; 
    33 
     4sub init { 
     5    my $self = shift; 
     6    $self->{output} = []; 
     7} 
     8 
    49sub insert { 
    5     my $self = shift; 
    6     my $ast = shift; 
    7     my $new = $ast->{output}; 
    8     my $current = $self->{output}[-1]; 
    9     my ($key) = keys %$current; 
    10     push @{$current->{$key}}, @$new; 
     10    push @{$_[0]{output}[-1][-1]}, @{$_[1]->{output}}; 
    1111} 
    1212 
    1313sub begin_node { 
    14     my $self = shift; 
    15     push @{$self->{output}}, {shift, []}; 
     14    push @{$_[0]->{output}}, [$_[1], []]; 
    1615} 
    1716 
    1817sub text_node { 
    19     my $self = shift; 
    20     push @{$self->{output}}, shift; 
     18    push @{$_[0]->{output}}, $_[1]; 
    2119} 
    2220 
  • trunk/src/plugins/ingy/Document-Formatter/lib/Document/Parser.pm

    r221 r223  
    1717    my $self = shift; 
    1818    $self->{input} ||= shift; 
     19    $self->{grammar} ||= $self->set_grammar; 
    1920    $self->{ast} ||= $self->set_ast; 
    20     $self->{grammar} ||= $self->set_grammar
     21    $self->{ast}->init
    2122    $self->parse_blocks('top'); 
    22     my $ast = $self->{ast}->content; 
    23     delete $self->{ast}; 
    24     return $ast; 
     23    return $self->{ast}->content; 
    2524} 
    2625 
  • trunk/test/spork-parser.t

    r218 r223  
    11#!/usr/bin/perl 
    22use lib 'lib'; 
    3 use Test::Base tests => 1
     3use Test::Base tests => 2
    44use Spork::Parser; 
    55use Spork::Emitter::HTML; 
     
    1414 
    1515__DATA__ 
    16 === Parse Spork Slide 
     16=== Format Spork Slide 
    1717--- spork format 
    1818== This is a test 
     
    4646</ul> 
    4747</div></div> 
    48 <p>Cool <b>stuff</b>&nbsp;is <i>here</i>.</p> 
     48<p>Cool <b>stuff</b> is <i>here</i>.</p> 
    4949<p>xxx<br /> 
    5050xxx</p> 
     
    5959} 
    6060</pre> 
     61=== Format Another Spork Slide 
     62--- spork format 
     63This is *bold* 
     64 
     65This *bold* is 
     66 
     67*Bold* is this 
     68--- html 
     69<p>This is <b>bold</b></p> 
     70<p>This <b>bold</b> is</p> 
     71<p><b>Bold</b> is this</p> 
     72