sjabloon

Crates.iosjabloon
lib.rssjabloon
version0.0.2
created_at2025-04-29 18:42:41.431267+00
updated_at2025-05-06 16:27:40.344861+00
descriptiona crate for templating html
homepage
repositoryhttps://github.com/snx-rs/sjabloon
max_upload_size
id1653914
size11,273
Julian (julianollivieira)

documentation

https://docs.rs/sjabloon

README

sjabloon

sjabloon is a modern templating engine for Rust with a JSX-like syntax. writing templates is comparable to writing JSX on the server.

overview of features

you can define templates using the template macro. this macro will be transpiled to a format macro call at build-time, which will result in a string at run-time. "components" are just functions/closures which return a string.

elegant and simple syntax
  • use braced blocks to write arbitrary Rust code
  • braces can be omitted for attribute values
  • quoted and unquoted text nodes
  • fragments
fn article(article: Article) -> String {
    template! {
        <a href=format!("articles/{}", article.slug)>
            <article>
                <img
                    src=article.cover.url
                    alt=article.cover.alt
                    width="400"
                    height="200"
                />
                <h2>{article.title}</h2>
                <small>author: {article.author}</small>
            </article>
        </a>
    }
}

fn articles_list(articles: Vec<Article>) -> String {
    template! {
        <section>
            <h1>articles</h1>
            <ul>
                {articles.into_iter().map(article).collect::<Vec<String>>().join("")} 
            </ul>
        </section>
    }
}
Commit count: 6

cargo fmt