k0kubun / hamlit

High Performance Haml Implementation
https://rubygems.org/gems/hamlit
Other
981 stars 59 forks source link

`each` doesn't render #62

Closed timoschilling closed 8 years ago

timoschilling commented 8 years ago

Context: I use a hand build render way:

file = "foo.haml"
engine = Tilt[file] # => Hamlit::Template
template = engine.new(file, escape_html: false, escape_attrs: false)
template.render

Template:

%ul
  - (1..3).each do |i|
    %li

Result:

<ul></ul>
timoschilling commented 8 years ago

Some debugging informations: Based on the pervious code the compiled template source is:

_buf = []; _buf << ("<ul>\n".freeze);
;  (1..3).each do |i|; 
; _hamlit_compiler1 = ''; _hamlit_compiler1 << ("<li>".freeze); _hamlit_compiler2 = (i;
; ); _hamlit_compiler1 << ((_hamlit_compiler2).to_s); _hamlit_compiler1 << ("</li>\n".freeze); _hamlit_compiler1; end; _buf << ("</ul>\n".freeze); _buf = _buf.join

The same template rendered with the hamlit comandline tool results in: bundle exec hamlit compile file.haml

_buf = []; _buf << ("<ul>\n".freeze);
;  (1..3).each do |i|;
; _buf << ("<li>".freeze); _hamlit_compiler1 = (i;
; ); _buf << (::Hamlit::Utils.escape_html((_hamlit_compiler1))); _buf << ("</li>\n".freeze); end; _buf << ("</ul>\n".freeze); _buf = _buf.join

bundle exec hamlit render file.haml brings the expected result:

<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>

What am I doing wrong?

timoschilling commented 8 years ago

Both cases use hamlit 2.2.2

k0kubun commented 8 years ago

Are you using hamlit-block?

k0kubun commented 8 years ago

See https://github.com/k0kubun/hamlit/issues/53#issuecomment-170331999, https://github.com/k0kubun/hamlit/issues/53#issuecomment-170334043 and https://github.com/k0kubun/hamlit/issues/53#issuecomment-170524664 for detail. This may be not a bug within Hamlit but a feature of hamlit-block.

timoschilling commented 8 years ago

Yes, I use hamlit-block. I'm the guy way nick has written #53. ;)

timoschilling commented 8 years ago

I close this as double of hamlit/hamlit-block#1