Fast Mustache template engine implementation in pure Rust.
MPL-2.0 License
Bot releases are hidden (Show)
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
Published by maciejhirsz over 2 years ago
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).Published by maciejhirsz almost 3 years ago
#[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)Published by maciejhirsz over 3 years ago
Error::NotFound(Box<str>)
which contains the name of a partial for which a template file couldn't be found.Published by maciejhirsz over 3 years ago
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).Published by maciejhirsz about 4 years ago
#[derive(Content)]
macro no longer errors if the Result
type has been aliased in current scope (#37).Published by maciejhirsz about 4 years ago
Fixes an issue with inverse sections {{^...}}
missing parent variables (#36).
Published by maciejhirsz about 4 years ago
Published by maciejhirsz over 4 years ago
Published by maciejhirsz over 4 years ago
[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>");
Published by maciejhirsz over 4 years ago
#[derive(Content)]
struct Data<'a> {
#[ramhorns(skip)]
secret: &'a str,
#[ramhorns(rename = "new")]
old: &'a str,
}
Published by maciejhirsz over 4 years ago
Template::from_file
, you can still use Template::new
to create local templates from strings.Templates
has been renamed to Ramhorns
.Ramhorns::lazy
and Ramhorns::from_file
, which allows you to do what Template::from_file
could do before:use ramhorns::Ramhorns;
let mut tpls = Ramhorns::lazy("./templates").unwrap();
let tpl = tpls.from_file("hello.html").unwrap();
Published by maciejhirsz over 4 years ago
Template
struct.Templates
internal hash map is now using a faster hashing algorithm.Published by maciejhirsz over 4 years ago
Content
can now be implemented for unsized types (#22).Published by maciejhirsz over 4 years ago
{{^foo}}missing{{/foo}}
would not render if the field foo
(or a key "foo"
in a HashMap
etc.) was missing in the Content
(#21).Published by maciejhirsz over 4 years ago
Error
now implements std::error::Error
.Published by maciejhirsz over 4 years ago
{{> file_descriptor}}
syntax.Templates
API for processing entire folders, including partials, at once.Thanks to @grego for the PR #16!
Published by maciejhirsz over 5 years ago
#[md]
attribute.{{& variable}}
as an alternative to {{{ variable }}}
for unescaped printing.