Class: Sass::Tree::Visitors::Extend

Inherits:
Base
  • Object
show all
Defined in:
lib/sass/tree/visitors/extend.rb

Overview

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

Destructively modifies the tree.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

node_name, #visit_if

Constructor Details

#initialize(extends) ⇒ Extend (protected)

Returns a new instance of Extend.



21
22
23
24
# File 'lib/sass/tree/visitors/extend.rb', line 21

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

Class Method Details

.visit(root, extends) ⇒ Object

Performs the given extensions on the static CSS tree based in root, then validates that all extends matched some selector.

The extensions to perform on this tree.

Parameters:

Returns:

  • (Object)

    The return value of #visit for the root node.



13
14
15
16
17
# File 'lib/sass/tree/visitors/extend.rb', line 13

def self.visit(root, extends)
  return if extends.empty?
  new(extends).send(:visit, root)
  check_extends_fired! extends
end

Instance Method Details

#visit(node) (protected)

If an exception is raised, this adds proper metadata to the backtrace.



27
28
29
30
31
32
# File 'lib/sass/tree/visitors/extend.rb', line 27

def visit(node)
  super(node)
rescue Sass::SyntaxError => e
  e.modify_backtrace(:filename => node.filename, :line => node.line)
  raise e
end

#visit_children(parent) (protected)

Keeps track of the current parent directives.



35
36
37
38
39
40
# File 'lib/sass/tree/visitors/extend.rb', line 35

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

#visit_rule(node) (protected)

Applies the extend to a single rule's selector.



43
44
45
# File 'lib/sass/tree/visitors/extend.rb', line 43

def visit_rule(node)
  node.resolved_rules = node.resolved_rules.do_extend(@extends, @parent_directives)
end