2018-11-24 16:13:36 +13:00
|
|
|
|
# Getting started
|
|
|
|
|
|
|
|
|
|
## Add Maud to your project
|
|
|
|
|
|
|
|
|
|
Once Rust is set up,
|
|
|
|
|
create a new project with Cargo:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
cargo new --bin pony-greeter
|
|
|
|
|
cd pony-greeter
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Add `maud` to your `Cargo.toml`:
|
|
|
|
|
|
|
|
|
|
```toml
|
|
|
|
|
[dependencies]
|
|
|
|
|
maud = "*"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Then save the following to `src/main.rs`:
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
use maud::html;
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let name = "Lyra";
|
|
|
|
|
let markup = html! {
|
|
|
|
|
p { "Hi, " (name) "!" }
|
|
|
|
|
};
|
|
|
|
|
println!("{}", markup.into_string());
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-01-22 19:31:51 +13:00
|
|
|
|
`html!` takes a single argument:
|
|
|
|
|
a template using Maud's custom syntax.
|
|
|
|
|
This call expands to an expression of type [`Markup`][Markup],
|
|
|
|
|
which can then be converted to a `String` using `.into_string()`.
|
2018-11-24 16:13:36 +13:00
|
|
|
|
|
|
|
|
|
[Markup]: https://docs.rs/maud/*/maud/type.Markup.html
|
|
|
|
|
|
2021-01-22 19:31:51 +13:00
|
|
|
|
Run this program with `cargo run`,
|
|
|
|
|
and you should get the following:
|
2018-11-24 16:13:36 +13:00
|
|
|
|
|
2021-01-15 17:40:46 +13:00
|
|
|
|
```html
|
2018-11-24 16:13:36 +13:00
|
|
|
|
<p>Hi, Lyra!</p>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Congrats – you've written your first Maud program!
|
2020-11-02 12:53:27 +13:00
|
|
|
|
|
|
|
|
|
## Which version of Rust?
|
|
|
|
|
|
|
|
|
|
While Maud works well
|
|
|
|
|
on both stable and [nightly] versions
|
|
|
|
|
of Rust,
|
|
|
|
|
the error messages are slightly better
|
|
|
|
|
on nightly.
|
|
|
|
|
For this reason,
|
|
|
|
|
it is recommended to develop using nightly Rust,
|
|
|
|
|
but test and deploy using stable.
|
|
|
|
|
|
|
|
|
|
[nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
|