/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

  1. module 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. protected
  17. # @see Node#to_src
  18. def to_src(tabs, opts, fmt)
  19. args =
  20. if @args.empty?
  21. ""
  22. else
  23. '(' + @args.map do |v, d|
  24. if d
  25. "#{v.to_sass(opts)}: #{d.to_sass(opts)}"
  26. else
  27. v.to_sass(opts)
  28. end
  29. end.join(", ") + ')'
  30. end
  31. "#{' ' * tabs}#{fmt == :sass ? '=' : '@mixin '}#{dasherize(@name, opts)}#{args}" +
  32. children_to_src(tabs, opts, fmt)
  33. end
  34. # Loads the mixin into the environment.
  35. #
  36. # @param environment [Sass::Environment] The lexical environment containing
  37. # variable and mixin values
  38. def _perform(environment)
  39. environment.set_mixin(@name, Sass::Mixin.new(@name, @args, environment, children))
  40. []
  41. end
  42. end
  43. end
  44. end