Evaluating the ERB filter in the template context as well.

This commit is contained in:
Nathan Weizenbaum 2008-02-23 01:37:35 -08:00
parent 491306ce52
commit a3388f9873
4 changed files with 29 additions and 18 deletions

View File

@ -564,8 +564,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
# #
# [erb] Parses the filtered text with ERB, like an RHTML template. # [erb] Parses the filtered text with ERB, like an RHTML template.
# Not available if the <tt>suppress_eval</tt> option is set to true. # Not available if the <tt>suppress_eval</tt> option is set to true.
# At the moment, this doesn't support access to variables # Embedded Ruby code is evaluated in the same context as the Haml template.
# defined by Ruby on Rails or Haml code.
# #
# [sass] Parses the filtered text with Sass to produce CSS output. # [sass] Parses the filtered text with Sass to produce CSS output.
# #

View File

@ -191,8 +191,9 @@ module Haml
include Base include Base
lazy_require 'erb' lazy_require 'erb'
def render(text) def compile(precompiler, text)
::ERB.new(text).result(binding) src = ::ERB.new(text).src.sub(/^_erbout = '';/, "").gsub("\n", ';')
precompiler.send(:push_silent, src)
end end
end end

View File

@ -36,26 +36,32 @@ This pre is pretty deeply&#x000A; nested.&#x000A; Does interpolation work
This one is, too.&#x000A;Nested, that is.&#x000A;&#x000A; This one is, too.&#x000A;Nested, that is.&#x000A;&#x000A;
</pre> </pre>
</p> </p>
<ul>
a <li>a</li>
b <li>b</li>
c <li>c</li>
d <li>d</li>
e <li>e</li>
f <li>f</li>
g <li>g</li>
h <li>h</li>
i <li>i</li>
j <li>j</li>
</ul>
<div class='res'>178</div>
<ul> <ul>
<li>Foo</li> <li>Foo</li>
<li>Bar</li> <li>Bar</li>

View File

@ -52,10 +52,15 @@
This one is, too. This one is, too.
Nested, that is. Nested, that is.
:erb - num = 10
<% 10.times do |c| %> %ul
<%= (c+97).chr %> :erb
<% end %> <% num.times do |c| %>
<li><%= (c+97).chr %></li>
<% end %>
<% res = 178 %>
.res= res
:markdown :markdown
* Foo * Foo