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

[Sass] Move detection of nodes only allowed at the root into Tree::Node.

This commit is contained in:
Nathan Weizenbaum 2009-12-21 20:30:56 -08:00
parent ad5d0ceb45
commit b6511d3ed1
3 changed files with 16 additions and 13 deletions

View file

@ -298,17 +298,6 @@ END
end
def validate_and_append_child(parent, child, line, root)
unless root
case child
when Tree::MixinDefNode
raise SyntaxError.new("Mixins may only be defined at the root of a document.",
:line => line.index)
when Tree::ImportNode
raise SyntaxError.new("Import directives may only be used at the root of a document.",
:line => line.index)
end
end
case child
when Array
child.each {|c| validate_and_append_child(parent, c, line, root)}

View file

@ -293,7 +293,8 @@ module Sass
# Returns an error message if the given child node is invalid,
# and false otherwise.
#
# By default, all child nodes are valid.
# By default, all child nodes except those only allowed at root level
# ({Tree::MixinDefNode}, {Tree::ImportNode}) are valid.
# This is expected to be overriden by subclasses
# for which some children are invalid.
#
@ -301,7 +302,12 @@ module Sass
# @return [Boolean, String] Whether or not the child node is valid,
# as well as the error message to display if it is invalid
def invalid_child?(child)
false
case child
when Tree::MixinDefNode
"Mixins may only be defined at the root of a document."
when Tree::ImportNode
"Import directives may only be used at the root of a document."
end
end
end
end

View file

@ -70,6 +70,14 @@ module Sass
return "" if result.empty?
return result + "\n"
end
# Returns false, because all nodes are allowed at the root of the document
# (properties are detected elsewhere post-mixin-resolution).
#
# @see Node#invalid_child?
def invalid_child?(child)
false
end
end
end
end