From 8a613d5cc03a240b557940b8cf29a3039e9a859b Mon Sep 17 00:00:00 2001 From: nex3 Date: Sun, 19 Nov 2006 22:20:28 +0000 Subject: [PATCH] = and ~ with a Ruby block now works. git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@156 7063305b-7217-0410-af8c-cdc13e5119b9 --- lib/haml/engine.rb | 31 ++++++++++++++++++------- test/results/standard.xhtml | 1 + test/results/whitespace_handling.xhtml | 6 ++++- test/rhtml/standard.rhtml | 3 +++ test/templates/standard.haml | 2 ++ test/templates/whitespace_handling.haml | 6 ++++- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lib/haml/engine.rb b/lib/haml/engine.rb index dc7c5380..67abaaa0 100644 --- a/lib/haml/engine.rb +++ b/lib/haml/engine.rb @@ -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 flattened is true, Haml::Helpers#find_and_flatten is run on # the result before it is added to @buffer - 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 text 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 @precompiled. @@ -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 diff --git a/test/results/standard.xhtml b/test/results/standard.xhtml index 706b29a8..400e0b35 100644 --- a/test/results/standard.xhtml +++ b/test/results/standard.xhtml @@ -31,6 +31,7 @@
  • f
  • with this text
    + hello -13 +
    + 13 + +
    + diff --git a/test/rhtml/standard.rhtml b/test/rhtml/standard.rhtml index 3892d6fb..a81053f6 100644 --- a/test/rhtml/standard.rhtml +++ b/test/rhtml/standard.rhtml @@ -38,6 +38,9 @@
  • <%= a %> <% end %>
    <%= @should_eval = "with this text" %>
    + <%= [ 104, 101, 108, 108, 111 ].map do |byte| + byte.chr + end %>