Make the Haml parser a little more flexible.
This commit is contained in:
parent
e8142f3f7b
commit
68104fd0bc
|
@ -73,7 +73,8 @@ module Haml
|
|||
raise Haml::Error, "Invalid format #{@options[:format].inspect}"
|
||||
end
|
||||
|
||||
@template = template.rstrip + "\n-#\n-#"
|
||||
@template = (template.rstrip + "\n-#\n-#").split(/\r\n|\r|\n/)
|
||||
@template_index = 0
|
||||
@to_close_stack = []
|
||||
@output_tabs = 0
|
||||
@template_tabs = 0
|
||||
|
|
|
@ -113,10 +113,7 @@ END
|
|||
|
||||
def precompile
|
||||
old_line = Line.new
|
||||
@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)
|
||||
|
||||
while line = next_line
|
||||
if line.text.empty?
|
||||
process_indent(old_line) if flat? && !old_line.text.empty?
|
||||
|
||||
|
@ -713,6 +710,23 @@ END
|
|||
@block_opened = false
|
||||
end
|
||||
|
||||
def raw_next_line
|
||||
text = @template.shift
|
||||
return unless text
|
||||
|
||||
index = @template_index
|
||||
@template_index += 1
|
||||
|
||||
return text, index
|
||||
end
|
||||
|
||||
def next_line
|
||||
text, index = raw_next_line
|
||||
return unless text
|
||||
|
||||
Line.new text.strip, text.lstrip.chomp, index, *count_soft_tabs(text)
|
||||
end
|
||||
|
||||
def contains_interpolation?(str)
|
||||
str.include?('#{')
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue