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 16 16: def to_s(tabs, super_rules = nil) 17: attributes = [] 18: sub_rules = [] 19: 20: # Save this because the comma's removed by the super_rule additions 21: was_continued = continued? 22: 23: total_rule = if super_rules 24: super_rules.split(/,\s*/).collect! do |s| 25: self.rule.split(/,\s*/).collect do |r| 26: if r.include?(PARENT) 27: r.gsub(PARENT, s) 28: else 29: "#{s} #{r}" 30: end 31: end.join(", ") 32: end.join(", ") + (was_continued ? ',' : '') 33: elsif self.rule.include?(PARENT) 34: raise Sass::SyntaxError.new("Base-level rules cannot contain the parent-selector-referencing character '#{PARENT}'", line) 35: else 36: self.rule 37: end 38: 39: children.each do |child| 40: if child.is_a? RuleNode 41: sub_rules << child 42: else 43: attributes << child 44: end 45: end 46: 47: to_return = '' 48: if !attributes.empty? 49: old_spaces = ' ' * (tabs - 1) 50: spaces = ' ' * tabs 51: if @style == :compact 52: attributes = attributes.map { |a| a.to_s(1) }.join(' ') 53: to_return << "#{old_spaces}#{total_rule} { #{attributes} }\n" 54: elsif @style == :compressed 55: attributes = attributes.map { |a| a.to_s(1) }.join(';') 56: to_return << "#{total_rule}{#{attributes}}" 57: else 58: attributes = attributes.map { |a| a.to_s(tabs + 1) }.join("\n") 59: end_attrs = (@style == :expanded ? "\n" + old_spaces : ' ') 60: to_return << "#{old_spaces}#{total_rule} {\n#{attributes}#{end_attrs}}\n" 61: end 62: elsif continued? 63: to_return << (' ' * (tabs - 1)) + total_rule + case @style 64: when :compressed; '' 65: when :compact; ' ' 66: else "\n" 67: end 68: end 69: 70: tabs += 1 unless attributes.empty? || @style != :nested 71: sub_rules.each do |sub| 72: if sub.continued? 73: check_multiline_rule(sub) 74: end 75: 76: to_return << sub.to_s(tabs, total_rule) 77: end 78: to_return 79: end