Class: Sass::Tree::Node
- Inherits:
-
Object
- Object
- Sass::Tree::Node
- Includes:
- Enumerable
- Defined in:
- lib/sass/tree/node.rb
Overview
The abstract superclass of all parse-tree nodes.
Direct Known Subclasses
AtRootNode, CharsetNode, CommentNode, ContentNode, DebugNode, DirectiveNode, EachNode, ErrorNode, ExtendNode, ForNode, FunctionNode, IfNode, KeyframeRuleNode, MixinDefNode, MixinNode, PropNode, ReturnNode, RootNode, RuleNode, TraceNode, VariableNode, WarnNode, WhileNode
Instance Attribute Summary collapse
-
#children ⇒ Array<Tree::Node>
readonly
The child nodes of this node.
-
#filename ⇒ String
The name of the document on which this node appeared.
-
#has_children ⇒ Boolean
Whether or not this node has child nodes.
-
#line ⇒ Fixnum
The line of the document on which this node appeared.
-
#options ⇒ {Symbol => Object}
The options hash for the node.
-
#source_range ⇒ Sass::Source::Range
The source range in the document on which this node appeared.
Instance Method Summary collapse
-
#<<(child)
Appends a child to the node.
-
#==(other) ⇒ Boolean
Compares this node and another object (only other Nodes will be equal).
- #balance(*args) protected
-
#bubbles? ⇒ Boolean
Whether or not this node bubbles up through RuleNodes.
-
#css ⇒ String
Computes the CSS corresponding to this static CSS tree.
-
#css_with_sourcemap ⇒ (String, Sass::Source::Map)
Computes the CSS corresponding to this static CSS tree, along with the respective source map.
-
#deep_copy ⇒ Node
Return a deep clone of this node.
-
#each {|node| ... }
Iterates through each node in the tree rooted at this node in a pre-order walk.
-
#initialize ⇒ Node
constructor
A new instance of Node.
-
#inspect ⇒ String
Returns a representation of the node for debugging purposes.
-
#invisible? ⇒ Boolean
True if #to_s will return
nil
; that is, if the node shouldn't be rendered. -
#style ⇒ Symbol
The output style.
-
#to_sass(options = {}) ⇒ String
Converts a node to Sass code that will generate it.
-
#to_scss(options = {}) ⇒ String
Converts a node to SCSS code that will generate it.
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
91 92 93 |
# File 'lib/sass/tree/node.rb', line 91
def initialize
@children = []
end
|
Instance Attribute Details
#children ⇒ Array<Tree::Node>
The child nodes of this node.
61 62 63 |
# File 'lib/sass/tree/node.rb', line 61
def children
@children
end
|
#filename ⇒ String
The name of the document on which this node appeared.
112 113 114 |
# File 'lib/sass/tree/node.rb', line 112
def filename
@filename || (@options && @options[:filename])
end
|
#has_children ⇒ Boolean
Whether or not this node has child nodes.
This may be true even when #children is empty,
in which case this node has an empty block (e.g. {}
).
68 69 70 |
# File 'lib/sass/tree/node.rb', line 68
def has_children
@has_children
end
|
#line ⇒ Fixnum
The line of the document on which this node appeared.
73 74 75 |
# File 'lib/sass/tree/node.rb', line 73
def line
@line
end
|
#options ⇒ {Symbol => Object}
The options hash for the node. See the Sass options documentation.
89 90 91 |
# File 'lib/sass/tree/node.rb', line 89
def options
@options
end
|
#source_range ⇒ Sass::Source::Range
The source range in the document on which this node appeared.
78 79 80 |
# File 'lib/sass/tree/node.rb', line 78
def source_range
@source_range
end
|
Instance Method Details
#<<(child)
Appends a child to the node.
120 121 122 123 124 125 126 127 128 |
# File 'lib/sass/tree/node.rb', line 120
def <<(child)
return if child.nil?
if child.is_a?(Array)
child.each {|c| self << c}
else
self.has_children = true
@children << child
end
end
|
#==(other) ⇒ Boolean
Compares this node and another object (only other Sass::Tree::Nodes will be equal). This does a structural comparison; if the contents of the nodes and all the child nodes are equivalent, then the nodes are as well.
Only static nodes need to override this.
141 142 143 |
# File 'lib/sass/tree/node.rb', line 141
def ==(other)
self.class == other.class && other.children == children
end
|
#balance(*args) (protected)
231 232 233 234 235 |
# File 'lib/sass/tree/node.rb', line 231
def balance(*args)
res = Sass::Shared.balance(*args)
return res if res
raise Sass::SyntaxError.new("Unbalanced brackets.", :line => line)
end
|
#bubbles? ⇒ Boolean
Whether or not this node bubbles up through RuleNodes.
223 224 225 |
# File 'lib/sass/tree/node.rb', line 223
def bubbles?
false
end
|
#css ⇒ String
Computes the CSS corresponding to this static CSS tree.
163 164 165 |
# File 'lib/sass/tree/node.rb', line 163
def css
Sass::Tree::Visitors::ToCss.new.visit(self)
end
|
#css_with_sourcemap ⇒ (String, Sass::Source::Map)
Computes the CSS corresponding to this static CSS tree, along with the respective source map.
172 173 174 175 176 |
# File 'lib/sass/tree/node.rb', line 172
def css_with_sourcemap
visitor = Sass::Tree::Visitors::ToCss.new(:build_source_mapping)
result = visitor.visit(self)
return result, visitor.source_mapping
end
|
#deep_copy ⇒ Node
Return a deep clone of this node. The child nodes are cloned, but options are not.
216 217 218 |
# File 'lib/sass/tree/node.rb', line 216
def deep_copy
Sass::Tree::Visitors::DeepCopy.visit(self)
end
|
#each {|node| ... }
Iterates through each node in the tree rooted at this node in a pre-order walk.
191 192 193 194 |
# File 'lib/sass/tree/node.rb', line 191
def each
yield self
children.each {|c| c.each {|n| yield n}}
end
|
#inspect ⇒ String
Returns a representation of the node for debugging purposes.
181 182 183 184 |
# File 'lib/sass/tree/node.rb', line 181
def inspect
return self.class.to_s unless has_children
"(#{self.class} #{children.map {|c| c.inspect}.join(' ')})"
end
|
#invisible? ⇒ Boolean
True if #to_s will return nil
;
that is, if the node shouldn't be rendered.
Should only be called in a static tree.
150 |
# File 'lib/sass/tree/node.rb', line 150
def invisible?; false; end
|
#style ⇒ Symbol
The output style. See the Sass options documentation.
155 156 157 |
# File 'lib/sass/tree/node.rb', line 155
def style
@options[:style]
end
|
#to_sass(options = {}) ⇒ String
Converts a node to Sass code that will generate it.
200 201 202 |
# File 'lib/sass/tree/node.rb', line 200
def to_sass(options = {})
Sass::Tree::Visitors::Convert.visit(self, options, :sass)
end
|
#to_scss(options = {}) ⇒ String
Converts a node to SCSS code that will generate it.
208 209 210 |
# File 'lib/sass/tree/node.rb', line 208
def to_scss(options = {})
Sass::Tree::Visitors::Convert.visit(self, options, :scss)
end
|