Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #11 from ypresto/fix_multiline_spec

Fixed printing 'ARRAY' on multiline token
  • Loading branch information...
commit cd516de9c11f4fafb38dbd7c6848ea47d0f1ee8f 2 parents 49bc2b9 + ef07e00
Viacheslav Tykhanovskyi authored November 10, 2012
13  lib/Text/Haml.pm
@@ -248,6 +248,7 @@ sub parse {
248 248
     my $tape = $self->tape;
249 249
 
250 250
     my $level;
  251
+    my @multiline_el_queue;
251 252
     my @lines = split /\n/, $tmpl;
252 253
     push @lines, '' if $tmpl =~ m/\n$/;
253 254
     @lines = ('') if $tmpl eq "\n";
@@ -501,6 +502,7 @@ sub parse {
501 502
                 $el->{line} ||= $line . "$1|"; # XXX: is this really necessary?
502 503
 
503 504
                 push @$tape, $el;
  505
+                push @multiline_el_queue, $el;
504 506
             }
505 507
 
506 508
             # Continue concatenation
@@ -513,20 +515,15 @@ sub parse {
513 515
 
514 516
         # Normal text
515 517
         else {
516  
-            # Terminate multiline tokens before current token
517  
-            if ($tape->[-1] && ref $tape->[-1]->{text} eq 'ARRAY') {
518  
-                $tape->[-1]->{text} = join(" ", @{$tape->[-1]->{text}});
519  
-            }
520  
-
521 518
             $el->{text} = $line if $line;
522 519
 
523 520
             push @$tape, $el;
524 521
         }
525 522
     }
526 523
 
527  
-    # Terminate multiline tokens on the end of file
528  
-    if ($tape->[-1] && ref $tape->[-1]->{text} eq 'ARRAY') {
529  
-        $tape->[-1]->{text} = join(" ", @{$tape->[-1]->{text}});
  524
+    # Finalize multilines
  525
+    for my $el (@multiline_el_queue) {
  526
+        $el->{text} = join(" ", @{$el->{text}});
530 527
     }
531 528
 }
532 529
 
31  t/multiline.t
@@ -5,7 +5,7 @@ use warnings;
5 5
 
6 6
 use Text::Haml;
7 7
 
8  
-use Test::More tests => 2;
  8
+use Test::More tests => 4;
9 9
 
10 10
 my $haml = Text::Haml->new;
11 11
 
@@ -43,3 +43,32 @@ is($output, <<'EOF');
43 43
   <p>This is short.</p>
44 44
 </whoo>
45 45
 EOF
  46
+
  47
+$output = $haml->render(<<'EOF');
  48
+%body
  49
+  test
  50
+  Wow.|
  51
+  - my $bar = 17;
  52
+  test2
  53
+EOF
  54
+is($output, <<'EOF');
  55
+<body>
  56
+  test
  57
+  Wow.
  58
+  test2
  59
+</body>
  60
+EOF
  61
+
  62
+$output = $haml->render(<<'EOF');
  63
+%body
  64
+  this is
  65
+  a test for      |
  66
+  multiline token |
  67
+  on last line.   |
  68
+EOF
  69
+is($output, <<'EOF');
  70
+<body>
  71
+  this is
  72
+  a test for multiline token on last line.
  73
+</body>
  74
+EOF

0 notes on commit cd516de

Please sign in to comment.
Something went wrong with that request. Please try again.