Class: Sass::Tree::Node

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
.ruby-sass/lib/sass/tree/node.rb

Overview

The abstract superclass of all parse-tree nodes.

Direct Known Subclasses

AtRootNode, CharsetNode, CommentNode, ContentNode, DebugNode, DirectiveNode, EachNode, ErrorNode, ExtendNode, ForNode, FunctionNode, IfNode, KeyframeRuleNode, MixinDefNode, MixinNode, PropNode, ReturnNode, RootNode, RuleNode, TraceNode, VariableNode, WarnNode, WhileNode

Direct Known Subclasses

AtRootNode, CharsetNode, CommentNode, ContentNode, DebugNode, DirectiveNode, EachNode, ErrorNode, ExtendNode, ForNode, FunctionNode, IfNode, KeyframeRuleNode, MixinDefNode, MixinNode, PropNode, ReturnNode, RootNode, RuleNode, TraceNode, VariableNode, WarnNode, WhileNode

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

#initializeNode

Returns a new instance of Node



91
92
93
94
95
# File '.ruby-sass/lib/sass/tree/node.rb', line 91

def initialize
  @children = []
  @filename = nil
  @options = nil
end

Constructor Details

#initializeNode

Returns a new instance of Node



91
92
93
94
95
# File '.ruby-sass/lib/sass/tree/node.rb', line 91

def initialize
  @children = []
  @filename = nil
  @options = nil
end

Instance Attribute Details

#childrenArray<Tree::Node>

The child nodes of this node.

Returns:



61
62
63
# File '.ruby-sass/lib/sass/tree/node.rb', line 61

def children
  @children
end

#filenameString

The name of the document on which this node appeared.

Returns:

  • (String)


114
115
116
# File '.ruby-sass/lib/sass/tree/node.rb', line 114

def filename
  @filename || (@options && @options[:filename])
end

#has_childrenBoolean

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. `{}`).

Returns:

  • (Boolean)


68
69
70
# File '.ruby-sass/lib/sass/tree/node.rb', line 68

def has_children
  @has_children
end

#lineInteger

The line of the document on which this node appeared.

Returns:

  • (Integer)


73
74
75
# File '.ruby-sass/lib/sass/tree/node.rb', line 73

def line
  @line
end

#options{Symbol => Object}

The options hash for the node. See the Sass options documentation.

Returns:

  • ({Symbol => Object})


89
90
91
# File '.ruby-sass/lib/sass/tree/node.rb', line 89

def options
  @options
end

#source_rangeSass::Source::Range

The source range in the document on which this node appeared.

Returns:



78
79
80
# File '.ruby-sass/lib/sass/tree/node.rb', line 78

def source_range
  @source_range
end

Class Method Details

.inherited(base) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File '.ruby-sass/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

Instance Method Details

#<<(child) ⇒ Object

Appends a child to the node.

Parameters:

Raises:



122
123
124
125
126
127
128
129
130
# File '.ruby-sass/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

#==(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.

Parameters:

  • other (Object)

    The object to compare with

Returns:

  • (Boolean)

    Whether or not this node and the other object are the same

See Also:



143
144
145
# File '.ruby-sass/lib/sass/tree/node.rb', line 143

def ==(other)
  self.class == other.class && other.children == children
end

#bubbles?Boolean

Whether or not this node bubbles up through RuleNodes.

Returns:

  • (Boolean)


225
226
227
# File '.ruby-sass/lib/sass/tree/node.rb', line 225

def bubbles?
  false
end

#cssString

Computes the CSS corresponding to this static CSS tree.

Returns:

  • (String)

    The resulting CSS

See Also:



165
166
167
# File '.ruby-sass/lib/sass/tree/node.rb', line 165

def css
  Sass::Tree::Visitors::ToCss.new.visit(self)
end

#css_with_sourcemap(String, Sass::Source::Map)

Computes the CSS corresponding to this static CSS tree, along with the respective source map.

Returns:

See Also:



174
175
176
177
178
# File '.ruby-sass/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

#deep_copyNode

Return a deep clone of this node. The child nodes are cloned, but options are not.

Returns:



218
219
220
# File '.ruby-sass/lib/sass/tree/node.rb', line 218

def deep_copy
  Sass::Tree::Visitors::DeepCopy.visit(self)
end

#each {|node| ... } ⇒ Object

Iterates through each node in the tree rooted at this node in a pre-order walk.

Yields:

  • node

Yield Parameters:

  • node (Node)

    a node in the tree



193
194
195
196
# File '.ruby-sass/lib/sass/tree/node.rb', line 193

def each
  yield self
  children.each {|c| c.each {|n| yield n}}
end

#inspectString

Returns a representation of the node for debugging purposes.

Returns:

  • (String)


183
184
185
186
# File '.ruby-sass/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

#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.

Returns:

  • (Boolean)


152
# File '.ruby-sass/lib/sass/tree/node.rb', line 152

def invisible?; false; end

#styleSymbol

The output style. See the Sass options documentation.

Returns:

  • (Symbol)


157
158
159
# File '.ruby-sass/lib/sass/tree/node.rb', line 157

def style
  @options[:style]
end

#to_sass(options = {}) ⇒ String

Converts a node to Sass code that will generate it.

Parameters:

  • options ({Symbol => Object}) (defaults to: {})

    An options hash (see CSS#initialize)

Returns:

  • (String)

    The Sass code corresponding to the node



202
203
204
# File '.ruby-sass/lib/sass/tree/node.rb', line 202

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.

Parameters:

  • options ({Symbol => Object}) (defaults to: {})

    An options hash (see CSS#initialize)

Returns:

  • (String)

    The Sass code corresponding to the node



210
211
212
# File '.ruby-sass/lib/sass/tree/node.rb', line 210

def to_scss(options = {})
  Sass::Tree::Visitors::Convert.visit(self, options, :scss)
end