Class: Sass::Tree::Node

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
/var/www/sass-pages/.sass/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

Instance Method Summary

Constructor Details

- (Node) initialize

A new instance of Node



59
60
61
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 59

def initialize
  @children = []
end

Instance Attribute Details

- (Array<Tree::Node>) children

The child nodes of this node.

Returns:



34
35
36
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 34

def children
  @children
end

- (String) filename

The name of the document on which this node appeared.

Returns:

  • (String)


80
81
82
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 80

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

- (Boolean) has_children

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)


41
42
43
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 41

def has_children
  @has_children
end

- (Fixnum) line

The line of the document on which this node appeared.

Returns:

  • (Fixnum)


46
47
48
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 46

def line
  @line
end

- ({Symbol => Object}) options

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

Returns:

  • ({Symbol => Object})


57
58
59
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 57

def options
  @options
end

Instance Method Details

- <<(child)

Appends a child to the node.

Parameters:

Raises:



88
89
90
91
92
93
94
95
96
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 88

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

- (Boolean) ==(other)

Compares this node and another object (only other 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:

  • (Object) other — The object to compare with

Returns:

  • (Boolean) — Whether or not this node and the other object are the same

See Also:



109
110
111
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 109

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

- balance(*args) (protected)

Raises:

See Also:

  • Sass::Shared.balance


194
195
196
197
198
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 194

def balance(*args)
  res = Sass::Shared.balance(*args)
  return res if res
  raise Sass::SyntaxError.new("Unbalanced brackets.", :line => line)
end

- (Node) deep_copy

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

Returns:



186
187
188
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 186

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

- (Tree::Node) do_extend(extends)

TODO: Link this to the reference documentation on @extend when such a thing exists.

Converts a static CSS tree (e.g. the output of Tree::Visitors::Cssize) into another static CSS tree, with the given extensions applied to all relevant RuleNodes.

Parameters:

Returns:

  • (Tree::Node) — The resulting tree of static CSS nodes.

Raises:

  • (Sass::SyntaxError) — Only if there’s a programmer error and this is not a static CSS tree


147
148
149
150
151
152
153
154
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 147

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(&block) {|node| ... }

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


161
162
163
164
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 161

def each(&block)
  yield self
  children.each {|c| c.each(&block)}
end

- (Boolean) invisible?

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)


118
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 118

def invisible?; false end

- (Symbol) style

The output style. See the Sass options documentation.

Returns:

  • (Symbol)


123
124
125
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 123

def style
  @options[:style]
end

- (String?) to_s

Computes the CSS corresponding to this static CSS tree.

Returns:

  • (String, nil) — The resulting CSS

See Also:



131
132
133
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 131

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

- (String) to_sass(options = {})

Converts a node to Sass code that will generate it.

Parameters:

Returns:

  • (String) — The Sass code corresponding to the node


170
171
172
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 170

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

- (String) to_scss(options = {})

Converts a node to SCSS code that will generate it.

Parameters:

Returns:

  • (String) — The Sass code corresponding to the node


178
179
180
# File '/var/www/sass-pages/.sass/lib/sass/tree/node.rb', line 178

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