From b513b5231d947369ae1433b0eaf64ba81ae76e1b Mon Sep 17 00:00:00 2001 From: nex3 Date: Mon, 9 Apr 2007 17:03:12 +0000 Subject: [PATCH] Missed a few :suppress_eval things. Fixed in trunk, soon in stable. git-svn-id: svn://hamptoncatlin.com/haml/trunk@489 7063305b-7217-0410-af8c-cdc13e5119b9 --- lib/haml/engine.rb | 31 ++++++++++++------------ test/haml/engine_test.rb | 2 ++ test/haml/templates/eval_suppressed.haml | 4 +-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/haml/engine.rb b/lib/haml/engine.rb index d13e26b0..456dff30 100644 --- a/lib/haml/engine.rb +++ b/lib/haml/engine.rb @@ -203,9 +203,9 @@ END def do_precompile push_silent <<-END def _haml_render - @haml_is_haml = true - _hamlout = @haml_stack[-1] - _erbout = _hamlout.buffer + @haml_is_haml = true + _hamlout = @haml_stack[-1] + _erbout = _hamlout.buffer END old_line = nil @@ -267,8 +267,7 @@ END # Close all the open tags @template_tabs.times { close } - push_silent "@haml_is_haml = false" - push_silent "end" + push_silent "@haml_is_haml = false\nend\n" end # Processes and deals with lowering indentation. @@ -314,7 +313,7 @@ END sub_line = line[1..-1] unless sub_line[0] == SILENT_COMMENT mbk = mid_block_keyword?(line) - push_silent(sub_line, !mbk) + push_silent(sub_line, !mbk, true) if (@block_opened && !mbk) || line[1..-1].split(' ', 2)[0] == "case" push_and_tabulate([:script]) end @@ -426,12 +425,14 @@ END # Evaluates text in the context of @scope_object, but # does not output the result. - def push_silent(text, add_index = false) - if add_index - @precompiled << "@haml_lineno = #{@index}\n#{text}\n" - else - # Not really DRY, but probably faster - @precompiled << "#{text}\n" + def push_silent(text, add_index = false, can_suppress = false) + unless (can_suppress && options[:suppress_eval]) + if add_index + @precompiled << "@haml_lineno = #{@index}\n#{text}\n" + else + # Not really DRY, but probably faster + @precompiled << "#{text}\n" + end end end @@ -520,7 +521,7 @@ END # Closes a Ruby block. def close_block - push_silent "end" + push_silent "end", false, true @template_tabs -= 1 end @@ -544,7 +545,7 @@ END # Closes a loud Ruby block. def close_loud(command) - push_silent 'end' + push_silent 'end', false, true @precompiled << command @template_tabs -= 1 end @@ -593,7 +594,7 @@ END value_exists = !value.empty? attributes_hash = "{nil}" if attributes_hash.nil? || @options[:suppress_eval] - object_ref = "nil" unless object_ref + object_ref = "nil" if object_ref.nil? || @options[:suppress_eval] if !attributes.empty? && '.#'.include?(attributes) raise SyntaxError.new("Illegal element: classes and ids must have values. Use %div instead.") diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index df578fbf..a75ffe8a 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -57,7 +57,9 @@ class EngineTest < Test::Unit::TestCase def test_stop_eval assert_equal("", render("= 'Hello'", :suppress_eval => true)) + assert_equal("", render("- puts 'foo'", :suppress_eval => true)) assert_equal("
\n", render("#foo{:yes => 'no'}/", :suppress_eval => true)) + assert_equal("
\n", render("%div[1]/", :suppress_eval => true)) begin assert_equal("", render(":ruby\n puts 'hello'", :suppress_eval => true)) diff --git a/test/haml/templates/eval_suppressed.haml b/test/haml/templates/eval_suppressed.haml index 8b39aa8a..c912b8ee 100644 --- a/test/haml/templates/eval_suppressed.haml +++ b/test/haml/templates/eval_suppressed.haml @@ -1,5 +1,5 @@ = "not me!" = "nor me!" -- foo = "not even me!" -%p= foo +- puts "not even me!" +%p= "NO!" %h1 Me!