Permalink
Browse files

Merge pull request #11 from ypresto/fix_multiline_spec

Fixed printing 'ARRAY' on multiline token
  • Loading branch information...
2 parents 49bc2b9 + ef07e00 commit cd516de9c11f4fafb38dbd7c6848ea47d0f1ee8f @vti committed Nov 10, 2012
Showing with 35 additions and 9 deletions.
  1. +5 −8 lib/Text/Haml.pm
  2. +30 −1 t/multiline.t
View
@@ -248,6 +248,7 @@ sub parse {
my $tape = $self->tape;
my $level;
+ my @multiline_el_queue;
my @lines = split /\n/, $tmpl;
push @lines, '' if $tmpl =~ m/\n$/;
@lines = ('') if $tmpl eq "\n";
@@ -501,6 +502,7 @@ sub parse {
$el->{line} ||= $line . "$1|"; # XXX: is this really necessary?
push @$tape, $el;
+ push @multiline_el_queue, $el;
}
# Continue concatenation
@@ -513,20 +515,15 @@ sub parse {
# Normal text
else {
- # Terminate multiline tokens before current token
- if ($tape->[-1] && ref $tape->[-1]->{text} eq 'ARRAY') {
- $tape->[-1]->{text} = join(" ", @{$tape->[-1]->{text}});
- }
-
$el->{text} = $line if $line;
push @$tape, $el;
}
}
- # Terminate multiline tokens on the end of file
- if ($tape->[-1] && ref $tape->[-1]->{text} eq 'ARRAY') {
- $tape->[-1]->{text} = join(" ", @{$tape->[-1]->{text}});
+ # Finalize multilines
+ for my $el (@multiline_el_queue) {
+ $el->{text} = join(" ", @{$el->{text}});
}
}
View
@@ -5,7 +5,7 @@ use warnings;
use Text::Haml;
-use Test::More tests => 2;
+use Test::More tests => 4;
my $haml = Text::Haml->new;
@@ -43,3 +43,32 @@ is($output, <<'EOF');
<p>This is short.</p>
</whoo>
EOF
+
+$output = $haml->render(<<'EOF');
+%body
+ test
+ Wow.|
+ - my $bar = 17;
+ test2
+EOF
+is($output, <<'EOF');
+<body>
+ test
+ Wow.
+ test2
+</body>
+EOF
+
+$output = $haml->render(<<'EOF');
+%body
+ this is
+ a test for |
+ multiline token |
+ on last line. |
+EOF
+is($output, <<'EOF');
+<body>
+ this is
+ a test for multiline token on last line.
+</body>
+EOF

0 comments on commit cd516de

Please sign in to comment.