#dom #virtual-dom #syntax #jsx-like #snax

ritz

Virtual HTML DOM library for Rust with JSX-like syntax powered by Snax

1 unstable release

0.1.0 Feb 19, 2019

#4 in #jsx-like

Download history 1456/week @ 2025-09-28 687/week @ 2025-10-05 873/week @ 2025-10-12 495/week @ 2025-10-19 306/week @ 2025-10-26 272/week @ 2025-11-02 218/week @ 2025-11-09 331/week @ 2025-11-16 330/week @ 2025-11-23 335/week @ 2025-11-30 339/week @ 2025-12-07 287/week @ 2025-12-14 257/week @ 2025-12-21 353/week @ 2025-12-28 427/week @ 2026-01-04 415/week @ 2026-01-11

1,503 downloads per month
Used in 2 crates

MIT license

16KB
272 lines

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! {
        /* Ritz supports regular multi-line Rust comments. */
        <html>
            <head>
                /*
                    Literal strings need to be quoted, unlike JSX.
                    This makes whitespace much more explicit, which is
                    useful!
                */
                <title>"Hello, Snax!"</title>
            </head>
            <body>
                /*
                    Ritz supports embedding Rust expressions that return
                    `impl IntoIterator<HtmlContent>`. String and &str work
                    great here!
                */
                <h1>
                    { page_title }
                </h1>
            </body>
        </html>
    };

    // The result of the html! macro is ritz::HtmlContent.
    // It implements Display and gives you compact HTML without a doctype!
    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.

Dependencies

~440KB