Class Index [+]

Quicksearch

Sass::Tree::MixinNode

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

Public Class Methods

new(name, args) click to toggle source

@param name [String] The name of the mixin @param args [Array] The arguments to the mixin

    # 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

cssize(extends, parent = nil) click to toggle source

@see Node#cssize

    # 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
options=(opts) click to toggle source

@see Node#options=

    # 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

_cssize(extends, parent) click to toggle source

@see Node#_cssize

    # 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
invalid_child?(child) click to toggle source

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
    # File lib/sass/tree/mixin_node.rb, line 39
39:     def invalid_child?(child)
40:       super unless child.is_a?(ExtendNode)
41:     end
perform!(environment) click to toggle source

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

     # 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} but #{@args.size} #{@args.size == 1 ? 'was' : 'were'} passed..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
to_src(tabs, opts, fmt) click to toggle source

@see Node#to_src

    # 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

Private Instance Methods

handle_include_loop!(environment) click to toggle source
     # File lib/sass/tree/mixin_node.rb, line 109
109:     def handle_include_loop!(environment)
110:       msg = "An @include loop has been found:"
111:       mixins = environment.stack.map {|s| s[:mixin]}.compact
112:       if mixins.size == 2 && mixins[0] == mixins[1]
113:         raise Sass::SyntaxError.new("#{msg} #{@name} includes itself")
114:       end
115: 
116:       mixins << @name
117:       msg << "\n" << Haml::Util.enum_cons(mixins, 2).map do |m1, m2|
118:         "    #{m1} includes #{m2}"
119:       end.join("\n")
120:       raise Sass::SyntaxError.new(msg)
121:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.