class Sass::Tree::Visitors::Extend

Destructively modifies the tree.
A visitor for performing selector inheritance on a static CSS tree.

def self.visit(root, extends)

Returns:
  • (Object) - The return value of \{#visit} for the root node.

Parameters:
  • extends (Sass::Util::SubsetMap{Selector::Simple =>) -- xtends [Sass::Util::SubsetMap{Selector::Simple =>
  • root (Tree::Node) -- The root node of the tree to visit.
def self.visit(root, extends)
  return if extends.empty?
  new(extends).send(:visit, root)
  check_extends_fired! extends
end

def check_extends_fired!(extends)

def check_extends_fired!(extends)
  extends.each_value do |ex|
    next if ex.success || ex.node.optional?
    message = "\"#{ex.extender}\" failed to @extend \"#{ex.target.join}\"."
    # TODO(nweiz): this should use the Sass stack trace of the extend node.
    raise Sass::SyntaxError.new(<<MESSAGE, :filename => ex.node.filename, :line => ex.node.line)
ssage}
selector "#{ex.target.join}" was not found.
"@extend #{ex.target.join} !optional" if the extend should be able to fail.
AGE
  end
end

def initialize(extends)

def initialize(extends)
  @parent_directives = []
  @extends = extends
end

def visit(node)

If an exception is raised, this adds proper metadata to the backtrace.
def visit(node)
  super(node)
rescue Sass::SyntaxError => e
  e.modify_backtrace(:filename => node.filename, :line => node.line)
  raise e
end

def visit_children(parent)

Keeps track of the current parent directives.
def visit_children(parent)
  @parent_directives.push parent if parent.is_a?(Sass::Tree::DirectiveNode)
  super
ensure
  @parent_directives.pop if parent.is_a?(Sass::Tree::DirectiveNode)
end

def visit_rule(node)

Applies the extend to a single rule's selector.
def visit_rule(node)
  node.resolved_rules = node.resolved_rules.do_extend(@extends, @parent_directives)
end