CSS in shrubbery notation: lower shrubbery to a CSS tree, and print a CSS tree back as shrubbery
Dependencies
///|
test "a rule" {
let src =
#|class(card):
#| display: grid
#| gap: rem(1)
inspect(
@shrubbery_css.to_css(src, style=Minified),
content=".card{display:grid;gap:1rem}",
)
}| CSS | what it is | shrubbery |
|---|---|---|
| .card | a class | class(card) |
| div | an element | div, or tag("…") when the name needs quoting |
| #sidebar | an id | id(sidebar) |
| :hover | a pseudo-class | hover() |
| ::before | a pseudo-element | element(before) |
| [type="text"] | an attribute match | has_attr(type = "text") |
| * | any element | any() |
| & | the parent selector | parent() |
| #f7f7f7 | a hex colour | hex(f7f7f7) |
| 10px | ten pixels | px(10) |
| 50% | fifty percent | percent(50) |
| !important | the important flag | important() |
| @media (…) | the media at-rule | media(…) |
| a b | b is inside a | a ~in b |
| a > b | b is a child of a | a ~child b |
| a + b | b is the next sibling | a ~next b |
| a ~ b | b is a later sibling | a ~sibling b |
///|
test "compound and descendant are different, and both are expressible" {
inspect(
@shrubbery_css.to_css("a class(b):\n x: y\n", style=Minified),
content="a.b{x:y}",
)
inspect(
@shrubbery_css.to_css("a ~in class(b):\n x: y\n", style=Minified),
content="a .b{x:y}",
)
}///|
test "underscores become hyphens" {
inspect(
@shrubbery_css.to_css("a:\n font_family: system_ui\n", style=Minified),
content="a{font-family:system-ui}",
)
}///|
test "the literal escape, in each position it is needed" {
let src =
#|class("btn__primary"):
#| color: hex(fff)
#|
#|tag("side_bar"):
#| font_family: ident("side_bar")
inspect(
@shrubbery_css.to_css(src, style=Minified),
content=".btn__primary{color:#fff}side_bar{font-family:side_bar}",
)
}///|
test "CSS becomes shrubbery, and back again" {
let shrub = @shrubbery_css.to_shrubbery(".card { display: grid }")
inspect(
shrub,
content=(
#|class(card):
#| display: grid
#|
),
)
inspect(
@shrubbery_css.to_css(shrub, style=Minified),
content=".card{display:grid}",
)
}///|
test "a CSS habit is met with its replacement" {
let l = @shrubbery_css.lower(".card:\n a: b\n")
inspect(l.diagnostics()[0].kind.code(), content="shrubcss::sigil_selector")
}| package | what |
|---|---|
| names | the tables: units, pseudo-classes, at-rules, relations, _ ⇄ - |
| kind, error | diagnostics, and the one bridge to error-report |
| lower | shrubbery → a CSS tree |
| emit | a CSS tree → shrubbery |
Install
Download zipCSS in shrubbery notation: lower shrubbery to a CSS tree, and print a CSS tree back as shrubbery
Dependencies