Class: Sass::Tree::DirectiveNode
- Defined in:
- lib/sass/tree/directive_node.rb,
lib/sass/css.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;
if it's importing a Sass file,
it becomes a FileNode,
but if it's importing a plain CSS file,
it becomes a DirectiveNode.
Instance Attribute Summary collapse
-
#value ⇒ String
The text of the directive,
@
and all.
Attributes inherited from Node
#children, #filename, #line, #options
Instance Method Summary collapse
-
#initialize(value) ⇒ DirectiveNode
constructor
A new instance of DirectiveNode.
-
#to_s(tabs) ⇒ String
Computes the CSS for the directive.
- #to_sass(tabs, opts = {}) ⇒ Object
Methods inherited from Node
#<<, #==, #_perform, #balance, #interpolate, #invalid_child?, #invisible?, #last, #perform, #perform!, #perform_children, #render, #style
Constructor Details
#initialize(value) ⇒ DirectiveNode
Returns a new instance of DirectiveNode.
21 22 23 24 |
# File 'lib/sass/tree/directive_node.rb', line 21
def initialize(value)
@value = value
super()
end
|
Instance Attribute Details
#value ⇒ String
The text of the directive, @
and all.
18 19 20 |
# File 'lib/sass/tree/directive_node.rb', line 18
def value
@value
end
|
Instance Method Details
#to_s(tabs) ⇒ String
Computes the CSS for the directive.
30 31 32 33 34 35 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 |
# File 'lib/sass/tree/directive_node.rb', line 30
def to_s(tabs)
if children.empty?
value + ";"
else
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)
rendered.lstrip! if first
result << rendered
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
end
|
#to_sass(tabs, opts = {}) ⇒ Object
46 47 48 |
# File 'lib/sass/css.rb', line 46
def to_sass(tabs, opts = {})
"#{' ' * tabs}#{value}#{children.map {|c| c.to_sass(tabs + 1, opts)}}\n"
end
|