Class: Sass::Tree::Node
- Inherits:
- Object
- Object
- Sass::Tree::Node
- Includes:
- Enumerable
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/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)
- - (Array<Tree::Node>) children readonly
The child nodes of this node.
- - (String) filename
The name of the document on which this node appeared.
- - (Boolean) has_children
Whether or not this node has child nodes.
- - (Fixnum) line
The line of the document on which this node appeared.
- - ({Symbol => Object}) options
The options hash for the node.
- - (Sass::Source::Range) source_range
The source range in the document on which this node appeared.
Instance Method Summary (collapse)
- - <<(child)
Appends a child to the node.
- - (Boolean) ==(other)
Compares this node and another object (only other Nodes will be equal).
- - balance(*args) protected
- - (Boolean) bubbles?
Whether or not this node bubbles up through RuleNodes.
- - (String) css
Computes the CSS corresponding to this static CSS tree.
- - ((String, Sass::Source::Map)) css_with_sourcemap
Computes the CSS corresponding to this static CSS tree, along with the respective source map.
- - (Node) deep_copy
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.
- - (Node) initialize constructor
A new instance of Node.
- - (String) inspect
Returns a representation of the node for debugging purposes.
- - (Boolean) invisible?
True if #to_s will return
nil
; that is, if the node shouldn’t be rendered. - - (Symbol) style
The output style.
- - (String) to_sass(options = {})
Converts a node to Sass code that will generate it.
- - (String) to_scss(options = {})
Converts a node to SCSS code that will generate it.
Constructor Details
- (Node) initialize
Returns a new instance of Node
91 92 93 94 95 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 91
def initialize
@children = []
@filename = nil
@options = nil
end |
Instance Attribute Details
- (Array<Tree::Node>) children
The child nodes of this node.
61 62 63 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 61
def children
@children
end |
- (String) filename
The name of the document on which this node appeared.
114 115 116 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 114
def filename
@filename || (@options && @options[:filename])
end |
- (Boolean) has_children
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 '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 68
def has_children
@has_children
end |
- (Fixnum) line
The line of the document on which this node appeared.
73 74 75 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 73
def line
@line
end |
- ({Symbol => Object}) options
The options hash for the node. See the Sass options documentation.
89 90 91 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 89
def options
@options
end |
- (Sass::Source::Range) source_range
The source range in the document on which this node appeared.
78 79 80 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 78
def source_range
@source_range
end |
Instance Method Details
- <<(child)
Appends a child to the node.
122 123 124 125 126 127 128 129 130 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 122
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 |
- (Boolean) ==(other)
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.
143 144 145 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 143
def ==(other)
self.class == other.class && other.children == children
end |
- balance(*args) (protected)
233 234 235 236 237 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 233
def balance(*args)
res = Sass::Shared.balance(*args)
return res if res
raise Sass::SyntaxError.new("Unbalanced brackets.", :line => line)
end |
- (Boolean) bubbles?
Whether or not this node bubbles up through RuleNodes.
225 226 227 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 225
def bubbles?
false
end |
- (String) css
Computes the CSS corresponding to this static CSS tree.
165 166 167 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 165
def css
Sass::Tree::Visitors::ToCss.new.visit(self)
end |
- ((String, Sass::Source::Map)) css_with_sourcemap
Computes the CSS corresponding to this static CSS tree, along with the respective source map.
174 175 176 177 178 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 174
def css_with_sourcemap
visitor = Sass::Tree::Visitors::ToCss.new(:build_source_mapping)
result = visitor.visit(self)
return result, visitor.source_mapping
end |
- (Node) deep_copy
Return a deep clone of this node. The child nodes are cloned, but options are not.
218 219 220 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 218
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.
193 194 195 196 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 193
def each
yield self
children.each {|c| c.each {|n| yield n}}
end |
- (String) inspect
Returns a representation of the node for debugging purposes.
183 184 185 186 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 183
def inspect
return self.class.to_s unless has_children
"(#{self.class} #{children.map {|c| c.inspect}.join(' ')})"
end |
- (Boolean) invisible?
True if #to_s will return nil
; that is, if the node shouldn’t be rendered. Should only be called in a static tree.
152 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 152
def invisible?; false; end |
- (Symbol) style
The output style. See the Sass options documentation.
157 158 159 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 157
def style
@options[:style]
end |
- (String) to_sass(options = {})
Converts a node to Sass code that will generate it.
202 203 204 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 202
def to_sass(options = {})
Sass::Tree::Visitors::Convert.visit(self, options, :sass)
end |
- (String) to_scss(options = {})
Converts a node to SCSS code that will generate it.
210 211 212 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/node.rb', line 210
def to_scss(options = {})
Sass::Tree::Visitors::Convert.visit(self, options, :scss)
end |