2006-12-04 08:41:09 +00:00
|
|
|
require 'sass/tree/node'
|
|
|
|
require 'sass/tree/attr_node'
|
|
|
|
|
|
|
|
module Sass::Tree
|
|
|
|
class RuleNode < ValueNode
|
2007-03-17 04:17:01 +00:00
|
|
|
# The character used to include the parent selector
|
|
|
|
PARENT = '&'
|
|
|
|
|
2006-12-04 08:41:09 +00:00
|
|
|
alias_method :rule, :value
|
|
|
|
alias_method :rule=, :value=
|
|
|
|
|
2007-02-06 03:34:49 +00:00
|
|
|
def to_s(tabs, super_rules = nil)
|
2006-12-04 08:41:09 +00:00
|
|
|
attributes = []
|
|
|
|
sub_rules = []
|
2007-03-17 04:17:01 +00:00
|
|
|
refs_parent = self.rule.include? PARENT
|
2007-01-17 16:32:15 +00:00
|
|
|
total_rule = if super_rules
|
2007-02-06 03:34:49 +00:00
|
|
|
super_rules.split(/,\s*/).collect! do |s|
|
2007-03-17 04:17:01 +00:00
|
|
|
if refs_parent
|
|
|
|
self.rule.gsub(PARENT, s)
|
|
|
|
else
|
|
|
|
self.rule.split(/,\s*/).collect {|r| "#{s} #{r}"}.join(", ")
|
|
|
|
end
|
2007-01-18 09:30:30 +00:00
|
|
|
end.join(", ")
|
2007-03-17 04:17:01 +00:00
|
|
|
elsif refs_parent
|
|
|
|
raise Sass::SyntaxError.new("Base-level rules cannot contain the parent-selector-referencing character '#{PARENT}'", line)
|
2007-01-18 09:30:30 +00:00
|
|
|
else
|
|
|
|
self.rule
|
|
|
|
end
|
2006-12-04 08:41:09 +00:00
|
|
|
|
|
|
|
children.each do |child|
|
2007-03-17 23:34:26 +00:00
|
|
|
if child.is_a? RuleNode
|
2006-12-04 08:41:09 +00:00
|
|
|
sub_rules << child
|
2007-03-17 23:34:26 +00:00
|
|
|
else
|
|
|
|
attributes << child
|
2006-12-04 08:41:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
to_return = ''
|
|
|
|
unless attributes.empty?
|
2007-02-06 03:34:49 +00:00
|
|
|
if @style == :compact
|
2007-02-06 01:58:23 +00:00
|
|
|
to_return << "#{total_rule} { #{attributes.join(' ')} }\n"
|
2007-02-06 03:34:49 +00:00
|
|
|
else
|
|
|
|
spaces = (@style == :expanded ? 2 : tabs * 2)
|
|
|
|
old_spaces = ' ' * (spaces - 2)
|
|
|
|
spaces = ' ' * spaces
|
|
|
|
|
|
|
|
attributes = attributes.join("\n").gsub("\n", "\n#{spaces}").rstrip
|
|
|
|
end_attrs = (@style == :expanded ? "\n" : ' ')
|
|
|
|
to_return << "#{old_spaces}#{total_rule} {\n#{spaces}#{attributes}#{end_attrs}}\n"
|
2007-02-06 01:58:23 +00:00
|
|
|
end
|
2006-12-04 08:41:09 +00:00
|
|
|
end
|
|
|
|
|
2007-03-17 10:24:43 +00:00
|
|
|
tabs += 1 unless attributes.empty?
|
|
|
|
sub_rules.each { |sub| to_return << sub.to_s(tabs, total_rule) }
|
2006-12-04 08:41:09 +00:00
|
|
|
to_return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|