2007-08-12 10:54:35 +00:00
|
|
|
module Sass::Tree
|
2009-04-25 12:19:08 -07:00
|
|
|
# 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;
|
2009-07-12 10:21:21 -04:00
|
|
|
# it becomes an {ImportNode}.
|
2009-04-25 12:19:08 -07:00
|
|
|
#
|
|
|
|
# @see Sass::Tree
|
2008-10-13 09:49:35 -07:00
|
|
|
class DirectiveNode < Node
|
2009-04-25 12:19:08 -07:00
|
|
|
# The text of the directive, `@` and all.
|
|
|
|
#
|
|
|
|
# @return [String]
|
2008-10-13 09:49:35 -07:00
|
|
|
attr_accessor :value
|
|
|
|
|
2009-04-25 12:19:08 -07:00
|
|
|
# @param value [String] See \{#value}
|
2009-04-21 19:25:18 -07:00
|
|
|
def initialize(value)
|
2008-10-13 09:49:35 -07:00
|
|
|
@value = value
|
2009-04-21 19:25:18 -07:00
|
|
|
super()
|
2008-10-13 09:49:35 -07:00
|
|
|
end
|
|
|
|
|
2009-09-14 01:34:16 -07:00
|
|
|
protected
|
|
|
|
|
2009-04-25 12:19:08 -07:00
|
|
|
# Computes the CSS for the directive.
|
|
|
|
#
|
|
|
|
# @param tabs [Fixnum] The level of indentation for the CSS
|
|
|
|
# @return [String] The resulting CSS
|
2009-09-14 01:34:16 -07:00
|
|
|
def _to_s(tabs)
|
2007-08-12 10:54:35 +00:00
|
|
|
if children.empty?
|
|
|
|
value + ";"
|
|
|
|
else
|
2009-04-21 18:39:34 -07:00
|
|
|
result = if style == :compressed
|
2007-09-07 09:00:58 +00:00
|
|
|
"#{value}{"
|
|
|
|
else
|
2009-04-21 18:39:34 -07:00
|
|
|
"#{' ' * (tabs - 1)}#{value} {" + (style == :compact ? ' ' : "\n")
|
2007-09-07 09:00:58 +00:00
|
|
|
end
|
2009-06-19 03:33:03 -07:00
|
|
|
was_prop = false
|
2007-08-12 10:54:35 +00:00
|
|
|
first = true
|
|
|
|
children.each do |child|
|
2009-05-08 13:42:39 -07:00
|
|
|
next if child.invisible?
|
2009-04-21 18:39:34 -07:00
|
|
|
if style == :compact
|
2009-06-19 03:49:40 -07:00
|
|
|
if child.is_a?(PropNode)
|
2009-06-19 03:33:03 -07:00
|
|
|
result << "#{child.to_s(first || was_prop ? 1 : tabs + 1)} "
|
2007-08-12 10:54:35 +00:00
|
|
|
else
|
2009-06-19 03:33:03 -07:00
|
|
|
if was_prop
|
2007-08-12 10:54:35 +00:00
|
|
|
result[-1] = "\n"
|
|
|
|
end
|
|
|
|
rendered = child.to_s(tabs + 1)
|
|
|
|
rendered.lstrip! if first
|
|
|
|
result << rendered
|
|
|
|
end
|
2009-06-19 03:49:40 -07:00
|
|
|
was_prop = child.is_a?(PropNode)
|
2008-03-30 11:15:37 -07:00
|
|
|
first = false
|
2009-04-21 18:39:34 -07:00
|
|
|
elsif style == :compressed
|
2009-06-19 03:33:03 -07:00
|
|
|
result << (was_prop ? ";#{child.to_s(1)}" : child.to_s(1))
|
2009-06-19 03:49:40 -07:00
|
|
|
was_prop = child.is_a?(PropNode)
|
2007-08-12 10:54:35 +00:00
|
|
|
else
|
2008-03-30 11:15:37 -07:00
|
|
|
result << child.to_s(tabs + 1) + "\n"
|
2007-08-12 10:54:35 +00:00
|
|
|
end
|
|
|
|
end
|
2009-04-21 18:39:34 -07:00
|
|
|
result.rstrip + if style == :compressed
|
2007-09-07 09:00:58 +00:00
|
|
|
"}"
|
|
|
|
else
|
2009-04-21 18:39:34 -07:00
|
|
|
(style == :expanded ? "\n" : " ") + "}\n"
|
2007-09-07 09:00:58 +00:00
|
|
|
end
|
2007-08-12 10:54:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|