hkoba / yatt_lite

YATT::Lite - Template with "use strict"
Other
5 stars 0 forks source link

newline after `<yatt:foreach>` should be omitted from template outputs #145

Closed hkoba closed 6 years ago

hkoba commented 6 years ago

Problem

This yatt template,

<yatt:foreach list="1..3">
&yatt:_;
</yatt:foreach>
<yatt:foreach list="1..3">
&yatt:_;
</yatt:foreach>

emits following currently:


1

2

3

1

2

3

This is not good to generate plain text.

hkoba commented 6 years ago

yatt source:

<ul>
  <yatt:foreach list="1..3">
  <li>&yatt:_;</li>
  </yatt:foreach>
</ul>

Generated code (current):

sub render_ { my ($this, $CON) = splice @_, 0, 2; my $body = $_[0]; print $CON (q|<ul>|, "\n");
  print $CON (q|  |); {; foreach  (1..3) { print $CON ("\n");
 print $CON (q|  <li>|, YATT::Lite::Util::escape($_), q|</li>|, "\n");
 print $CON (q|  |);} continue {} }; print $CON (q|
</ul>|); print $CON ("\n");}

Generated code with $cgen->cut_next_nl at the beginning of loop body generation:

sub render_ { my ($this, $CON) = splice @_, 0, 2; my $body = $_[0]; print $CON (q|<ul>|, "\n");
  print $CON (q|  |); {; foreach  (1..3) { print $CON (q|  <li>|, YATT::Lite::Util::escape($_), q|</li>|, "\n");
 print $CON (q|  |);} continue {} }; print $CON (q|
</ul>|); print $CON ("\n");}

Ideal result:

sub render_ { my ($this, $CON) = splice @_, 0, 2; my $body = $_[0]; print $CON (q|<ul>|, "\n");
   {; foreach  (1..3) { print $CON (q|  <li>|, YATT::Lite::Util::escape($_), q|</li>|, "\n");
  } continue {} }; print $CON (q|
</ul>|); }

To get above ideal result, macro_foreach should be allowed to get surrounding token lists. Hmm...