Class: Sass::Tree::Node

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

Overview

The abstract superclass of all parse-tree nodes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNode

Returns a new instance of Node.



59
60
61
# File 'lib/sass/tree/node.rb', line 59

def initialize
  @children = []
end

Instance Attribute Details

#childrenArray<Tree::Node>

The child nodes of this node.

Returns:



34
35
36
# File 'lib/sass/tree/node.rb', line 34

def children
  @children
end

#filenameString

The name of the document on which this node appeared.

Returns:

  • (String)


80
81
82
# File 'lib/sass/tree/node.rb', line 80

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)


41
42
43
# File 'lib/sass/tree/node.rb', line 41

def has_children
  @has_children
end

#lineFixnum

The line of the document on which this node appeared.

Returns:

  • (Fixnum)


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.

Returns:

  • ({Symbol => Object})


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.

Parameters:

Raises:



88
89
90
91
92
93
94
95
96
# File '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

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



109
110
111
# File 'lib/sass/tree/node.rb', line 109

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

#balance(*args) (protected)

Raises:

See Also:

  • Shared.balance


194
195
196
197
198
# File '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

#deep_copyNode

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

Returns:



186
187
188
# File 'lib/sass/tree/node.rb', line 186

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

#do_extend(extends) ⇒ Tree::Node

TODO:

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.

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 '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 {|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 'lib/sass/tree/node.rb', line 161

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.

Returns:

  • (Boolean)


118
# File 'lib/sass/tree/node.rb', line 118

def invisible?; false; end

#styleSymbol

The output style. See the Sass options documentation.

Returns:

  • (Symbol)


123
124
125
# File 'lib/sass/tree/node.rb', line 123

def style
  @options[:style]
end

#to_sString?

Computes the CSS corresponding to this static CSS tree.

Returns:

  • (String, nil)

    The resulting CSS

See Also:



131
132
133
# File 'lib/sass/tree/node.rb', line 131

def to_s
  Sass::Tree::Visitors::ToCss.visit(self)
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



170
171
172
# File 'lib/sass/tree/node.rb', line 170

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



178
179
180
# File 'lib/sass/tree/node.rb', line 178

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