6: def to_s(tabs)
7: if children.empty?
8: value + ";"
9: else
10: result = if @style == :compressed
11: "#{value}{"
12: else
13: "#{' ' * (tabs - 1)}#{value} {" + (@style == :compact ? ' ' : "\n")
14: end
15: was_attr = false
16: first = true
17: children.each do |child|
18: if child.is_a?(RuleNode) && child.continued?
19: check_multiline_rule(child)
20: continued_rule = true
21: end
22:
23: if @style == :compact
24: if child.is_a?(AttrNode)
25: result << "#{child.to_s(first || was_attr ? 1 : tabs + 1)} "
26: else
27: if was_attr
28: result[-1] = "\n"
29: end
30: rendered = child.to_s(tabs + 1)
31: rendered.lstrip! if first
32: result << rendered
33: end
34: was_attr = child.is_a?(AttrNode)
35: first = continued_rule
36: elsif @style == :compressed
37: result << (was_attr ? ";#{child.to_s(1)}" : child.to_s(1))
38: was_attr = child.is_a?(AttrNode)
39: else
40: result << child.to_s(tabs + 1) + (continued_rule ? '' : "\n")
41: end
42: end
43: result.rstrip + if @style == :compressed
44: "}"
45: else
46: (@style == :expanded ? "\n" : " ") + "}\n"
47: end
48: end
49: end