Ritz
Ritz is a simple templating library that has JSX-like syntax
powered by Snax.
Requirements
Ritz requires Rust 1.32 or newer.
Some things are still a bit in flux, so I'm sorry in advance if I break
anything!
Examples
Simple Page
use ritz::html;
fn main() {
let page_title = "Hello, world, from Snax!";
let page = html! {
<html>
<head>
<title>"Hello, Snax!"</title>
</head>
<body>
<h1>
{ page_title }
</h1>
</body>
</html>
};
println!("<!doctype html>");
println!("{}", page);
}
Composition via functions
Ritz is designed to work well when using functions to reuse pieces of HTML!
use ritz::{html, Fragment, HtmlContent};
fn user_widget<'a>(name: &'a str, age: u32) -> HtmlContent<'a> {
html! {
<div class="user">
{ name } " is " { age.to_string() } " years old!"
</div>
}
}
fn users() -> HtmlContent<'static> {
let users = vec![
("Gandalf", 34),
("Arwen Undómie", 75),
("Primula Brandybuck", 133),
];
html! {
<div class="users">
{ Fragment::new(users.iter().map(|(name, age)| user_widget(name, *age))) }
</div>
}
}
License
Ritz is available under the MIT license. See LICENSE.txt for
details.