Clean up a little Haml code.

This commit is contained in:
Nathan Weizenbaum 2008-05-28 19:48:39 -07:00
parent 62137499b5
commit 210429f06e
2 changed files with 9 additions and 12 deletions

View File

@ -73,13 +73,16 @@ module Haml
raise Haml::Error, "Invalid format #{@options[:format].inspect}"
end
@template = template.rstrip #String
@template = template.rstrip + "\n-#\n-#"
@to_close_stack = []
@output_tabs = 0
@template_tabs = 0
@index = 0
@flat_spaces = -1
@newlines = 0
@precompiled = ''
@merged_text = ''
@tab_change = 0
if @options[:filters]
warn <<END

View File

@ -109,28 +109,22 @@ END
end.join(';') + ';'
end
Line = Struct.new("Line", :text, :unstripped, :index, :spaces, :tabs)
Line = Struct.new(:text, :unstripped, :index, :spaces, :tabs)
def precompile
@precompiled = ''
@merged_text = ''
@tab_change = 0
old_line = Line.new
(@template + "\n-#\n-#").split(/\r\n|\r|\n/).each_with_index do |text, index|
@template.split(/\r\n|\r|\n/).each_with_index do |text, index|
line = Line.new text.strip, text.lstrip.chomp, index
line.spaces, line.tabs = count_soft_tabs(text)
if line.text.empty?
process_indent(old_line) if flat? && !old_line.text.empty?
unless flat?
newline
next
if flat?
push_flat(old_line)
old_line.text, old_line.unstripped, old_line.spaces = '', '', 0
end
push_flat(old_line)
old_line.text, old_line.unstripped, old_line.spaces = '', '', 0
newline
next
end