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.
# Not available if the <tt>suppress_eval</tt> option is set to true.
# At the moment, this doesn't support access to variables
# defined by Ruby on Rails or Haml code.
# Embedded Ruby code is evaluated in the same context as the Haml template.
#
# [sass] Parses the filtered text with Sass to produce CSS output.
#

View File

@ -191,8 +191,9 @@ module Haml
include Base
lazy_require 'erb'
def render(text)
::ERB.new(text).result(binding)
def compile(precompiler, text)
src = ::ERB.new(text).src.sub(/^_erbout = '';/, "").gsub("\n", ';')
precompiler.send(:push_silent, src)
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;
</pre>
</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>
<li>Foo</li>
<li>Bar</li>

View File

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