Class: Sass::Tree::MixinDefNode

Inherits:
Node show all
Defined in:
/var/www/haml-pages/.haml/lib/sass/tree/mixin_def_node.rb

Overview

A dynamic node representing a mixin definition.

See Also:

Instance Method Summary

Methods inherited from Node

#<<, #==, #_cssize, #_to_s, #balance, #check_child!, #children_to_src, #cssize, #cssize!, #dasherize, #do_extend, #each, #invisible?, #perform, #perform!, #perform_children, #run_interp, #selector_to_sass, #selector_to_scss, #selector_to_src, #semi, #style, #to_s, #to_sass, #to_scss

Constructor Details

- (MixinDefNode) initialize(name, args)

A new instance of MixinDefNode

Parameters:

  • (String) name — The mixin name
  • (Array<(Script::Node, Script::Node)>) args — The arguments for the mixin. Each element is a tuple containing the variable for argument and the parse tree for the default value of the argument


11
12
13
14
15
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_def_node.rb', line 11

def initialize(name, args)
  @name = name
  @args = args
  super()
end

Instance Method Details

- _perform(environment) (protected)

Loads the mixin into the environment.

Parameters:

  • (Sass::Environment) environment — The lexical environment containing variable and mixin values


42
43
44
45
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_def_node.rb', line 42

def _perform(environment)
  environment.set_mixin(@name, Sass::Mixin.new(@name, @args, environment, children))
  []
end

- (Boolean, String) invalid_child?(child) (protected)

Returns an error message if the given child node is invalid, and false otherwise.

ExtendNodes are valid within MixinDefNodes.

Parameters:

Returns:

  • (Boolean, String) — Whether or not the child node is valid, as well as the error message to display if it is invalid


55
56
57
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_def_node.rb', line 55

def invalid_child?(child)
  super unless child.is_a?(ExtendNode)
end

- to_src(tabs, opts, fmt) (protected)

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_def_node.rb', line 20

def to_src(tabs, opts, fmt)
  args =
    if @args.empty?
      ""
    else
      '(' + @args.map do |v, d|
        if d
          "#{v.to_sass(opts)}: #{d.to_sass(opts)}"
        else
          v.to_sass(opts)
        end
      end.join(", ") + ')'
    end
        
  "#{'  ' * tabs}#{fmt == :sass ? '=' : '@mixin '}#{dasherize(@name, opts)}#{args}" +
    children_to_src(tabs, opts, fmt)
end