Class: Sass::Tree::RuleNode

Class | Sass::Tree::RuleNode
In: | lib/sass/tree/rule_node.rb
Parent: | ValueNode

### Methods

add_rules continued? rules to_s

### Constants

PARENT | = | '&' |  | The character used to include the parent selector

### External Aliases

value | -> | rule
value= | -> | rule=

### Public Instance methods

add_rules(node)

[Source]

        # File lib/sass/tree/rule_node.rb, line 16
    16:     def add_rules(node)
    17:       self.rule = rules
    18:       self.rule += node.rules
    19:     end

continued?()

[Source]

        # File lib/sass/tree/rule_node.rb, line 21
    21:     def continued?
    22:       rule[-1] == ?,
    23:     end

rules()

[Source]

        # File lib/sass/tree/rule_node.rb, line 12
    12:     def rules
    13:       Array(rule)
    14:     end

to_s(tabs, super_rules = nil)

[Source]

        # File lib/sass/tree/rule_node.rb, line 25
    25:     def to_s(tabs, super_rules = nil)
    26:       attributes = []
    27:       sub_rules = []
    28:
    29:       rule_split = /\s*,\s*/
    30:       rule_separator = @style == :compressed ? ',' : ', '
    31:       line_separator = [:nested, :expanded].include?(@style) ? ",\n" : rule_separator
    32:       rule_indent = '  ' * (tabs - 1)
    33:       total_rule = if super_rules
    34:         super_rules.split(",\n").map do |super_line|
    35:           super_line.strip.split(rule_split).map do |super_rule|
    36:             self.rules.map do |line|
    37:               rule_indent + line.gsub(/,$/, '').split(rule_split).map do |rule|
    38:                 if rule.include?(PARENT)
    39:                   rule.gsub(PARENT, super_rule)
    40:                 else
    41:                   "#{super_rule} #{rule}"
    42:                 end
    43:               end.join(rule_separator)
    44:             end.join(line_separator)
    45:           end.join(rule_separator)
    46:         end.join(line_separator)
    47:       elsif self.rules.any? { |r| r.include?(PARENT) }
    48:         raise Sass::SyntaxError.new("Base-level rules cannot contain the parent-selector-referencing character '#{PARENT}'.", line)
    49:       else
    50:         per_rule_indent, total_indent = [:nested, :expanded].include?(@style) ? [rule_indent, ''] : ['', rule_indent]
    51:         total_indent + self.rules.map do |r|
    52:           per_rule_indent + r.gsub(/,$/, '').gsub(rule_split, rule_separator).rstrip
    53:         end.join(line_separator)
    54:       end
    55:
    56:       children.each do |child|
    57:         if child.is_a? RuleNode
    58:           sub_rules << child
    59:         else
    60:           attributes << child
    61:         end
    62:       end
    63:
    64:       to_return = ''
    65:       if !attributes.empty?
    66:         old_spaces = '  ' * (tabs - 1)
    67:         spaces = '  ' * tabs
    68:         if @style == :compact
    69:           attributes = attributes.map { |a| a.to_s(1) }.join(' ')
    70:           to_return << "#{total_rule} { #{attributes} }\n"
    71:         elsif @style == :compressed
    72:           attributes = attributes.map { |a| a.to_s(1) }.join(';')
    73:           to_return << "#{total_rule}{#{attributes}}"
    74:         else
    75:           attributes = attributes.map { |a| a.to_s(tabs + 1) }.join("\n")
    76:           end_attrs = (@style == :expanded ? "\n" + old_spaces : ' ')
    77:           to_return << "#{total_rule} {\n#{attributes}#{end_attrs}}\n"
    78:         end
    79:       end
    80:
    81:       tabs += 1 unless attributes.empty? || @style != :nested
    82:       sub_rules.each do |sub|
    83:         to_return << sub.to_s(tabs, total_rule)
    84:       end
    85:
    86:       to_return
    87:     end

[Validate]