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, ContentNode, DebugNode, DirectiveNode, EachNode, ExtendNode, ForNode, FunctionNode, IfNode, 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.
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.
-
#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_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.
60 61 62 |
# File 'lib/sass/tree/node.rb', line 60
def initialize
@children = []
end
|
Instance Attribute Details
#children ⇒ Array<Tree::Node>
The child nodes of this node.
35 36 37 |
# File 'lib/sass/tree/node.rb', line 35
def children
@children
end
|
#filename ⇒ String
The name of the document on which this node appeared.
81 82 83 |
# File 'lib/sass/tree/node.rb', line 81
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. {}
).
42 43 44 |
# File 'lib/sass/tree/node.rb', line 42
def has_children
@has_children
end
|
#line ⇒ Fixnum
The line of the document on which this node appeared.
47 48 49 |
# File 'lib/sass/tree/node.rb', line 47
def line
@line
end
|
#options ⇒ {Symbol => Object}
The options hash for the node. See the Sass options documentation.
58 59 60 |
# File 'lib/sass/tree/node.rb', line 58
def options
@options
end
|
Instance Method Details
#<<(child)
Appends a child to the node.
89 90 91 92 93 94 95 96 97 |
# File 'lib/sass/tree/node.rb', line 89
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.
110 111 112 |
# File 'lib/sass/tree/node.rb', line 110
def ==(other)
self.class == other.class && other.children == children
end
|
#balance(*args) (protected)
189 190 191 192 193 |
# File 'lib/sass/tree/node.rb', line 189
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.
181 182 183 |
# File 'lib/sass/tree/node.rb', line 181
def bubbles?
false
end
|
#deep_copy ⇒ Node
Return a deep clone of this node. The child nodes are cloned, but options are not.
174 175 176 |
# File 'lib/sass/tree/node.rb', line 174
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.
149 150 151 152 |
# File 'lib/sass/tree/node.rb', line 149
def each
yield self
children.each {|c| c.each {|n| yield n}}
end
|
#inspect ⇒ String
Returns a representation of the node for debugging purposes.
139 140 141 142 |
# File 'lib/sass/tree/node.rb', line 139
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.
119 |
# File 'lib/sass/tree/node.rb', line 119
def invisible?; false; end
|
#style ⇒ Symbol
The output style. See the Sass options documentation.
124 125 126 |
# File 'lib/sass/tree/node.rb', line 124
def style
@options[:style]
end
|
#to_s ⇒ String?
Computes the CSS corresponding to this static CSS tree.
132 133 134 |
# File 'lib/sass/tree/node.rb', line 132
def to_s
Sass::Tree::Visitors::ToCss.visit(self)
end
|
#to_sass(options = {}) ⇒ String
Converts a node to Sass code that will generate it.
158 159 160 |
# File 'lib/sass/tree/node.rb', line 158
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.
166 167 168 |
# File 'lib/sass/tree/node.rb', line 166
def to_scss(options = {})
Sass::Tree::Visitors::Convert.visit(self, options, :scss)
end
|