2006-12-04 08:40:23 +00:00
|
|
|
module Sass
|
|
|
|
module Tree
|
|
|
|
class Node
|
2007-01-28 10:14:15 +00:00
|
|
|
attr_accessor :children
|
|
|
|
attr_accessor :line
|
2007-03-25 04:57:03 +00:00
|
|
|
attr_accessor :filename
|
2006-12-04 08:40:23 +00:00
|
|
|
|
2008-07-19 23:27:17 -04:00
|
|
|
def initialize(options)
|
|
|
|
@options = options
|
|
|
|
@style = options[:style]
|
2006-12-04 08:40:23 +00:00
|
|
|
@children = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def <<(child)
|
2007-03-18 04:15:50 +00:00
|
|
|
if msg = invalid_child?(child)
|
|
|
|
raise Sass::SyntaxError.new(msg, child.line)
|
|
|
|
end
|
2006-12-04 08:40:23 +00:00
|
|
|
@children << child
|
|
|
|
end
|
2008-04-07 23:09:17 -07:00
|
|
|
|
2006-12-04 08:40:23 +00:00
|
|
|
def to_s
|
|
|
|
result = String.new
|
|
|
|
children.each do |child|
|
2007-01-28 10:14:15 +00:00
|
|
|
if child.is_a? AttrNode
|
2007-01-31 06:38:23 +00:00
|
|
|
raise SyntaxError.new('Attributes aren\'t allowed at the root of a document.', child.line)
|
2007-08-10 05:21:56 +00:00
|
|
|
else
|
2007-09-07 09:00:58 +00:00
|
|
|
result << "#{child.to_s(1)}" + (@style == :compressed ? '' : "\n")
|
2007-03-25 04:57:03 +00:00
|
|
|
end
|
2006-12-04 08:40:23 +00:00
|
|
|
end
|
2007-09-07 09:00:58 +00:00
|
|
|
@style == :compressed ? result+"\n" : result[0...-1]
|
2006-12-04 08:40:23 +00:00
|
|
|
end
|
2007-03-18 04:15:50 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# This method should be overridden by subclasses to return an error message
|
|
|
|
# if the given child node is invalid,
|
|
|
|
# and false or nil otherwise.
|
|
|
|
def invalid_child?(child)
|
|
|
|
false
|
|
|
|
end
|
2006-12-04 08:40:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|