Merge branch 'stable'
Conflicts: lib/haml/precompiler.rb test/haml/engine_test.rb
This commit is contained in:
commit
1d98b31a75
|
@ -94,8 +94,8 @@ END
|
|||
end
|
||||
|
||||
precompile
|
||||
rescue Haml::Error
|
||||
$!.backtrace.unshift "#{@options[:filename]}:#{@index + $!.line_offset + @options[:line] - 1}" if @index
|
||||
rescue Haml::Error => e
|
||||
e.backtrace.unshift "#{@options[:filename]}:#{(e.line ? e.line + 1 : @index) + @options[:line] - 1}" if @index
|
||||
raise
|
||||
end
|
||||
|
||||
|
|
|
@ -5,13 +5,12 @@ module Haml
|
|||
|
||||
# By default, an error is taken to refer to the line of the template
|
||||
# that was being processed when the exception was raised.
|
||||
# However, if line_offset is non-zero, it's added to that line number
|
||||
# to get the line to report for the error.
|
||||
attr_reader :line_offset
|
||||
# However, if line is non-nil, it + 1 is used instead.
|
||||
attr_reader :line
|
||||
|
||||
def initialize(message = nil, line_offset = 0)
|
||||
def initialize(message = nil, line = nil)
|
||||
super(message)
|
||||
@line_offset = line_offset
|
||||
@line = line
|
||||
end
|
||||
# :startdoc:
|
||||
end
|
||||
|
|
|
@ -127,7 +127,7 @@ END
|
|||
end
|
||||
|
||||
if old_line.spaces != old_line.tabs * 2
|
||||
raise SyntaxError.new(<<END.strip, 1 + old_line.index - @index)
|
||||
raise SyntaxError.new(<<END.strip, old_line.index)
|
||||
#{old_line.spaces} space#{old_line.spaces == 1 ? ' was' : 's were'} used for indentation. Haml must be indented using two spaces.
|
||||
END
|
||||
end
|
||||
|
@ -138,7 +138,7 @@ END
|
|||
resolve_newlines
|
||||
|
||||
if !flat? && line.tabs - old_line.tabs > 1
|
||||
raise SyntaxError.new(<<END.strip, 2 + old_line.index - @index)
|
||||
raise SyntaxError.new(<<END.strip, line.index)
|
||||
#{line.spaces} spaces were used for indentation. Haml must be indented using two spaces.
|
||||
END
|
||||
end
|
||||
|
@ -245,7 +245,10 @@ END
|
|||
# Renders a block of text as plain text.
|
||||
# Also checks for an illegally opened block.
|
||||
def push_plain(text)
|
||||
raise SyntaxError.new("Illegal nesting: nesting within plain text is illegal.", 1) if @block_opened
|
||||
if @block_opened
|
||||
raise SyntaxError.new("Illegal nesting: nesting within plain text is illegal.", @next_line.index)
|
||||
end
|
||||
|
||||
push_text text
|
||||
end
|
||||
|
||||
|
@ -512,8 +515,8 @@ END
|
|||
attributes = parse_class_and_id(attributes)
|
||||
Buffer.merge_attrs(attributes, static_attributes) if static_attributes
|
||||
|
||||
raise SyntaxError.new("Illegal nesting: nesting within a self-closing tag is illegal.", 1) if @block_opened && self_closing
|
||||
raise SyntaxError.new("Illegal nesting: content can't be both given on the same line as %#{tag_name} and nested within it.", 1) if @block_opened && !value.empty?
|
||||
raise SyntaxError.new("Illegal nesting: nesting within a self-closing tag is illegal.", @next_line.index) if @block_opened && self_closing
|
||||
raise SyntaxError.new("Illegal nesting: content can't be both given on the same line as %#{tag_name} and nested within it.", @next_line.index) if @block_opened && !value.empty?
|
||||
raise SyntaxError.new("There's no Ruby code for #{action} to evaluate.") if parse && value.empty?
|
||||
raise SyntaxError.new("Self-closing tags can't have content.") if self_closing && !value.empty?
|
||||
|
||||
|
@ -580,7 +583,7 @@ END
|
|||
conditional << ">" if conditional
|
||||
|
||||
if @block_opened && !line.empty?
|
||||
raise SyntaxError.new('Illegal nesting: nesting within a tag that already has content is illegal.', 1)
|
||||
raise SyntaxError.new('Illegal nesting: nesting within a tag that already has content is illegal.', @next_line.index)
|
||||
end
|
||||
|
||||
open = "<!--#{conditional} "
|
||||
|
@ -601,7 +604,7 @@ END
|
|||
|
||||
# Renders an XHTML doctype or XML shebang.
|
||||
def render_doctype(line)
|
||||
raise SyntaxError.new("Illegal nesting: nesting within a header command is illegal.", 1) if @block_opened
|
||||
raise SyntaxError.new("Illegal nesting: nesting within a header command is illegal.", @next_line.index) if @block_opened
|
||||
doctype = text_for_doctype(line)
|
||||
push_text doctype if doctype
|
||||
end
|
||||
|
@ -671,7 +674,7 @@ END
|
|||
text, index = raw_next_line
|
||||
return unless text
|
||||
|
||||
line = Line.new text.strip, text.lstrip.chomp, text, index, *count_soft_tabs(text)
|
||||
line = Line.new text.strip, text.lstrip.chomp, text, index, *count_soft_tabs(text, index)
|
||||
|
||||
unless flat?
|
||||
if line.text.empty?
|
||||
|
@ -682,7 +685,7 @@ END
|
|||
handle_multiline(line)
|
||||
end
|
||||
|
||||
line
|
||||
@next_line = line
|
||||
end
|
||||
|
||||
def un_next_line(line)
|
||||
|
@ -747,11 +750,11 @@ END
|
|||
end
|
||||
|
||||
# Counts the tabulation of a line.
|
||||
def count_soft_tabs(line)
|
||||
def count_soft_tabs(line, index)
|
||||
spaces = line.index(/([^ ]|$)/)
|
||||
if line[spaces] == ?\t
|
||||
return nil if line.strip.empty?
|
||||
raise SyntaxError.new(<<END.strip, 2)
|
||||
raise SyntaxError.new(<<END.strip, index)
|
||||
A tab character was used for indentation. Haml must be indented using two spaces.
|
||||
Are you sure you have soft tabs enabled in your editor?
|
||||
END
|
||||
|
|
|
@ -38,6 +38,15 @@ END
|
|||
"= 'foo'\n-raise 'foo'" => ["foo", 2],
|
||||
"\n\n\n- raise 'foo'" => ["foo", 4],
|
||||
"%p foo |\n bar |\n baz |\nbop\n- raise 'foo'" => ["foo", 5],
|
||||
"foo\n\n\n bar" => ["Illegal nesting: nesting within plain text is illegal.", 4],
|
||||
"%p/\n\n bar" => ["Illegal nesting: nesting within a self-closing tag is illegal.", 3],
|
||||
"%p foo\n\n bar" => ["Illegal nesting: content can't be both given on the same line as %p and nested within it.", 3],
|
||||
"/ foo\n\n bar" => ["Illegal nesting: nesting within a tag that already has content is illegal.", 3],
|
||||
"!!!\n\n bar" => ["Illegal nesting: nesting within a header command is illegal.", 3],
|
||||
"foo\n\n\n\tbar" => [<<END.strip, 4],
|
||||
A tab character was used for indentation. Haml must be indented using two spaces.
|
||||
Are you sure you have soft tabs enabled in your editor?
|
||||
END
|
||||
}
|
||||
|
||||
User = Struct.new('User', :id)
|
||||
|
|
Loading…
Reference in New Issue