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 @style == :compact
19: if child.is_a?(AttrNode)
20: result << "#{child.to_s(first || was_attr ? 1 : tabs + 1)} "
21: else
22: if was_attr
23: result[-1] = "\n"
24: end
25: rendered = child.to_s(tabs + 1)
26: rendered.lstrip! if first
27: result << rendered
28: end
29: was_attr = child.is_a?(AttrNode)
30: first = false
31: elsif @style == :compressed
32: result << (was_attr ? ";#{child.to_s(1)}" : child.to_s(1))
33: was_attr = child.is_a?(AttrNode)
34: else
35: result << child.to_s(tabs + 1) + "\n"
36: end
37: end
38: result.rstrip + if @style == :compressed
39: "}"
40: else
41: (@style == :expanded ? "\n" : " ") + "}\n"
42: end
43: end
44: end