maud/docs/content/getting-started.md
2019-03-16 16:29:31 +13:00

56 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Getting started
## Install nightly Rust
Maud requires the nightly version of Rust.
If you're using `rustup`,
see the [documentation][rustup]
for how to install this version.
[rustup]: https://github.com/rust-lang/rustup.rs/blob/master/README.md#working-with-nightly-rust
## 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
#![feature(proc_macro_hygiene)]
extern crate maud;
use maud::html;
fn main() {
let name = "Lyra";
let markup = html! {
p { "Hi, " (name) "!" }
};
println!("{}", markup.into_string());
}
```
`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()`.
[Markup]: https://docs.rs/maud/*/maud/type.Markup.html
Run this program with `cargo run`, and you should get the following:
```
<p>Hi, Lyra!</p>
```
Congrats you've written your first Maud program!