maud-extensions
Proc macros for Maud that make inline CSS/JS and component-style authoring simpler.
This crate includes bundled copies of gnat/surreal and gnat/css-scope-inline. Check those repos to see what these two tiny JS files can do and how to use them.
Why use it?
- Define component-local
js()andcss()helpers with short macros. - Wrap markup with
component!and auto-inject(js())+(css()). - Emit direct
<script>/<style>blocks when needed. - Bundle
surreal.jsandcss-scope-inline.jswith zero path setup. - Embed fonts as base64
@font-faceCSS.
Table of Contents
- Install
- Quick Start
- component!
- Runtime Injection
- Macro Reference
- Migration (Breaking)
- Font Helpers
- License
Install
Quick Start
use ;
use ;
;
component!
component! wraps one top-level Maud element and appends (js()) and (css())
inside that root element automatically.
use ;
use ;
;
Equivalent output shape:
- root element content
- then
(js()) - then
(css())
Rules:
- input must be exactly one top-level element with a
{ ... }body js()andcss()helpers must already be in scope- trailing
;is allowed - invalid root shapes fail at compile time with guidance
Runtime Injection
Use bundled runtime scripts with no filesystem setup:
use surreal_scope_inline;
html!
Need custom files instead? Use js_file! / css_file! (include_str! behavior):
use js_file;
html!
Macro Reference
js! { ... }/js!("...")- Generate local
fn js() -> maud::Markuphelper.
- Generate local
css! { ... }/css!("...")- Generate local
fn css() -> maud::Markuphelper.
- Generate local
component! { ... }- Wrap one root element and inject
(js())+(css())at the end of its body.
- Wrap one root element and inject
inline_js! { ... }/inline_js!("...")- Emit
<script>markup directly. - Validate JS via
swc_ecma_parser.
- Emit
inline_css! { ... }/inline_css!("...")- Emit
<style>markup directly. - Validate CSS via
cssparser.
- Emit
js_file!("path")/css_file!("path")- Emit
<script>/<style>tags from file contents.
- Emit
surreal_scope_inline!()- Emit bundled
surreal.jsandcss-scope-inline.js.
- Emit bundled
font_face!(...)/font_faces!(...)- Embed font files as base64
@font-faceCSS.
- Embed font files as base64
Migration (Breaking)
The JS/CSS macro names were intentionally swapped.
- old
js!-> nowinline_js! - old
css!-> nowinline_css! - old
inline_js!-> nowjs! - old
inline_css!-> nowcss!
If you were manually placing (js()) / (css()) inside root markup, you can now
switch to component! and remove those explicit calls.
Font Helpers
font_face! and font_faces! embed font files as base64 data URLs. Because
this macro expands at the call site, the consuming crate must include base64
if you use these macros.
use font_face;
html!
License
MIT OR Apache-2.0