2 releases
Uses new Rust 2024
new 0.0.2 | May 6, 2025 |
---|---|
0.0.1 | Apr 29, 2025 |
#295 in #value
103 downloads per month
3KB
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
- fragments
- quoted and unquoted text nodes
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(task).collect::<Vec<String>>().join("")}
</ul>
</section>
}
}
Dependencies
~0.5–1MB
~20K SLoC