Class: Sass::Tree::MixinNode
Overview
A dynamic node representing a mixin include.
Instance Attribute Summary
Attributes inherited from Node
#children, #filename, #line, #options
Instance Method Summary collapse
-
#_perform(environment) ⇒ Array<Tree::Node>
protected
Runs the mixin.
-
#initialize(name, args) ⇒ MixinNode
constructor
A new instance of MixinNode.
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.
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.
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
|