class Sass::Tree::Node

The abstract superclass of all parse-tree nodes.

def <<(child)

Other tags:
    See: #invalid_child? -

Raises:
  • (Sass::SyntaxError) - if `child` is invalid

Parameters:
  • child (Tree::Node) -- The child node
def <<(child)
  return if child.nil?
  check_child! child
  self.has_children = true
  @children << child
end

def ==(other)

Other tags:
    See: Sass::Tree -

Returns:
  • (Boolean) - Whether or not this node and the other object

Parameters:
  • other (Object) -- The object to compare with
def ==(other)
  self.class == other.class && other.children == children
end

def _cssize(extends, parent)

Other tags:
    See: Sass::Tree -
    See: #cssize -

Raises:
  • (Sass::SyntaxError) - if some element of the tree is invalid

Returns:
  • (Tree::Node, Array) - The resulting static CSS nodes

Parameters:
  • parent (Node, nil) -- The parent node of this node.
  • extends (Haml::Util::SubsetMap{Selector::Simple => Selector::Sequence}) --
def _cssize(extends, parent)
  node = dup
  node.cssize!(extends, parent)
  node
end

def _perform(environment)

Other tags:
    See: Sass::Tree -
    See: #perform -

Returns:
  • (Tree::Node, Array) - The resulting static nodes

Parameters:
  • environment (Sass::Environment) -- The lexical environment containing
def _perform(environment)
  node = dup
  node.perform!(environment)
  node
end

def _to_s

Other tags:
    See: Sass::Tree -
    See: #to_s -

Returns:
  • (String, nil) - The resulting CSS

Parameters:
  • args (Array) -- ignored
def _to_s
  raise NotImplementedError.new("All static-node subclasses of Sass::Tree::Node must override #_to_s or #to_s.")
end

def balance(*args)

Raises:
  • (Sass::SyntaxError) - if the brackets aren't balanced

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

def check_child!(child)

Other tags:
    See: #invalid_child? -

Raises:
  • (Sass::SyntaxError) - if `child` is invalid

Parameters:
  • child (Tree::Node) -- The child node
def check_child!(child)
  if msg = invalid_child?(child)
    raise Sass::SyntaxError.new(msg, :line => child.line)
  end
end

def children=(children)

Other tags:
    Private: -
def children=(children)
  self.has_children ||= !children.empty?
  @children = children
end

def children_to_src(tabs, opts, fmt)

Returns:
  • (String) - The Sass or SCSS code corresponding to the children

Parameters:
  • fmt (Symbol) -- `:sass` or `:scss`
  • opts ({Symbol => Object}) -- An options hash (see {Sass::CSS#initialize})
  • tabs (Fixnum) -- The amount of tabulation to use for the Sass code
def children_to_src(tabs, opts, fmt)
  return fmt == :sass ? "\n" : " {}\n" if children.empty?
  (fmt == :sass ? "\n" : " {\n") +
    children.map {|c| c.send("to_#{fmt}", tabs + 1, opts)}.join.rstrip +
    (fmt == :sass ? "\n" : " }\n")
end

def cssize(extends, parent = nil)

Other tags:
    See: Sass::Tree -

Raises:
  • (Sass::SyntaxError) - if some element of the tree is invalid

Returns:
  • (Tree::Node) - The resulting tree of static nodes

Parameters:
  • parent (Node, nil) -- The parent node of this node.
  • extends (Haml::Util::SubsetMap{Selector::Simple => Selector::Sequence}) --
def cssize(extends, parent = nil)
  _cssize(extends, (parent if parent.class == self.class))
rescue Sass::SyntaxError => e
  e.modify_backtrace(:filename => filename, :line => line)
  raise e
end

def cssize!(extends, parent)

Other tags:
    See: #cssize -

Parameters:
  • parent (Node, nil) -- The parent node of this node.
  • extends (Haml::Util::SubsetMap{Selector::Simple => Selector::Sequence}) --
def cssize!(extends, parent)
  self.children = children.map {|c| c.cssize(extends, self)}.flatten
end

def dasherize(s, opts)

Returns:
  • (String) - The converted string

Parameters:
  • opts ({Symbol => Object}) -- The options hash
  • s (String) -- The string to convert
def dasherize(s, opts)
  if opts[:dasherize]
    s.gsub('_', '-')
  else
    s
  end
end

def do_extend(extends)

Raises:
  • (Sass::SyntaxError) - Only if there's a programmer error

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

Parameters:
  • extends (Haml::Util::SubsetMap{Selector::Simple => Selector::Sequence}) --

Other tags:
    Todo: - Link this to the reference documentation on `@extend`
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

def each(&block)

Other tags:
    Yieldparam: node - a node in the tree

Other tags:
    Yield: - node
def each(&block)
  yield self
  children.each {|c| c.each(&block)}
end

def filename

Returns:
  • (String) -
def filename
  @filename || (@options && @options[:filename])
end

def initialize

def initialize
  @children = []
end

def invalid_child?(child)

Returns:
  • (Boolean, String) - Whether or not the child node is valid,

Parameters:
  • child (Tree::Node) -- A potential child node
def invalid_child?(child)
  case child
  when Tree::MixinDefNode
    "Mixins may only be defined at the root of a document."
  when Tree::ImportNode
    "Import directives may only be used at the root of a document."
  when Tree::ExtendNode
    "Extend directives may only be used within rules."
  end
end

def invisible?; false; end

Returns:
  • (Boolean) -
def invisible?; false; end

def options=(options)

Other tags:
    See: #options -

Parameters:
  • options ({Symbol => Object}) -- The options
def options=(options)
  children.each {|c| c.options = options}
  @options = options
end

def perform(environment)

Other tags:
    See: Sass::Tree -

Raises:
  • (Sass::SyntaxError) - if some element of the tree is invalid

Returns:
  • (Tree::Node) - The resulting tree of static nodes

Parameters:
  • environment (Sass::Environment) -- The lexical environment containing
def perform(environment)
  _perform(environment)
rescue Sass::SyntaxError => e
  e.modify_backtrace(:filename => filename, :line => line)
  raise e
end

def perform!(environment)

Other tags:
    See: #perform -

Parameters:
  • environment (Sass::Environment) -- The lexical environment containing
def perform!(environment)
  self.children = perform_children(Environment.new(environment))
end

def perform_children(environment)

Returns:
  • (Array) - The resulting static nodes

Parameters:
  • environment (Sass::Environment) -- The lexical environment containing
def perform_children(environment)
  children.map {|c| c.perform(environment)}.flatten
end

def run_interp(text, environment)

Returns:
  • (String) - The interpolated text

Parameters:
  • environment (Sass::Environment) -- The lexical environment containing
  • text (Array) -- The text to interpolate
def run_interp(text, environment)
  text.map do |r|
    next r if r.is_a?(String)
    val = r.perform(environment)
    # Interpolated strings should never render with quotes
    next val.value if val.is_a?(Sass::Script::String)
    val.to_s
  end.join.strip
end

def selector_to_sass(sel, opts)

Returns:
  • (String) - The Sass code corresponding to the selector

Parameters:
  • opts ({Symbol => Object}) -- An options hash (see {Sass::CSS#initialize})
  • sel (Array) -- The selector to convert
def selector_to_sass(sel, opts)
  sel.map do |r|
    if r.is_a?(String)
      r.gsub(/(,[ \t]*)?\n\s*/) {$1 ? $1 + "\n" : " "}
    else
      "\#{#{r.to_sass(opts)}}"
    end
  end.join
end

def selector_to_scss(sel, tabs, opts)

Returns:
  • (String) - The SCSS code corresponding to the selector

Parameters:
  • opts ({Symbol => Object}) -- An options hash (see {Sass::CSS#initialize})
  • tabs (Fixnum) -- The indentation of the selector
  • sel (Array) -- The selector to convert
def selector_to_scss(sel, tabs, opts)
  sel.map {|r| r.is_a?(String) ? r : "\#{#{r.to_sass(opts)}}"}.
    join.gsub(/^[ \t]*/, '  ' * tabs)
end

def selector_to_src(sel, tabs, opts, fmt)

Returns:
  • (String) - The Sass or SCSS code corresponding to the selector

Parameters:
  • fmt (Symbol) -- `:sass` or `:scss`
  • opts ({Symbol => Object}) -- An options hash (see {Sass::CSS#initialize})
  • tabs (Fixnum) -- The indentation of the selector
  • sel (Array) -- The selector to convert
def selector_to_src(sel, tabs, opts, fmt)
  fmt == :sass ? selector_to_sass(sel, opts) : selector_to_scss(sel, tabs, opts)
end

def semi(fmt)

Returns:
  • (String) - A semicolon or the empty string

Parameters:
  • fmt (Symbol) -- `:sass` or `:scss`
def semi(fmt)
  fmt == :sass ? "" : ";"
end

def style

Returns:
  • (Symbol) -
def style
  @options[:style]
end

def to_s(*args)

Other tags:
    See: Sass::Tree -

Returns:
  • (String, nil) - The resulting CSS

Parameters:
  • args (Array) -- Passed on to \{#\_to\_s}
def to_s(*args)
  _to_s(*args)
rescue Sass::SyntaxError => e
  e.modify_backtrace(:filename => filename, :line => line)
  raise e
end

def to_sass(tabs = 0, opts = {})

Returns:
  • (String) - The Sass code corresponding to the node

Parameters:
  • opts ({Symbol => Object}) -- An options hash (see {Sass::CSS#initialize})
  • tabs (Fixnum) -- The amount of tabulation to use for the Sass code
def to_sass(tabs = 0, opts = {})
  to_src(tabs, opts, :sass)
end

def to_scss(tabs = 0, opts = {})

Returns:
  • (String) - The Sass code corresponding to the node

Parameters:
  • opts ({Symbol => Object}) -- An options hash (see {Sass::CSS#initialize})
  • tabs (Fixnum) -- The amount of tabulation to use for the SCSS code
def to_scss(tabs = 0, opts = {})
  to_src(tabs, opts, :scss)
end

def to_src(tabs, opts, fmt)

Returns:
  • (String) - The Sass or SCSS code corresponding to the node

Parameters:
  • fmt (Symbol) -- `:sass` or `:scss`
  • opts ({Symbol => Object}) -- An options hash (see {Sass::CSS#initialize})
  • tabs (Fixnum) -- The amount of tabulation to use for the SCSS code
def to_src(tabs, opts, fmt)
  raise NotImplementedError.new("All static-node subclasses of Sass::Tree::Node must override #to_#{fmt}.")
end