2019-03-16 19:36:07 +13:00
|
|
|
<!-- Comment that prevents the title from getting picked up -->
|
|
|
|
|
|
|
|
# A macro for writing HTML
|
|
|
|
|
2018-11-24 16:13:36 +13:00
|
|
|
```rust
|
2021-01-15 17:40:46 +13:00
|
|
|
# let _ = maud::
|
2018-11-24 16:13:36 +13:00
|
|
|
html! {
|
|
|
|
h1 { "Hello, world!" }
|
|
|
|
p.intro {
|
|
|
|
"This is an example of the "
|
2019-09-14 13:48:59 +12:00
|
|
|
a href="https://github.com/lambda-fairy/maud" { "Maud" }
|
2018-11-24 16:13:36 +13:00
|
|
|
" template language."
|
|
|
|
}
|
|
|
|
}
|
2021-01-15 17:40:46 +13:00
|
|
|
# ;
|
2018-11-24 16:13:36 +13:00
|
|
|
```
|
|
|
|
|
2021-01-22 19:31:51 +13:00
|
|
|
Maud is an HTML [template engine] for Rust.
|
2023-02-12 22:19:56 +11:00
|
|
|
It's implemented as a macro, `html!`, which compiles your markup to specialized Rust code.
|
|
|
|
This unique approach makes Maud templates fast, type-safe, and easy to deploy.
|
2018-11-24 16:13:36 +13:00
|
|
|
|
|
|
|
[template engine]: https://www.simple-is-better.org/template/
|
|
|
|
|
|
|
|
## Tight integration with Rust
|
|
|
|
|
2023-02-12 22:19:56 +11:00
|
|
|
Since Maud is a Rust macro, it can borrow most of its features from the host language.
|
2021-01-22 19:31:51 +13:00
|
|
|
Pattern matching and `for` loops work as they do in Rust.
|
2023-02-12 22:19:56 +11:00
|
|
|
There is no need to derive JSON conversions, as your templates can work with Rust values directly.
|
2018-11-24 16:13:36 +13:00
|
|
|
|
|
|
|
## Type safety
|
|
|
|
|
2023-02-12 22:19:56 +11:00
|
|
|
Your templates are checked by the compiler, just like the code around them.
|
|
|
|
Any typos will be caught at compile time, not after your app has already started.
|
2018-11-24 16:13:36 +13:00
|
|
|
|
|
|
|
## Minimal runtime
|
|
|
|
|
2023-02-12 22:19:56 +11:00
|
|
|
Since most of the work happens at compile time, the runtime footprint is small.
|
|
|
|
The Maud runtime library, including integration with the [Rocket] and [Actix] web frameworks, is around 100 SLoC.
|
2018-11-24 16:13:36 +13:00
|
|
|
|
|
|
|
[Rocket]: https://rocket.rs/
|
|
|
|
[Actix]: https://actix.rs/
|
|
|
|
|
|
|
|
## Simple deployment
|
|
|
|
|
2023-02-12 22:19:56 +11:00
|
|
|
There is no need to track separate template files, since all relevant code is linked into the final executable.
|