Class: Sass::Tree::Visitors::Base Abstract
- Inherits:
- Object
- Object
- Sass::Tree::Visitors::Base
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/visitors/base.rb
Overview
The abstract base class for Sass visitors. Visitors should extend this class, then implement visit_*
methods for each node they care about (e.g. visit_rule
for RuleNode or visit_for
for ForNode). These methods take the node in question as argument. They may yield
to visit the child nodes of the current node.
Note: due to the unusual nature of IfNode, special care must be taken to ensure that it is properly handled. In particular, there is no built-in scaffolding for dealing with the return value of @else
nodes.
Direct Known Subclasses
CheckNesting, Convert, Cssize, DeepCopy, Extend, Perform, SetOptions, ToCss
Class Method Summary (collapse)
- + (String) node_name(node) protected
Returns the name of a node as used in the
visit_*
method. - + (Object) visit(root)
Runs the visitor on a tree.
Instance Method Summary (collapse)
- - (Object) visit(node) protected
Runs the visitor on the given node.
- - (Array<Object>) visit_children(parent) protected
Visit the child nodes for a given node.
- - visit_if(node) protected
yield
s, then runs the visitor on the@else
clause if the node has one.
Class Method Details
+ (String) node_name(node) (protected)
Returns the name of a node as used in the visit_*
method.
59 60 61 62 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/visitors/base.rb', line 59
def self.node_name(node)
Sass::Util.deprecated(self, "Call node.class.node_name instead.")
node.class.node_name
end |
+ (Object) visit(root)
Runs the visitor on a tree.
23 24 25 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/visitors/base.rb', line 23
def self.visit(root)
new.send(:visit, root)
end |
Instance Method Details
- (Object) visit(node) (protected)
Runs the visitor on the given node. This can be overridden by subclasses that need to do something for each node.
34 35 36 37 38 39 40 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/visitors/base.rb', line 34
def visit(node)
if respond_to?(node.class.visit_method, true)
send(node.class.visit_method, node) {visit_children(node)}
else
visit_children(node)
end
end |
- (Array<Object>) visit_children(parent) (protected)
Visit the child nodes for a given node. This can be overridden by subclasses that need to do something with the child nodes’ return values.
This method is run when visit_*
methods yield
, and its return value is returned from the yield
.
51 52 53 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/visitors/base.rb', line 51
def visit_children(parent)
parent.children.map {|c| visit(c)}
end |
- visit_if(node) (protected)
yield
s, then runs the visitor on the @else
clause if the node has one. This exists to ensure that the contents of the @else
clause get visited.
66 67 68 69 70 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/visitors/base.rb', line 66
def visit_if(node)
yield
visit(node.else) if node.else
node
end |