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
CharsetNode, CommentNode, DebugNode, DirectiveNode, EachNode, ExtendNode, ForNode, FunctionNode, IfNode, MixinDefNode, MixinNode, PropNode, ReturnNode, RootNode, RuleNode, 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.
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
-
#deep_copy ⇒ Node
Return a deep clone of this node.
-
#do_extend(extends) ⇒ Tree::Node
Converts a static CSS tree (e.g. the output of Visitors::Cssize) into another static CSS tree, with the given extensions applied to all relevant RuleNodes.
-
#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.
-
#invisible? ⇒ Boolean
True if #to_s will return
nil
; that is, if the node shouldn't be rendered. -
#style ⇒ Symbol
The output style.
-
#to_s ⇒ String?
Computes the CSS corresponding to this static CSS tree.
-
#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.
59 60 61 |
# File 'lib/sass/tree/node.rb', line 59
def initialize
@children = []
end
|
Instance Attribute Details
#children ⇒ Array<Tree::Node>
The child nodes of this node.
34 35 36 |
# File 'lib/sass/tree/node.rb', line 34
def children
@children
end
|
#filename ⇒ String
The name of the document on which this node appeared.
80 81 82 |
# File 'lib/sass/tree/node.rb', line 80
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. {}
).
41 42 43 |
# File 'lib/sass/tree/node.rb', line 41
def has_children
@has_children
end
|
#line ⇒ Fixnum
The line of the document on which this node appeared.
46 47 48 |
# File 'lib/sass/tree/node.rb', line 46
def line
@line
end
|
#options ⇒ {Symbol => Object}
The options hash for the node. See the Sass options documentation.
57 58 59 |
# File '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 '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
|
#==(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.
109 110 111 |
# File '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 '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
|
#deep_copy ⇒ Node
Return a deep clone of this node. The child nodes are cloned, but options are not.
186 187 188 |
# File 'lib/sass/tree/node.rb', line 186
def deep_copy
Sass::Tree::Visitors::DeepCopy.visit(self)
end
|
#do_extend(extends) ⇒ Tree::Node
Link this to the reference documentation on @extend
when such a thing exists.
Converts a static CSS tree (e.g. the output of 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 '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 {|node| ... }
Iterates through each node in the tree rooted at this node in a pre-order walk.
161 162 163 164 |
# File 'lib/sass/tree/node.rb', line 161
def each(&block)
yield self
children.each {|c| c.each(&block)}
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.
118 |
# File 'lib/sass/tree/node.rb', line 118
def invisible?; false; end
|
#style ⇒ Symbol
The output style. See the Sass options documentation.
123 124 125 |
# File 'lib/sass/tree/node.rb', line 123
def style
@options[:style]
end
|
#to_s ⇒ String?
Computes the CSS corresponding to this static CSS tree.
131 132 133 |
# File 'lib/sass/tree/node.rb', line 131
def to_s
Sass::Tree::Visitors::ToCss.visit(self)
end
|
#to_sass(options = {}) ⇒ String
Converts a node to Sass code that will generate it.
170 171 172 |
# File 'lib/sass/tree/node.rb', line 170
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.
178 179 180 |
# File 'lib/sass/tree/node.rb', line 178
def to_scss(options = {})
Sass::Tree::Visitors::Convert.visit(self, options, :scss)
end
|