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

[Sass] Throw PropNode errors in #cssize, not #_to_s.

This commit is contained in:
Nathan Weizenbaum 2009-11-26 01:06:26 -08:00
parent 7678edd6c5
commit 6d2e93d3f1
2 changed files with 18 additions and 18 deletions

View file

@ -63,19 +63,7 @@ module Sass::Tree
#
# @param tabs [Fixnum] The level of indentation for the CSS
# @return [String] The resulting CSS
# @raise [Sass::SyntaxError] if the property uses invalid syntax
def _to_s(tabs)
if @options[:property_syntax] == :old && @prop_syntax == :new
raise Sass::SyntaxError.new("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.")
elsif @options[:property_syntax] == :new && @prop_syntax == :old
raise Sass::SyntaxError.new("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.")
elsif value[-1] == ?;
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no \";\" required at end-of-line).")
elsif value.empty?
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no value)." +
pseudo_class_selector_message)
end
to_return = ' ' * (tabs - 1 + self.tabs) + name + ":" +
(style == :compressed ? '' : ' ') + value + (style == :compressed ? "" : ";")
end
@ -84,10 +72,14 @@ module Sass::Tree
#
# @param parent [PropNode, nil] The parent node of this node,
# or nil if the parent isn't a {PropNode}
# @raise [Sass::SyntaxError] if the property uses invalid syntax
def _cssize(parent)
node = super
result = node.children.dup
result.unshift(node) if !node.value.empty? || node.children.empty?
if !node.value.empty? || node.children.empty?
node.send(:check!)
result.unshift(node)
end
result
end
@ -127,6 +119,19 @@ module Sass::Tree
private
def check!
if @options[:property_syntax] == :old && @prop_syntax == :new
raise Sass::SyntaxError.new("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.")
elsif @options[:property_syntax] == :new && @prop_syntax == :old
raise Sass::SyntaxError.new("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.")
elsif value[-1] == ?;
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no \";\" required at end-of-line).")
elsif value.empty?
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no value)." +
pseudo_class_selector_message)
end
end
def declaration
(@prop_syntax == :new ? "#{name}: #{value}" : ":#{name} #{value}").strip
end

View file

@ -32,11 +32,6 @@ MSG
"a\n b=c: d" => 'Invalid property: "b=c: d".',
"a: b" => 'Properties aren\'t allowed at the root of a document.',
":a b" => 'Properties aren\'t allowed at the root of a document.',
"a:" => 'Properties aren\'t allowed at the root of a document.',
":a" => <<MSG,
Properties aren't allowed at the root of a document.
If ":a" should be a selector, use "\\:a" instead.
MSG
"!" => 'Invalid variable: "!".',
"!a" => 'Invalid variable: "!a".',
"! a" => 'Invalid variable: "! a".',