Class: Sass::Tree::DirectiveNode

Inherits:
Node
  • Object
show all
Defined in:
lib/sass/tree/directive_node.rb

Overview

A static node representing an unproccessed Sass @-directive. Directives known to Sass, like @for and @debug, are handled by their own nodes; only CSS directives like @media and @font-face become DirectiveNodes.

@import is a bit of a weird case; it becomes an ImportNode.

See Also:

Constant Summary

Constants inherited from Node

Node::SAVED_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #filename, #has_children, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #_around_dump, #_cssize, #_perform, #balance, #check_child!, #children_to_src, #cssize, #cssize!, #dasherize, #do_extend, #each, #invalid_child?, #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

#initialize(value) ⇒ DirectiveNode

Returns a new instance of DirectiveNode.

Parameters:

  • value (String)

    See #value



18
19
20
21
# File 'lib/sass/tree/directive_node.rb', line 18

def initialize(value)
  @value = value
  super()
end

Instance Attribute Details

#valueString

The text of the directive, @ and all.

Returns:

  • (String)


15
16
17
# File 'lib/sass/tree/directive_node.rb', line 15

def value
  @value
end

Instance Method Details

#_to_s(tabs) ⇒ String (protected)

Computes the CSS for the directive.

Parameters:

  • tabs (Fixnum)

    The level of indentation for the CSS

Returns:

  • (String)

    The resulting CSS



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sass/tree/directive_node.rb', line 36

def _to_s(tabs)
  return value + ";" unless has_children
  return value + " {}" if children.empty?
  result = if style == :compressed
             "#{value}{"
           else
             "#{'  ' * (tabs - 1)}#{value} {" + (style == :compact ? ' ' : "\n")
           end
  was_prop = false
  first = true
  children.each do |child|
    next if child.invisible?
    if style == :compact
      if child.is_a?(PropNode)
        result << "#{child.to_s(first || was_prop ? 1 : tabs + 1)} "
      else
        if was_prop
          result[-1] = "\n"
        end
        rendered = child.to_s(tabs + 1).dup
        rendered = rendered.lstrip if first
        result << rendered.rstrip + "\n"
      end
      was_prop = child.is_a?(PropNode)
      first = false
    elsif style == :compressed
      result << (was_prop ? ";#{child.to_s(1)}" : child.to_s(1))
      was_prop = child.is_a?(PropNode)
    else
      result << child.to_s(tabs + 1) + "\n"
    end
  end
  result.rstrip + if style == :compressed
                    "}"
                  else
                    (style == :expanded ? "\n" : " ") + "}\n"
                  end
end

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

See Also:



26
27
28
29
30
# File 'lib/sass/tree/directive_node.rb', line 26

def to_src(tabs, opts, fmt)
  res = "#{'  ' * tabs}#{value}"
  return res + "#{semi fmt}\n" unless has_children
  res + children_to_src(tabs, opts, fmt) + "\n"
end