Fast Mustache template engine implementation in pure Rust.
Ramhorns::get
now takes &str
as an argument (see #70, #69, thanks to @lcnr for reporting)rename_all
attribute similar to serde
and optional index-based sections by @tiagolobocastro (#63)Debug
for Ramhorns
& Template
(#72, thanks to @dsaghliani for reporting)Full Changelog: https://github.com/maciejhirsz/ramhorns/compare/v0.14.0...v1.0.0
This patch adds great work from @grego:
{{#section}}{{field}}{{/section}}
you can just write {{section field}}
. You can also use this nesting for opening and closing of sections (#59).Ramhorns
struct can now take a custom hasher as a generic param for its internal partials HashMap
(also #59).pulldown_cmark
is now an optional dependency (enabled by default).#[md]
has been replaced with #[ramhorns(md)]
for consistency. (#56)#[ramhorns(callback = path::to::fn)]
attribute which can execute arbitrary code for inserting values into template, see tests/main.rs
for an example. (#56, #58)Error::NotFound(Box<str>)
which contains the name of a partial for which a template file couldn't be found.Content
is now implemented for arrays and ArrayVec
from the arrayvec
crate (#49, by @grego).Ramhorns::from_folder_with_extension
to which allows to use custom file extensions for templates (#46, by @halvko).#[derive(Content)]
macro no longer errors if the Result
type has been aliased in current scope (#37).Fixes an issue with inverse sections {{^...}}
missing parent variables (#36).
[ramhorns(flatten)]
that works similar to #[serde(flatten)]
, allowing composed structs to act as a single mapping inside templates. This is best illustrated with an example:
#[derive(Content)]
pub struct Parent<'a> {
title: &'a str,
#[ramhorns(flatten)]
child: Child<'a>,
}
#[derive(Content)]
pub struct Child<'a> {
body: &'a str,
}
let tpl = Template::new("<h1>{{title}}</h1><head>{{body}}</head>").unwrap();
let html = tpl.render(&Parent {
title: "This is the title",
child: Child {
body: "This is the body",
}
});
assert_eq!(html, "<h1>This is the title</h1><head>This is the body</head>");