Class: Sass::Tree::MixinNode

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

Overview

A static node representing a mixin include. When in a static tree, the sole purpose is to wrap exceptions to add the mixin to the backtrace.

See Also:

Instance Method Summary

Methods inherited from Node

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

Constructor Details

- (MixinNode) initialize(name, args)

A new instance of MixinNode

Parameters:

  • (String) name — The name of the mixin
  • (Array<Script::Node>) args — The arguments to the mixin


18
19
20
21
22
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_node.rb', line 18

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

Instance Method Details

- _cssize(extends, parent) (protected)

See Also:



50
51
52
53
54
55
56
57
58
59
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_node.rb', line 50

def _cssize(extends, parent)
  children.map do |c|
    parent.check_child! c
    c.cssize(extends, parent)
  end.flatten
rescue Sass::SyntaxError => e
  e.modify_backtrace(:mixin => @name, :filename => filename, :line => line)
  e.add_backtrace(:filename => filename, :line => line)
  raise e
end

- cssize(extends, parent = nil)

See Also:



25
26
27
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_node.rb', line 25

def cssize(extends, parent = nil)
  _cssize(extends, parent) # Pass on the parent even if it's not a MixinNode
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 MixinNodes.

Parameters:

Returns:

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


39
40
41
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_node.rb', line 39

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

- options=(opts)

See Also:



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

def options=(opts)
  super
  @args.each {|a| a.context = :equals} if opts[:sass2]
end

- perform!(environment) (protected)

Runs the mixin.

Parameters:

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

Raises:

See Also:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_node.rb', line 68

def perform!(environment)
  handle_include_loop!(environment) if environment.mixins_in_use.include?(@name)

  original_env = environment
  original_env.push_frame(:filename => filename, :line => line)
  original_env.prepare_frame(:mixin => @name)
  raise Sass::SyntaxError.new("Undefined mixin '#{@name}'.") unless mixin = environment.mixin(@name)

  raise Sass::SyntaxError.new("Mixin \#{@name} takes \#{mixin.args.size} argument\#{'s' if mixin.args.size != 1}\n but \#{@args.size} \#{@args.size == 1 ? 'was' : 'were'} passed.\n".gsub("\n", "")) if mixin.args.size < @args.size
  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
        val = default.perform(env)
        if default.context == :equals && val.is_a?(Sass::Script::String)
          val = Sass::Script::String.new(val.value)
        end
        val
      end)
    raise Sass::SyntaxError.new("Mixin #{@name} is missing parameter #{var.inspect}.") unless env.var(var.name)
    env
  end

  self.children = mixin.tree.map {|c| c.perform(environment)}.flatten
rescue Sass::SyntaxError => e
  if original_env # Don't add backtrace info if this is an @include loop
    e.modify_backtrace(:mixin => @name, :line => @line)
    e.add_backtrace(:line => @line)
  end
  raise e
ensure
  original_env.pop_frame if original_env
end

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

See Also:



44
45
46
47
# File '/var/www/haml-pages/.haml/lib/sass/tree/mixin_node.rb', line 44

def to_src(tabs, opts, fmt)
  args = '(' + @args.map {|a| a.to_sass(opts)}.join(", ") + ')' unless @args.empty?
  "#{'  ' * tabs}#{fmt == :sass ? '+' : '@include '}#{dasherize(@name, opts)}#{args}#{semi fmt}\n"
end