From edc209e51435c020310396376285c90e87dc32f8 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Wed, 4 Nov 2009 15:15:04 -0800 Subject: [PATCH] [Haml] Fix the problem added in 408da5f, re-enable the disabled optimizations. --- TODO | 3 --- lib/haml/precompiler.rb | 12 +++++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 96361f45..a6e3aa05 100644 --- a/TODO +++ b/TODO @@ -14,9 +14,6 @@ Lexer errors in particular are icky See in particular error changes made in c07b5c8 ** Haml - Fix problem added in 408da5f - Might be able to do this by fiddling with when we resolve_newlines - Might take larger-scale refactoring Support finer-grained HTML-escaping in filters Speed Make tags with dynamic attributes pre-render as much as possible diff --git a/lib/haml/precompiler.rb b/lib/haml/precompiler.rb index da1a8b51..64a90ec0 100644 --- a/lib/haml/precompiler.rb +++ b/lib/haml/precompiler.rb @@ -308,6 +308,7 @@ END str = "" mtabs = 0 + newlines = 0 @to_merge.each do |type, val, tabs| case type when :text @@ -317,8 +318,11 @@ END if mtabs != 0 && !@options[:ugly] val = "_hamlout.adjust_tabs(#{mtabs}); " + val end - str << "\#{#{val}}" + str << "\#{#{"\n" * newlines}#{val}}" mtabs = 0 + newlines = 0 + when :newlines + newlines += val else raise SyntaxError.new("[HAML BUG] Undefined entry in Haml::Precompiler@to_merge.") end @@ -330,6 +334,7 @@ END else "_hamlout.push_text(\"#{str}\", #{mtabs}, #{@dont_tab_up_next_text.inspect});" end + @precompiled << "\n" * newlines @to_merge = [] @dont_tab_up_next_text = false end @@ -1012,8 +1017,7 @@ END def resolve_newlines return unless @newlines > 0 - flush_merged_text unless @to_merge.all? {|type, *_| type == :text} - @precompiled << "\n" * @newlines + @to_merge << [:newlines, @newlines] @newlines = 0 end @@ -1037,6 +1041,8 @@ END when :script last[1].gsub!(/\(haml_temp, (.*?)\);$/, '(haml_temp.rstrip, \1);') rstrip_buffer! index - 1 + when :newlines + rstrip_buffer! index - 1 else raise SyntaxError.new("[HAML BUG] Undefined entry in Haml::Precompiler@to_merge.") end