Sha256: d2d463a2374a0a2da5764964cb538b8574aab843fd33ae26a18e16a41dc98cf4

Contents?: true

Size: 1.58 KB

Versions: 52

Compression:

Stored size: 1.58 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}'.", @line) 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, ((name, default), value)|
        env.set_local_var(name,
          if value
            value.perform(environment)
          elsif default
            default.perform(env)
          end)
        raise Sass::SyntaxError.new("Mixin #{@name} is missing parameter !#{name}.") unless env.var(name)
        env
      end
      mixin.tree.map {|c| c.perform(environment)}.flatten
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
haml-edge-2.1.25 lib/sass/tree/mixin_node.rb
haml-edge-2.1.26 lib/sass/tree/mixin_node.rb
haml-edge-2.1.27 lib/sass/tree/mixin_node.rb
haml-edge-2.1.28 lib/sass/tree/mixin_node.rb
haml-edge-2.1.29 lib/sass/tree/mixin_node.rb
haml-edge-2.1.30 lib/sass/tree/mixin_node.rb
haml-edge-2.1.32 lib/sass/tree/mixin_node.rb
haml-edge-2.1.33 lib/sass/tree/mixin_node.rb
haml-edge-2.1.34 lib/sass/tree/mixin_node.rb
haml-edge-2.1.35 lib/sass/tree/mixin_node.rb
haml-edge-2.1.36 lib/sass/tree/mixin_node.rb
haml-edge-2.1.37 lib/sass/tree/mixin_node.rb
haml-edge-2.1.38 lib/sass/tree/mixin_node.rb
haml-edge-2.1.39 lib/sass/tree/mixin_node.rb
haml-edge-2.1.40 lib/sass/tree/mixin_node.rb
haml-edge-2.1.41 lib/sass/tree/mixin_node.rb
haml-edge-2.1.42 lib/sass/tree/mixin_node.rb
haml-edge-2.1.43 lib/sass/tree/mixin_node.rb
haml-edge-2.1.44 lib/sass/tree/mixin_node.rb
haml-edge-2.1.45 lib/sass/tree/mixin_node.rb