Class: Sass::Tree::DirectiveNode

Inherits:
Node show all
Defined in:
lib/sass/css.rb,
lib/sass/tree/directive_node.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #filename, #line

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #last, #perform

Constructor Details

#initialize(value, options) ⇒ DirectiveNode

Returns a new instance of DirectiveNode.



5
6
7
8
# File 'lib/sass/tree/directive_node.rb', line 5

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

Instance Attribute Details

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/sass/tree/directive_node.rb', line 3

def value
  @value
end

Instance Method Details

#to_s(tabs) ⇒ Object



10
11
12
13
14
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
40
41
42
43
44
45
46
47
48
# File 'lib/sass/tree/directive_node.rb', line 10

def to_s(tabs)
  if children.empty?
    value + ";"
  else
    result = if @style == :compressed
               "#{value}{"
             else
               "#{'  ' * (tabs - 1)}#{value} {" + (@style == :compact ? ' ' : "\n")
             end
    was_attr = false
    first = true
    children.each do |child|
      if @style == :compact
        if child.is_a?(AttrNode)
          result << "#{child.to_s(first || was_attr ? 1 : tabs + 1)} "
        else
          if was_attr
            result[-1] = "\n"
          end
          rendered = child.to_s(tabs + 1)
          rendered.lstrip! if first
          result << rendered
        end
        was_attr = child.is_a?(AttrNode)
        first = false
      elsif @style == :compressed
        result << (was_attr ? ";#{child.to_s(1)}" : child.to_s(1))
        was_attr = child.is_a?(AttrNode)
      else
        result << child.to_s(tabs + 1) + "\n"
      end
    end
    result.rstrip + if @style == :compressed
                      "}"
                    else
                      (@style == :expanded ? "\n" : " ") + "}\n"
                    end
  end
end

#to_sass(tabs, opts = {}) ⇒ Object



39
40
41
# File 'lib/sass/css.rb', line 39

def to_sass(tabs, opts = {})
  "#{'  ' * tabs}#{value}#{children.map {|c| c.to_sass(tabs + 1, opts)}}\n"
end