1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/lib/sass/tree/rule_node.rb
2007-01-18 09:30:30 +00:00

37 lines
872 B
Ruby

require 'sass/tree/node'
require 'sass/tree/attr_node'
module Sass::Tree
class RuleNode < ValueNode
alias_method :rule, :value
alias_method :rule=, :value=
def to_s(super_rules = nil)
attributes = []
sub_rules = []
total_rule = if super_rules
super_rules.split(/,\s*/).collect! do |s|
self.rule.split(/,\s*/).collect! {|r| "#{s} #{r}"}.join(", ")
end.join(", ")
else
self.rule
end
children.each do |child|
if child.is_a? AttrNode
attributes << child
else
sub_rules << child
end
end
to_return = ''
unless attributes.empty?
to_return << "#{total_rule} { #{attributes.join(' ')} }\n"
end
sub_rules.each { |sub| to_return << sub.to_s(total_rule) }
to_return
end
end
end