Class | Sass::Tree::RuleNode |
In: |
lib/sass/tree/rule_node.rb
|
Parent: | ValueNode |
PARENT | = | '&' | The character used to include the parent selector |
value | -> | rule |
value= | -> | rule= |
# File lib/sass/tree/rule_node.rb, line 12 12: def to_s(tabs, super_rules = nil) 13: attributes = [] 14: sub_rules = [] 15: total_rule = if super_rules 16: super_rules.split(/,\s*/).collect! do |s| 17: self.rule.split(/,\s*/).collect do |r| 18: if r.include?(PARENT) 19: r.gsub(PARENT, s) 20: else 21: "#{s} #{r}" 22: end 23: end.join(", ") 24: end.join(", ") 25: elsif self.rule.include?(PARENT) 26: raise Sass::SyntaxError.new("Base-level rules cannot contain the parent-selector-referencing character '#{PARENT}'", line) 27: else 28: self.rule 29: end 30: 31: children.each do |child| 32: if child.is_a? RuleNode 33: sub_rules << child 34: else 35: attributes << child 36: end 37: end 38: 39: to_return = '' 40: unless attributes.empty? 41: if @style == :compact 42: to_return << "#{total_rule} { #{attributes.join(' ')} }\n" 43: else 44: spaces = (@style == :expanded ? 2 : tabs * 2) 45: old_spaces = ' ' * (spaces - 2) 46: spaces = ' ' * spaces 47: 48: attributes = attributes.join("\n").gsub("\n", "\n#{spaces}").rstrip 49: end_attrs = (@style == :expanded ? "\n" : ' ') 50: to_return << "#{old_spaces}#{total_rule} {\n#{spaces}#{attributes}#{end_attrs}}\n" 51: end 52: end 53: 54: tabs += 1 unless attributes.empty? 55: sub_rules.each { |sub| to_return << sub.to_s(tabs, total_rule) } 56: to_return 57: end