Use symbols to mark the end of the document.
This commit is contained in:
parent
462ca56e3a
commit
0044d01be7
|
@ -79,7 +79,8 @@ module Haml
|
||||||
raise Haml::Error, "Invalid format #{@options[:format].inspect}"
|
raise Haml::Error, "Invalid format #{@options[:format].inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@template = (template.rstrip + "\n-#\n-#").split(/\r\n|\r|\n/)
|
# :eod is a special end-of-document marker
|
||||||
|
@template = (template.rstrip).split(/\r\n|\r|\n/) + [:eod, :eod]
|
||||||
@template_index = 0
|
@template_index = 0
|
||||||
@to_close_stack = []
|
@to_close_stack = []
|
||||||
@output_tabs = 0
|
@output_tabs = 0
|
||||||
|
|
|
@ -110,7 +110,9 @@ END
|
||||||
end.join(';') + ';'
|
end.join(';') + ';'
|
||||||
end
|
end
|
||||||
|
|
||||||
class Line < Struct.new(:text, :unstripped, :full, :index, :precompiler)
|
class Line < Struct.new(:text, :unstripped, :full, :index, :precompiler, :eod)
|
||||||
|
alias_method :eod?, :eod
|
||||||
|
|
||||||
def tabs
|
def tabs
|
||||||
line = self
|
line = self
|
||||||
@tabs ||= precompiler.instance_eval do
|
@tabs ||= precompiler.instance_eval do
|
||||||
|
@ -721,7 +723,13 @@ END
|
||||||
text, index = raw_next_line
|
text, index = raw_next_line
|
||||||
return unless text
|
return unless text
|
||||||
|
|
||||||
line = Line.new text.strip, text.lstrip.chomp, text, index, self
|
# :eod is a special end-of-document marker
|
||||||
|
line =
|
||||||
|
if text == :eod
|
||||||
|
Line.new '-#', '-#', '-#', index, self, true
|
||||||
|
else
|
||||||
|
Line.new text.strip, text.lstrip.chomp, text, index, self, false
|
||||||
|
end
|
||||||
|
|
||||||
# `flat?' here is a little outdated,
|
# `flat?' here is a little outdated,
|
||||||
# so we have to manually check if the previous line closes the flat block.
|
# so we have to manually check if the previous line closes the flat block.
|
||||||
|
@ -746,6 +754,7 @@ END
|
||||||
if is_multiline?(line.text)
|
if is_multiline?(line.text)
|
||||||
line.text.slice!(-1)
|
line.text.slice!(-1)
|
||||||
while new_line = raw_next_line.first
|
while new_line = raw_next_line.first
|
||||||
|
break if new_line == :eod
|
||||||
newline and next if new_line.strip.empty?
|
newline and next if new_line.strip.empty?
|
||||||
break unless is_multiline?(new_line.strip)
|
break unless is_multiline?(new_line.strip)
|
||||||
line.text << new_line.strip[0...-1]
|
line.text << new_line.strip[0...-1]
|
||||||
|
|
Loading…
Reference in New Issue