Class Sass::Tree::DirectiveNode
In: lib/sass/css.rb
lib/sass/tree/directive_node.rb
Parent: Object

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 {DirectiveNode}s.

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

@see Sass::Tree

Methods

new   to_s   to_sass  

Attributes

value  [RW]  The text of the directive, `@` and all.

@return [String]

Public Class methods

@param value [String] See \{value}

[Source]

    # File lib/sass/tree/directive_node.rb, line 18
18:     def initialize(value)
19:       @value = value
20:       super()
21:     end

Public Instance methods

Computes the CSS for the directive.

@param tabs [Fixnum] The level of indentation for the CSS @return [String] The resulting CSS

[Source]

    # File lib/sass/tree/directive_node.rb, line 27
27:     def to_s(tabs)
28:       if children.empty?
29:         value + ";"
30:       else
31:         result = if style == :compressed
32:                    "#{value}{"
33:                  else
34:                    "#{'  ' * (tabs - 1)}#{value} {" + (style == :compact ? ' ' : "\n")
35:                  end
36:         was_prop = false
37:         first = true
38:         children.each do |child|
39:           next if child.invisible?
40:           if style == :compact
41:             if child.is_a?(PropNode)
42:               result << "#{child.to_s(first || was_prop ? 1 : tabs + 1)} "
43:             else
44:               if was_prop
45:                 result[-1] = "\n"
46:               end
47:               rendered = child.to_s(tabs + 1)
48:               rendered.lstrip! if first
49:               result << rendered
50:             end
51:             was_prop = child.is_a?(PropNode)
52:             first = false
53:           elsif style == :compressed
54:             result << (was_prop ? ";#{child.to_s(1)}" : child.to_s(1))
55:             was_prop = child.is_a?(PropNode)
56:           else
57:             result << child.to_s(tabs + 1) + "\n"
58:           end
59:         end
60:         result.rstrip + if style == :compressed
61:                           "}"
62:                         else
63:                           (style == :expanded ? "\n" : " ") + "}\n"
64:                         end
65:       end
66:     end

@see Node#to_sass

[Source]

    # File lib/sass/css.rb, line 48
48:       def to_sass(tabs, opts = {})
49:         "#{'  ' * tabs}#{value}#{children.map {|c| c.to_sass(tabs + 1, opts)}}\n"
50:       end

[Validate]