Skip to content

Commit

Permalink
= and ~ with a Ruby block now works.
Browse files Browse the repository at this point in the history
git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@156 7063305b-7217-0410-af8c-cdc13e5119b9
  • Loading branch information
nex3 committed Nov 19, 2006
1 parent 2fb6003 commit 8a613d5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
31 changes: 23 additions & 8 deletions lib/haml/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ def process_line(count, line, index, block_opened)
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
Expand Down Expand Up @@ -362,18 +362,23 @@ def push_flat(text, spaces)
#
# 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
Expand All @@ -391,6 +396,8 @@ def close
close_tag value
when :flat
close_flat value
when :loud
close_loud value
end
end

Expand Down Expand Up @@ -421,9 +428,17 @@ def close_flat(in_tag)
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>.
Expand Down Expand Up @@ -453,7 +468,7 @@ def render_tag(line, index)

if value_exists
if parse
push_script(value, flattened, index)
push_script(value, flattened, false, index)
else
push_text(value)
end
Expand Down
1 change: 1 addition & 0 deletions test/results/standard.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion test/results/whitespace_handling.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

3 changes: 3 additions & 0 deletions test/rhtml/standard.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
2 changes: 2 additions & 0 deletions test/templates/standard.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 5 additions & 1 deletion test/templates/whitespace_handling.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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>"

0 comments on commit 8a613d5

Please sign in to comment.