Class Sass::Tree::MixinNode
In: lib/sass/tree/mixin_node.rb
Parent: Node

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.

@see Sass::Tree

Methods

_cssize   cssize   invalid_child?   new   options=   perform!   to_src  

Public Class methods

@param name [String] The name of the mixin @param args [Array<Script::Node>] The arguments to the mixin

[Source]

    # File lib/sass/tree/mixin_node.rb, line 18
18:     def initialize(name, args)
19:       @name = name
20:       @args = args
21:       super()
22:     end

Public Instance methods

@see Node#cssize

[Source]

    # File lib/sass/tree/mixin_node.rb, line 25
25:     def cssize(extends, parent = nil)
26:       _cssize(extends, parent) # Pass on the parent even if it's not a MixinNode
27:     end

@see Node#options=

[Source]

    # File lib/sass/tree/mixin_node.rb, line 11
11:     def options=(opts)
12:       super
13:       @args.each {|a| a.context = :equals} if opts[:sass2]
14:     end

Protected Instance methods

@see Node#_cssize

[Source]

    # File lib/sass/tree/mixin_node.rb, line 50
50:     def _cssize(extends, parent)
51:       children.map do |c|
52:         parent.check_child! c
53:         c.cssize(extends, parent)
54:       end.flatten
55:     rescue Sass::SyntaxError => e
56:       e.modify_backtrace(:mixin => @name, :filename => filename, :line => line)
57:       e.add_backtrace(:filename => filename, :line => line)
58:       raise e
59:     end

Returns an error message if the given child node is invalid, and false otherwise.

{ExtendNode}s are valid within {MixinNode}s.

@param child [Tree::Node] A potential child node @return [Boolean, String] Whether or not the child node is valid,

  as well as the error message to display if it is invalid

[Source]

    # File lib/sass/tree/mixin_node.rb, line 39
39:     def invalid_child?(child)
40:       super unless child.is_a?(ExtendNode)
41:     end

Runs the mixin.

@param environment [Sass::Environment] The lexical environment containing

  variable and mixin values

@raise [Sass::SyntaxError] if there is no mixin with the given name @raise [Sass::SyntaxError] if an incorrect number of arguments was passed @see Sass::Tree

[Source]

     # File lib/sass/tree/mixin_node.rb, line 68
 68:     def perform!(environment)
 69:       handle_include_loop!(environment) if environment.mixins_in_use.include?(@name)
 70: 
 71:       original_env = environment
 72:       original_env.push_frame(:filename => filename, :line => line)
 73:       original_env.prepare_frame(:mixin => @name)
 74:       raise Sass::SyntaxError.new("Undefined mixin '#{@name}'.") unless mixin = environment.mixin(@name)
 75: 
 76:       raise Sass::SyntaxError.new("Mixin \#{@name} takes \#{mixin.args.size} argument\#{'s' if mixin.args.size != 1}\n but \#{@args.size} \#{@args.size == 1 ? 'was' : 'were'} passed.\n".gsub("\n", "")) if mixin.args.size < @args.size
 77:       environment = mixin.args.zip(@args).
 78:         inject(Sass::Environment.new(mixin.environment)) do |env, ((var, default), value)|
 79:         env.set_local_var(var.name,
 80:           if value
 81:             value.perform(environment)
 82:           elsif default
 83:             val = default.perform(env)
 84:             if default.context == :equals && val.is_a?(Sass::Script::String)
 85:               val = Sass::Script::String.new(val.value)
 86:             end
 87:             val
 88:           end)
 89:         raise Sass::SyntaxError.new("Mixin #{@name} is missing parameter #{var.inspect}.") unless env.var(var.name)
 90:         env
 91:       end
 92: 
 93:       self.children = mixin.tree.map {|c| c.perform(environment)}.flatten
 94:     rescue Sass::SyntaxError => e
 95:       if original_env # Don't add backtrace info if this is an @include loop
 96:         e.modify_backtrace(:mixin => @name, :line => @line)
 97:         e.add_backtrace(:line => @line)
 98:       end
 99:       raise e
100:     ensure
101:       original_env.pop_frame if original_env
102:     end

@see Node#to_src

[Source]

    # File lib/sass/tree/mixin_node.rb, line 44
44:     def to_src(tabs, opts, fmt)
45:       args = '(' + @args.map {|a| a.to_sass(opts)}.join(", ") + ')' unless @args.empty?
46:       "#{'  ' * tabs}#{fmt == :sass ? '+' : '@include '}#{dasherize(@name, opts)}#{args}#{semi fmt}\n"
47:     end

[Validate]