Class: Sass::Tree::RootNode
Overview
A static node that is the root node of the Sass document.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#template
readonly
The Sass template from which this node was created.
Attributes inherited from Node
#children, #filename, #has_children, #line, #options
Instance Method Summary collapse
-
#_to_s(*args) ⇒ String
protected
Computes the CSS corresponding to this Sass tree.
- #cssize(*args)
-
#cssize!(parent)
protected
Destructively converts this static Sass node into a static CSS node, and checks that there are no properties at root level.
-
#initialize(template) ⇒ RootNode
constructor
A new instance of RootNode.
-
#invalid_child?(child) ⇒ Boolean
protected
Returns false, because all nodes are allowed at the root of the document (properties are detected elsewhere post-mixin-resolution).
- #perform(environment)
- #perform!(environment)
- #to_s(*args)
-
#to_sass(opts = {}) ⇒ String
Converts a node to Sass code that will generate it.
-
#to_scss(opts = {}) ⇒ String
Converts a node to SCSS code that will generate it.
- #to_src(opts, fmt) protected
Methods inherited from Node
#<<, #==, #_cssize, #_perform, #balance, #children_to_src, #dasherize, #each, #invisible?, #perform_children, #render, #run_interp, #semi, #style
Constructor Details
#initialize(template) ⇒ RootNode
Returns a new instance of RootNode.
11 12 13 14 |
# File 'lib/sass/tree/root_node.rb', line 11
def initialize(template)
super()
@template = template
end
|
Instance Attribute Details
#template (readonly)
The Sass template from which this node was created
8 9 10 |
# File 'lib/sass/tree/root_node.rb', line 8
def template
@template
end
|
Instance Method Details
#_to_s(*args) ⇒ String (protected)
Computes the CSS corresponding to this Sass tree.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sass/tree/root_node.rb', line 97
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
|
#cssize(*args)
34 35 36 37 38 39 |
# File 'lib/sass/tree/root_node.rb', line 34
def cssize(*args)
super
rescue Sass::SyntaxError => e
e.sass_template = @template
raise e
end
|
#cssize!(parent) (protected)
Destructively converts this static Sass node into a static CSS node, and checks that there are no properties at root level.
84 85 86 87 88 89 90 |
# File 'lib/sass/tree/root_node.rb', line 84
def cssize!(parent)
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
|
#invalid_child?(child) ⇒ Boolean (protected)
Returns false, because all nodes are allowed at the root of the document (properties are detected elsewhere post-mixin-resolution).
113 114 115 |
# File 'lib/sass/tree/root_node.rb', line 113
def invalid_child?(child)
false
end
|
#perform(environment)
25 26 27 28 29 30 31 |
# File 'lib/sass/tree/root_node.rb', line 25
def perform(environment)
environment.options = @options if environment.options.nil? || environment.options.empty?
super
rescue Sass::SyntaxError => e
e.sass_template = @template
raise e
end
|
#perform!(environment)
42 43 44 45 |
# File 'lib/sass/tree/root_node.rb', line 42
def perform!(environment)
environment.options = @options if environment.options.nil? || environment.options.empty?
super
end
|
#to_s(*args)
17 18 19 20 21 22 |
# File 'lib/sass/tree/root_node.rb', line 17
def to_s(*args)
super
rescue Sass::SyntaxError => e
e.sass_template = @template
raise e
end
|
#to_sass(opts = {}) ⇒ String
Converts a node to Sass code that will generate it.
51 52 53 |
# File 'lib/sass/tree/root_node.rb', line 51
def to_sass(opts = {})
to_src(opts, :sass)
end
|
#to_scss(opts = {}) ⇒ String
Converts a node to SCSS code that will generate it.
59 60 61 |
# File 'lib/sass/tree/root_node.rb', line 59
def to_scss(opts = {})
to_src(opts, :scss)
end
|
#to_src(opts, fmt) (protected)
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sass/tree/root_node.rb', line 65
def to_src(opts, fmt)
Haml::Util.enum_cons(children + [nil], 2).map do |child, nxt|
child.send("to_#{fmt}", 0, opts) +
if nxt &&
(child.is_a?(CommentNode) && child.line + child.value.count("\n") + 1 == nxt.line) ||
(child.is_a?(ImportNode) && nxt.is_a?(ImportNode) && child.line + 1 == nxt.line)
""
else
"\n"
end
end.join.rstrip + "\n"
end
|