avosetta
A fast, minimal html templating language for Rust.
about
avosetta is a minimal templating library for that utilises procedural macros
to generate as close to optimal code as possible for rendering HTML content
at runtime. It has no unsafe code, only a handful of dependencies, and does
allocate any values on the heap.
We implement a terse, simple syntax for specifying templates that is
straightforward to parse, has little ambiguity and integrates into Rust
code better. And unlike other templating libraries such as maud, our syntax
typically only has a single way of writing various constructs, reducing
code-style clashing. For more information, read the full syntax reference
here.
Optimisations include automatically escaping static string literals at
compile-time and collapsing contiguous push_str calls into a single one.
Therefore, if your html fragment is entirely static, the generated code will
just be a single push_str with a &'static str.
getting started
To start using avosetta, you'll first need to add our package to your
Cargo.toml manifest:
[]
= "0.1.0"
Then you can start writing HTML templates directly in your Rust source
code. We recommend that you import the prelude module to reduce unnecessary
qualifications, but that's up to you.
use *;
reference
The syntax that this macro accepts is unique to avosetta, however, it shares
some major similarities with crates such as maud and markup. All of these
crates implement a terse, pug-like syntax which integrates into rust code better
and is less error-prone.
Unlike the other crates, however, avosetta has a more minimal syntax.
elements
There are two types of elements that can be defined: normal and void.
void elements cannot have a body and must be terminated with a semicolon.
html!
attributes
Elements can also have attributes, which is a comma delimited list of
key=value pairs. Note, that attribute values can be dynamic (interpolated at
runtime), where as attribute names must be known at compile time.
html!
interpolation
The process of "injecting" or writing dynamic content into the HTML is
called interpolation. This might be used for displaying a local variable
containing a username, or for performing a conditional if check before
rendering some sub-content.
All interpolations start with an @, however, depending on the context,
different interpolations will be generated in the impl Html.
let x = 9;
html!
string literals
Whilst most content can be interpolated into the HTML at runtime, there
is a specific optimisation made for static string literals. When used without an
@, the string literals are automatically escaped at compile-time and rendered
using avosetta::raw.
html!