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.
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. {}
).
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.
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)
197 198 199 200 201 |
# File 'lib/sass/tree/node.rb', line 197
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.
187 188 189 190 191 |
# File 'lib/sass/tree/node.rb', line 187
def deep_copy
node = dup
node.children = children.map {|c| c.deep_copy}
node
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.
148 149 150 151 152 153 154 155 |
# File 'lib/sass/tree/node.rb', line 148
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.
162 163 164 165 |
# File 'lib/sass/tree/node.rb', line 162
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.
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.
171 172 173 |
# File 'lib/sass/tree/node.rb', line 171
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.
179 180 181 |
# File 'lib/sass/tree/node.rb', line 179
def to_scss(options = {})
Sass::Tree::Visitors::Convert.visit(self, options, :scss)
end
|