Reference · Browser

style_with

signature
style_with(str | fn) -> null

What it does

At the top level of a program, names a command that every component's and view's style goes through as the program loads, before the styles are scoped: the command reads CSS on its standard input and writes CSS on its standard output. With PostCSS and Tailwind's plugin (style_with("npx postcss"), the config beside the program), @apply, theme() and nesting work in a component's own CSS. It may be given a function instead, written in Quillo or in Rust (a .rs or .qwer file): a CSS engine of the program's own, with no Node. The function is called once with all the styles as one text, each marked with a /*! quillo-style <id> */ comment, and gives them back as text, the marks kept. It gives null.

Examples

in a program
style_with("npx postcss")            // postcss.config.js beside the program loads Tailwindcomponent Card(title: str) {    style css`      .card { @apply rounded border p-4 }      .title { @apply text-lg font-bold; color: theme(colors.blue.700) }    `    <div.card><h2.title>{title}</h2></div>}route GET / = <html><body><Card title="Hello"/></body></html>
in a program
use "tailwind.rs"                     // pub fn tailwind_apply(css: String) -> Result<String, String>style_with(tailwind_apply)
fn engine(css) = replace(css, "@apply m-2;", "margin: .5rem;")print(style_with(engine))
output
null

Edge cases

print(style_with("cat"))
output
null

Errors

An empty command is a runtime error, not an error value, as the program loads. A function that gives no CSS stops the program before it serves.

this one fails
print(style_with(""))
output
line 1: `style_with` takes the command to run, like style_with("npx postcss")
this one fails
fn engine(css) = 3style_with(engine)component C() {    style css`.c { color: red }`    <p.c/>}
output
main.qwe: style_with `engine` failed: it gave int, not CSS text

Chaining

style_with is a declaration, written once at the top level, not piped into or out of. The command string can be built, from env for instance:

in a program
style_with(env("POSTCSS") ?? "npx postcss")

See also

classes, raw, escape, file

Thread
8Useful? Like it, or add to its thread below.

Thread 0 posts

On style_with(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo