Sha256: ce47fedcdc23d014fa33cf4c797f7f2dffaff1deda565aefdd75f0e579425d87

Contents?: true

Size: 1.59 KB

Versions: 68

Compression:

Stored size: 1.59 KB

Contents

require 'sass/tree/node'

module Sass::Tree
  # A dynamic node representing a mixin include.
  #
  # @see Sass::Tree
  class MixinNode < Node
    # @param name [String] The name of the mixin
    # @param args [Array<Script::Node>] The arguments to the mixin
    def initialize(name, args)
      @name = name
      @args = args
      super()
    end

    protected

    # Runs the mixin.
    #
    # @param environment [Sass::Environment] The lexical environment containing
    #   variable and mixin values
    # @return [Array<Tree::Node>] The resulting static nodes
    # @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
    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
  end
end

Version data entries

68 entries across 68 versions & 2 rubygems

Version Path
drnic-haml-2.3.1 lib/sass/tree/mixin_node.rb
haml-edge-2.3.93 lib/sass/tree/mixin_node.rb
haml-edge-2.3.92 lib/sass/tree/mixin_node.rb
haml-edge-2.3.91 lib/sass/tree/mixin_node.rb
haml-edge-2.3.90 lib/sass/tree/mixin_node.rb
haml-edge-2.3.89 lib/sass/tree/mixin_node.rb
haml-edge-2.3.87 lib/sass/tree/mixin_node.rb
haml-edge-2.3.88 lib/sass/tree/mixin_node.rb
haml-edge-2.3.86 lib/sass/tree/mixin_node.rb
haml-edge-2.3.85 lib/sass/tree/mixin_node.rb
haml-edge-2.3.84 lib/sass/tree/mixin_node.rb
haml-edge-2.3.83 lib/sass/tree/mixin_node.rb
haml-edge-2.3.82 lib/sass/tree/mixin_node.rb
haml-edge-2.3.81 lib/sass/tree/mixin_node.rb
haml-edge-2.3.80 lib/sass/tree/mixin_node.rb
haml-edge-2.3.79 lib/sass/tree/mixin_node.rb
haml-edge-2.3.78 lib/sass/tree/mixin_node.rb
haml-edge-2.3.77 lib/sass/tree/mixin_node.rb
haml-edge-2.3.76 lib/sass/tree/mixin_node.rb
haml-edge-2.3.75 lib/sass/tree/mixin_node.rb