Class: Sass::Tree::Node
- Inherits:
-
Object
- Object
- Sass::Tree::Node
- Includes:
- Enumerable
- Defined in:
- /var/www/sass-pages/.sass/lib/sass/tree/node.rb
Overview
The abstract superclass of all parse-tree nodes.
Direct Known Subclasses
CharsetNode, CommentNode, DebugNode, DirectiveNode, EachNode, ExtendNode, ForNode, FunctionNode, IfNode, MixinDefNode, MixinNode, PropNode, ReturnNode, RootNode, RuleNode, VariableNode, WarnNode, WhileNode
Instance Attribute Summary
- - (Array<Tree::Node>) children 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.
Instance Method Summary
- - <<(child) Appends a child to the node.
- - (Boolean) =(other) Compares this node and another object (only other Tree::Nodes will be equal).
- - balance(*args) protected
- - (Node) deep_copy Return a deep clone of this node.
- - (Tree::Node) do_extend(extends) Converts a static CSS tree (e.g. the output of Tree::Visitors::Cssize) into another static CSS tree, with the given extensions applied to all relevant RuleNodes.
- - each(&block) {|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.
-
- (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_s Computes the CSS corresponding to this static CSS tree.
- - (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
A new instance of Node
59 60 61 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 59
def initialize
@children = []
end
|
Instance Attribute Details
- (Array<Tree::Node>) children
The child nodes of this node.
34 35 36 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 34
def children
@children
end
|
- (String) filename
The name of the document on which this node appeared.
80 81 82 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 80
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. {}).
41 42 43 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 41
def has_children
@has_children
end
|
- (Fixnum) line
The line of the document on which this node appeared.
46 47 48 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 46
def line
@line
end
|
- ({Symbol => Object}) options
The options hash for the node. See the Sass options documentation.
57 58 59 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 57
def options
@options
end
|
Instance Method Details
- <<(child)
Appends a child to the node.
88 89 90 91 92 93 94 95 96 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 88
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 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.
109 110 111 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 109
def ==(other)
self.class == other.class && other.children == children
end
|
- balance(*args) (protected)
194 195 196 197 198 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 194
def balance(*args)
res = Sass::Shared.balance(*args)
return res if res
raise Sass::SyntaxError.new("Unbalanced brackets.", :line => line)
end
|
- (Node) deep_copy
Return a deep clone of this node. The child nodes are cloned, but options are not.
186 187 188 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 186
def deep_copy
Sass::Tree::Visitors::DeepCopy.visit(self)
end
|
- (Tree::Node) do_extend(extends)
TODO:
Link this to the reference documentation on @extend when such a thing exists.
Converts a static CSS tree (e.g. the output of Tree::Visitors::Cssize) into another static CSS tree, with the given extensions applied to all relevant RuleNodes.
147 148 149 150 151 152 153 154 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 147
def do_extend(extends)
node = dup
node.children = children.map {|c| c.do_extend(extends)}
node
rescue Sass::SyntaxError => e
e.modify_backtrace(:filename => filename, :line => line)
raise e
end
|
- each(&block) {|node| ... }
Iterates through each node in the tree rooted at this node in a pre-order walk.
161 162 163 164 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 161
def each(&block)
yield self
children.each {|c| c.each(&block)}
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.
118 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 118
def invisible?; false end
|
- (Symbol) style
The output style. See the Sass options documentation.
123 124 125 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 123
def style
@options[:style]
end
|
- (String?) to_s
Computes the CSS corresponding to this static CSS tree.
131 132 133 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 131
def to_s
Sass::Tree::Visitors::ToCss.visit(self)
end
|
- (String) to_sass(options = {})
Converts a node to Sass code that will generate it.
170 171 172 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 170
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.
178 179 180 |
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 178
def to_scss(options = {})
Sass::Tree::Visitors::Convert.visit(self, options, :scss)
end
|