Module: Less::StyleSheet::Mixin4

Defined in:
lib/sass/less.rb

Overview

Selector mixins that don't have arguments. This depends only on the syntax at the call site; if it doesn't use parens, it hits this production, regardless of whether the mixin being called has arguments or not.

Instance Method Summary collapse

Instance Method Details

#build_with_sass(env) Also known as: build



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sass/less.rb', line 15

def build_with_sass(env)
  selectors.build(env, :mixin).each do |path|
    el = path.inject(env.root) do |current, node|
      current.descend(node.selector, node) or raise MixinNameError, "#{selectors.text_value} in #{env}"
    end
    if el.is_a?(Node::Mixin::Def)
      # Calling a mixin with arguments, which gets compiled to a Sass mixin
      env << Node::Mixin::Call.new(el, [], env)
    else
      # Calling a mixin without arguments, which gets compiled to @extend
      sel = selector_str(path)
      base = selector_str(selector_base(path))
      if base == sel
        env << Node::SassNode.new(Sass::Tree::ExtendNode.new([sel]))
      else
        Sass::Util.sass_warn <<WARNING
WARNING: Sass doesn't support mixing in selector sequences.
Replacing "#{sel}" with "@extend #{base}"
WARNING
        env << Node::SassNode.new(Sass::Tree::CommentNode.new(["// #{sel};"], true, false))
        env << Node::SassNode.new(Sass::Tree::ExtendNode.new([base]))
      end
    end
  end
end

#selector_base(path)



43
44
45
46
47
48
# File 'lib/sass/less.rb', line 43

def selector_base(path)
  el, i = Sass::Util.enum_with_index(path).to_a.reverse.find {|e, i| e.selector !~ /^:{1,2}$/} ||
    [path.first, 0]
  sel = (el.selector =~ /^:{0,2}$/ ? el.selector : "")
  [Node::Element.new(el.name, sel)] + path[i+1..-1]
end

#selector_str(path)



50
51
52
# File 'lib/sass/less.rb', line 50

def selector_str(path)
  path.map {|e| e.sass_selector_str}.join(' ').gsub(' :', ':')
end