1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Haml] Make flush_merged_text a little more imperative and cleaner.

This commit is contained in:
Nathan Weizenbaum 2009-11-04 15:09:19 -08:00
parent 761d2c2598
commit 050d263fd2

View file

@ -306,15 +306,19 @@ END
def flush_merged_text
return if @to_merge.empty?
text, tab_change = @to_merge.inject(["", 0]) do |(str, mtabs), (type, val, tabs)|
str = ""
mtabs = 0
@to_merge.each do |type, val, tabs|
case type
when :text
[str << val.inspect[1...-1], mtabs + tabs]
str << val.inspect[1...-1]
mtabs += tabs
when :script
if mtabs != 0 && !@options[:ugly]
val = "_hamlout.adjust_tabs(#{mtabs}); " + val
end
[str << "\#{#{val}}", 0]
str << "\#{#{val}}"
mtabs = 0
else
raise SyntaxError.new("[HAML BUG] Undefined entry in Haml::Precompiler@to_merge.")
end
@ -322,9 +326,9 @@ END
@precompiled <<
if @options[:ugly]
"_hamlout.buffer << \"#{text}\";"
"_hamlout.buffer << \"#{str}\";"
else
"_hamlout.push_text(\"#{text}\", #{tab_change}, #{@dont_tab_up_next_text.inspect});"
"_hamlout.push_text(\"#{str}\", #{mtabs}, #{@dont_tab_up_next_text.inspect});"
end
@to_merge = []
@dont_tab_up_next_text = false