Class: Sass::Tree::MixinNode
Overview
A static node representing a mixin include. When in a static tree, the sole purpose is to wrap exceptions to add the mixin to the backtrace.
Instance Attribute Summary
Attributes inherited from Node
#children, #filename, #has_children, #line, #options
Instance Method Summary collapse
- #_cssize(parent) protected
- #cssize(parent = nil)
-
#initialize(name, args) ⇒ MixinNode
constructor
A new instance of MixinNode.
- #options=(opts)
-
#perform!(environment)
protected
Runs the mixin.
- #to_src(tabs, opts, fmt) protected
Methods inherited from Node
#<<, #==, #_perform, #_to_s, #balance, #children_to_src, #cssize!, #dasherize, #each, #invalid_child?, #invisible?, #perform, #perform_children, #render, #run_interp, #semi, #style, #to_s, #to_sass, #to_scss
Constructor Details
#initialize(name, args) ⇒ MixinNode
Returns a new instance of MixinNode.
18 19 20 21 22 |
# File 'lib/sass/tree/mixin_node.rb', line 18
def initialize(name, args)
@name = name
@args = args
super()
end
|
Instance Method Details
#_cssize(parent) (protected)
37 38 39 40 41 42 43 |
# File 'lib/sass/tree/mixin_node.rb', line 37
def _cssize(parent)
children.map {|c| c.cssize(parent)}.flatten
rescue Sass::SyntaxError => e
e.modify_backtrace(:mixin => @name, :line => line)
e.add_backtrace(:filename => filename, :line => line)
raise e
end
|
#cssize(parent = nil)
25 26 27 |
# File 'lib/sass/tree/mixin_node.rb', line 25
def cssize(parent = nil)
_cssize(parent) # Pass on the parent even if it's not a MixinNode
end
|
#options=(opts)
11 12 13 14 |
# File 'lib/sass/tree/mixin_node.rb', line 11
def options=(opts)
super
@args.each {|a| a.context = :equals} if opts[:sass2]
end
|
#perform!(environment) (protected)
Runs the mixin.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sass/tree/mixin_node.rb', line 52
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
val = default.perform(env)
if default.context == :equals && val.is_a?(Sass::Script::String)
val = Sass::Script::String.new(val.value)
end
val
end)
raise Sass::SyntaxError.new("Mixin #{@name} is missing parameter #{var.inspect}.") unless env.var(var.name)
env
end
self.children = mixin.tree.map {|c| c.perform(environment)}.flatten
rescue Sass::SyntaxError => e
e.modify_backtrace(:mixin => @name, :line => @line)
e.add_backtrace(:line => @line)
raise e
end
|
#to_src(tabs, opts, fmt) (protected)
31 32 33 34 |
# File 'lib/sass/tree/mixin_node.rb', line 31
def to_src(tabs, opts, fmt)
args = '(' + @args.map {|a| a.to_sass(opts)}.join(", ") + ')' unless @args.empty?
"#{' ' * tabs}#{fmt == :sass ? '+' : '@include '}#{dasherize(@name, opts)}#{args}#{semi fmt}\n"
end
|