2009-09-14 01:34:16 -07:00
|
|
|
module Sass
|
|
|
|
module Tree
|
|
|
|
# A static node that is the root node of the Sass document.
|
|
|
|
class RootNode < Node
|
2009-09-14 02:11:02 -07:00
|
|
|
# The Sass template from which this node was created
|
|
|
|
#
|
|
|
|
# @param template [String]
|
|
|
|
attr_reader :template
|
|
|
|
|
|
|
|
# @param template [String] The Sass template from which this node was created
|
|
|
|
def initialize(template)
|
|
|
|
super()
|
|
|
|
@template = template
|
|
|
|
end
|
|
|
|
|
|
|
|
# @see \{Node#to\_s}
|
|
|
|
def to_s(*args)
|
|
|
|
super
|
|
|
|
rescue Sass::SyntaxError => e
|
|
|
|
e.sass_template = @template
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
|
|
|
|
# @see \{Node#perform}
|
2009-11-21 10:07:59 -08:00
|
|
|
def perform(environment)
|
|
|
|
environment.options = @options if environment.options.nil? || environment.options.empty?
|
2009-09-14 02:11:02 -07:00
|
|
|
super
|
2009-11-24 22:25:48 -08:00
|
|
|
rescue Sass::SyntaxError => e
|
|
|
|
e.sass_template = @template
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
|
|
|
|
# @see \{Node#cssize}
|
|
|
|
def cssize(*args)
|
|
|
|
super
|
2009-09-14 02:11:02 -07:00
|
|
|
rescue Sass::SyntaxError => e
|
|
|
|
e.sass_template = @template
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
|
2009-09-14 01:34:16 -07:00
|
|
|
protected
|
|
|
|
|
2009-11-25 01:35:56 -08:00
|
|
|
# Destructively converts this static Sass node into a static CSS node,
|
|
|
|
# and checks that there are no properties at root level.
|
|
|
|
#
|
|
|
|
# @param parent [Node] ignored
|
|
|
|
def cssize!(parent)
|
2009-11-24 22:19:50 -08:00
|
|
|
super
|
|
|
|
return unless child = children.find {|c| c.is_a?(PropNode)}
|
|
|
|
message = "Properties aren't allowed at the root of a document." +
|
|
|
|
child.pseudo_class_selector_message
|
|
|
|
raise Sass::SyntaxError.new(message, :line => child.line)
|
|
|
|
end
|
|
|
|
|
2009-09-14 01:34:16 -07:00
|
|
|
# Computes the CSS corresponding to this Sass tree.
|
|
|
|
#
|
|
|
|
# @param args [Array] ignored
|
|
|
|
# @return [String] The resulting CSS
|
|
|
|
# @raise [Sass::SyntaxError] if some element of the tree is invalid
|
|
|
|
# @see Sass::Tree
|
|
|
|
def _to_s(*args)
|
|
|
|
result = String.new
|
|
|
|
children.each do |child|
|
|
|
|
next if child.invisible?
|
|
|
|
child_str = child.to_s(1)
|
|
|
|
result << child_str + (style == :compressed ? '' : "\n")
|
|
|
|
end
|
|
|
|
result.rstrip!
|
|
|
|
return "" if result.empty?
|
|
|
|
return result + "\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|