Class: Sass::Tree::MixinNode

Inherits:
Node show all
Defined in:
lib/sass/tree/mixin_node.rb

Overview

A dynamic node representing a mixin include.

See Also:

Instance Attribute Summary

Attributes inherited from Node

#children, #filename, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #_to_s, #balance, #interpolate, #invalid_child?, #invisible?, #last, #perform, #perform!, #perform_children, #render, #style, #to_s, #to_sass

Constructor Details

#initialize(name, args) ⇒ MixinNode

Returns a new instance of MixinNode.

Parameters:

  • name (String)

    The name of the mixin

  • args (Array<Script::Node>)

    The arguments to the mixin



10
11
12
13
14
# File 'lib/sass/tree/mixin_node.rb', line 10

def initialize(name, args)
  @name = name
  @args = args
  super()
end

Instance Method Details

#_perform(environment) ⇒ Array<Tree::Node> (protected)

Runs the mixin.

Parameters:

  • environment (Sass::Environment)

    The lexical environment containing variable and mixin values

Returns:

  • (Array<Tree::Node>)

    The resulting static nodes

Raises:

See Also:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sass/tree/mixin_node.rb', line 26

def _perform(environment)
  raise Sass::SyntaxError.new("Undefined mixin '#{@name}'.") unless mixin = environment.mixin(@name)

  raise Sass::SyntaxError.new(<<END.gsub("\n", "")) if mixin.args.size < @args.size
Mixin #{@name} takes #{mixin.args.size} argument#{'s' if mixin.args.size != 1}
 but #{@args.size} #{@args.size == 1 ? 'was' : 'were'} passed.
END

  environment = mixin.args.zip(@args).
    inject(Sass::Environment.new(mixin.environment)) do |env, ((var, default), value)|
    env.set_local_var(var.name,
      if value
        value.perform(environment)
      elsif default
        default.perform(env)
      end)
    raise Sass::SyntaxError.new("Mixin #{@name} is missing parameter #{var.inspect}.") unless env.var(var.name)
    env
  end
  mixin.tree.map {|c| c.perform(environment)}.flatten
end