PageRenderTime 49ms CodeModel.GetById 43ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/scalate-jruby/src/main/resources/haml-3.0.25/lib/sass/tree/mixin_def_node.rb

http://github.com/scalate/scalate
Ruby | 48 lines | 32 code | 4 blank | 12 comment | 2 complexity | 9d543bd4e1224abe2b7e46caaadc0180 MD5 | raw file
 1module Sass
 2  module Tree
 3    # A dynamic node representing a mixin definition.
 4    #
 5    # @see Sass::Tree
 6    class MixinDefNode < Node
 7      # @param name [String] The mixin name
 8      # @param args [Array<(Script::Node, Script::Node)>] The arguments for the mixin.
 9      #   Each element is a tuple containing the variable for argument
10      #   and the parse tree for the default value of the argument
11      def initialize(name, args)
12        @name = name
13        @args = args
14        super()
15      end
16
17      protected
18
19      # @see Node#to_src
20      def to_src(tabs, opts, fmt)
21        args =
22          if @args.empty?
23            ""
24          else
25            '(' + @args.map do |v, d|
26              if d
27                "#{v.to_sass(opts)}: #{d.to_sass(opts)}"
28              else
29                v.to_sass(opts)
30              end
31            end.join(", ") + ')'
32          end
33              
34        "#{'  ' * tabs}#{fmt == :sass ? '=' : '@mixin '}#{dasherize(@name, opts)}#{args}" +
35          children_to_src(tabs, opts, fmt)
36      end
37
38      # Loads the mixin into the environment.
39      #
40      # @param environment [Sass::Environment] The lexical environment containing
41      #   variable and mixin values
42      def _perform(environment)
43        environment.set_mixin(@name, Sass::Mixin.new(@name, @args, environment, children))
44        []
45      end
46    end
47  end
48end