= and ~ with a Ruby block now works.

git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@156 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2006-11-19 22:20:28 +00:00
parent 2fb6003f7f
commit 8a613d5cc0
6 changed files with 39 additions and 10 deletions

View File

@ -216,9 +216,9 @@ module Haml
when COMMENT
render_comment(line)
when SCRIPT
push_script(line[1..-1], false, index)
push_script(line[1..-1], false, block_opened, index)
when FLAT_SCRIPT
push_flat_script(line[1..-1], index)
push_flat_script(line[1..-1], block_opened, index)
when SILENT_SCRIPT
sub_line = line[1..-1]
unless sub_line[0] == SILENT_COMMENT
@ -362,18 +362,23 @@ module Haml
#
# If <tt>flattened</tt> is true, Haml::Helpers#find_and_flatten is run on
# the result before it is added to <tt>@buffer</tt>
def push_script(text, flattened, index)
def push_script(text, flattened, block_opened, index)
unless options[:suppress_eval]
push_silent("haml_temp = #{text}", index)
@precompiled << "haml_temp = _hamlout.push_script(haml_temp, #{@output_tabs}, #{flattened})\n"
out = "haml_temp = _hamlout.push_script(haml_temp, #{@output_tabs}, #{flattened})\n"
if block_opened
push_and_tabulate([:loud, out])
else
@precompiled << out
end
end
end
# Causes <tt>text</tt> to be evaluated, and Haml::Helpers#find_and_flatten
# to be run on it afterwards.
def push_flat_script(text, index)
def push_flat_script(text, block_opened, index)
unless text.empty?
push_script(text, true, index)
push_script(text, true, block_opened, index)
else
start_flat(false)
end
@ -391,6 +396,8 @@ module Haml
close_tag value
when :flat
close_flat value
when :loud
close_loud value
end
end
@ -421,9 +428,17 @@ module Haml
if in_tag
close
else
push_silent("_erbout.concat('\n')")
push_silent('_erbout.concat("\n")')
@template_tabs -= 1
end
end
# Closes a loud Ruby block.
def close_loud(command)
push_silent "end"
@precompiled << command
@template_tabs -= 1
end
# Parses a line that will render as an XHTML tag, and adds the code that will
# render that tag to <tt>@precompiled</tt>.
@ -453,7 +468,7 @@ module Haml
if value_exists
if parse
push_script(value, flattened, index)
push_script(value, flattened, false, index)
else
push_text(value)
end

View File

@ -31,6 +31,7 @@
<li>f</li>
</ul>
<div class='of_divs_with_underscore' id='combo'>with this text</div>
hello
<div class='footer'>
<strong class='shout'>
This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.

View File

@ -40,4 +40,8 @@
<strong>indeed!</strong>
</textarea>
</div>
13
<div class='foo'>
13
<textarea>&#x000A;a&#x000A;</textarea><textarea>&#x000A;b&#x000A;</textarea><textarea>&#x000A;c&#x000A;</textarea>
</div>

View File

@ -38,6 +38,9 @@
<li><%= a %>
<% end %>
<div class='of_divs_with_underscore' id='combo'><%= @should_eval = "with this text" %></div>
<%= [ 104, 101, 108, 108, 111 ].map do |byte|
byte.chr
end %>
<div class='footer'>
<strong class='shout'>
<%= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.\n" +

View File

@ -34,5 +34,7 @@
- ('a'..'f').each do |a|
%li= a
#combo.of_divs_with_underscore= @should_eval = "with this text"
= [ 104, 101, 108, 108, 111 ].map do |byte|
- byte.chr
.footer
%strong.shout= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works"

View File

@ -56,4 +56,8 @@
to
http://www.network-science.de/ascii/
%strong indeed!
~ 13
.foo
~ 13
~ ['a', 'b', 'c'].map do |a|
- "<textarea>\n#{a}\n</textarea>"