diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index 761c7a4e..36b29848 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -42,8 +42,8 @@ module Haml # SyntaxErrors have weird line reporting # when there's trailing whitespace, # which there is for Haml documents. - return exception.message.scan(/:(\d+)/)[0] if exception.is_a?(::SyntaxError) - exception.backtrace[0].scan(/:(\d+)/)[0] + return exception.message.scan(/:(\d+)/).first.first if exception.is_a?(::SyntaxError) + exception.backtrace[0].scan(/:(\d+)/).first.first end private diff --git a/lib/haml/filters.rb b/lib/haml/filters.rb index 6ffbddbc..a8aef764 100644 --- a/lib/haml/filters.rb +++ b/lib/haml/filters.rb @@ -225,7 +225,8 @@ END def compile(precompiler, text) return if precompiler.options[:suppress_eval] - src = ::ERB.new(text).src.sub(/^_erbout = '';/, "").gsub("\n", ';') + src = ::ERB.new(text).src.sub(/^#coding:.*?\n/, ''). + sub(/^_erbout = '';/, "").gsub("\n", ';') precompiler.send(:push_silent, src) end end diff --git a/lib/haml/helpers.rb b/lib/haml/helpers.rb index 749c1c6e..33512745 100644 --- a/lib/haml/helpers.rb +++ b/lib/haml/helpers.rb @@ -269,10 +269,9 @@ module Haml min_tabs = min_tabs > tabs ? tabs : min_tabs end - result = captured.map do |line| + captured.map do |line| line[min_tabs..-1] - end - result.to_s + end.join end end diff --git a/lib/haml/html.rb b/lib/haml/html.rb index 7ffe0720..3093fe1a 100644 --- a/lib/haml/html.rb +++ b/lib/haml/html.rb @@ -79,7 +79,7 @@ module Haml class ::Hpricot::Doc def to_haml(tabs = 0) output = '' - children.each { |child| output += child.to_haml(0) } + children.each { |child| output += child.to_haml(0) } if children output end end @@ -148,13 +148,9 @@ module Haml output += haml_attributes if attributes.length > 0 end - output += "\n" - - self.children.each do |child| - output += child.to_haml(tabs + 1) + (self.children || []).inject(output + "\n") do |output, child| + output + child.to_haml(tabs + 1) end - - output end private diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index ccb9fdc3..efb4779c 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -492,7 +492,7 @@ HAML def test_compile_error render("a\nb\n- fee)\nc") rescue Exception => e - assert_match(/^compile error\n\(test_compile_error\):3: syntax error/i, e.message) + assert_match(/\(test_compile_error\):3: syntax error/i, e.message) else assert(false, '"a\nb\n- fee)\nc" doesn\'t produce an exception!') diff --git a/test/haml/results/filters.xhtml b/test/haml/results/filters.xhtml index 6e192ec0..bd4809d2 100644 --- a/test/haml/results/filters.xhtml +++ b/test/haml/results/filters.xhtml @@ -52,11 +52,6 @@ This