class Sass::Tree::Node
The abstract superclass of all parse-tree nodes.
Attributes
The child nodes of this node.
@return [Array<Tree::Node>]
The name of the document on which this node appeared.
@return [String]
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. ‘{}`).
@return [Boolean]
The line of the document on which this node appeared.
@return [Integer]
The options hash for the node. See {file:SASS_REFERENCE.md#Options the Sass
options documentation}.
@return [{Symbol => Object}]
The source range in the document on which this node appeared.
@return [Sass::Source::Range]
Public Class Methods
# File lib/sass/tree/node.rb, line 33 def self.inherited(base) node_name = base.name.gsub(/.*::(.*?)Node$/, '\\1').downcase base.instance_eval <<-METHODS # @return [Symbol] The name that is used for this node when visiting. def node_name :#{node_name} end # @return [Symbol] The method that is used on the visitor to visit nodes of this type. def visit_method :visit_#{node_name} end # @return [Symbol] The method name that determines if the parent is invalid. def invalid_child_method_name :"invalid_#{node_name}_child?" end # @return [Symbol] The method name that determines if the node is an invalid parent. def invalid_parent_method_name :"invalid_#{node_name}_parent?" end METHODS end
# File lib/sass/tree/node.rb, line 91 def initialize @children = [] @filename = nil @options = nil end
Public Instance Methods
Appends a child to the node.
@param child [Tree::Node, Array<Tree::Node>] The child node or nodes @raise [Sass::SyntaxError] if ‘child` is invalid
# File lib/sass/tree/node.rb, line 122 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
Compares this node and another object (only other {Tree::Node}s 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.
@param other [Object] The object to compare with @return [Boolean] Whether or not this node and the other object
are the same
@see Sass::Tree
# File lib/sass/tree/node.rb, line 143 def ==(other) self.class == other.class && other.children == children end
Whether or not this node bubbles up through RuleNodes.
@return [Boolean]
# File lib/sass/tree/node.rb, line 225 def bubbles? false end
@private
# File lib/sass/tree/node.rb, line 106 def children=(children) self.has_children ||= !children.empty? @children = children end
Computes the CSS
corresponding to this static CSS
tree.
@return [String] The resulting CSS
@see Sass::Tree
# File lib/sass/tree/node.rb, line 165 def css Sass::Tree::Visitors::ToCss.new.visit(self) end
Computes the CSS
corresponding to this static CSS
tree, along with the respective source map.
@return [(String, Sass::Source::Map
)] The resulting CSS
and the source map @see Sass::Tree
# File lib/sass/tree/node.rb, line 174 def css_with_sourcemap visitor = Sass::Tree::Visitors::ToCss.new(:build_source_mapping) result = visitor.visit(self) return result, visitor.source_mapping end
Return a deep clone of this node. The child nodes are cloned, but options are not.
@return [Node]
# File lib/sass/tree/node.rb, line 218 def deep_copy Sass::Tree::Visitors::DeepCopy.visit(self) end
Iterates through each node in the tree rooted at this node in a pre-order walk.
@yield node @yieldparam node [Node] a node in the tree
# File lib/sass/tree/node.rb, line 193 def each yield self children.each {|c| c.each {|n| yield n}} end
The name of the document on which this node appeared.
@return [String]
# File lib/sass/tree/node.rb, line 114 def filename @filename || (@options && @options[:filename]) end
Returns a representation of the node for debugging purposes.
@return [String]
# File lib/sass/tree/node.rb, line 183 def inspect return self.class.to_s unless has_children "(#{self.class} #{children.map {|c| c.inspect}.join(' ')})" end
True if {#to_s} will return ‘nil`; that is, if the node shouldn’t be rendered. Should only be called in a static tree.
@return [Boolean]
# File lib/sass/tree/node.rb, line 152 def invisible?; false; end
Sets the options hash for the node and all its children.
@param options [{Symbol => Object}] The options @see options
# File lib/sass/tree/node.rb, line 101 def options=(options) Sass::Tree::Visitors::SetOptions.visit(self, options) end
The output style. See {file:SASS_REFERENCE.md#Options the Sass
options documentation}.
@return [Symbol]
# File lib/sass/tree/node.rb, line 157 def style @options[:style] end
Converts a node to Sass
code that will generate it.
@param options [{Symbol => Object}] An options hash (see {Sass::CSS#initialize}) @return [String] The Sass
code corresponding to the node
# File lib/sass/tree/node.rb, line 202 def to_sass(options = {}) Sass::Tree::Visitors::Convert.visit(self, options, :sass) end
Converts a node to SCSS
code that will generate it.
@param options [{Symbol => Object}] An options hash (see {Sass::CSS#initialize}) @return [String] The Sass
code corresponding to the node
# File lib/sass/tree/node.rb, line 210 def to_scss(options = {}) Sass::Tree::Visitors::Convert.visit(self, options, :scss) end
Protected Instance Methods
@see Sass::Shared.balance
@raise [Sass::SyntaxError] if the brackets aren’t balanced
# File lib/sass/tree/node.rb, line 233 def balance(*args) res = Sass::Shared.balance(*args) return res if res raise Sass::SyntaxError.new("Unbalanced brackets.", :line => line) end