Module: CSS::Nesting
Overview
Desugars CSS Nesting Module Level 1 — replaces ‘&` with the parent selector and lifts every nested rule out of its parent. The result is a flat Stylesheet whose rules contain only declarations and at-rules.
The substitution favors readable output over conservative correctness padding: ‘:is(parent)` wrapping is only emitted when the parent has multiple selectors, or when a non-lone `&` is mixed into a compound and the parent has combinators. In simple cases the parent is inlined directly (`& .x` with parent `.a` → `.a .x`, not `:is(.a) .x`).
Instance Method Summary collapse
Instance Method Details
#desugar(stylesheet) ⇒ Object
14 15 16 |
# File 'lib/css/nesting.rb', line 14 def desugar(stylesheet) Nodes::Stylesheet.new(rules: stylesheet.rules.flat_map { desugar_top_level(it) }) end |