boilerplate
is a statically-checked Rust template engine with no runtime
dependencies. There are two ways to use boilerplate,
boilerplate::boilerplate
, a function-like macro, and
boilerplate::Boilerplate
, a derive macro.
Function-like Macro
use boilerplate;
let foo = true;
let bar: = Ok;
let output = boilerplate!;
assert_eq!;
Derive Macro
Derive Boilerplate
on the type you want to use as a template context:
use Boilerplate;
boilerplate
template code and interpolations are Rust, so errors are checked
at compile time and the template language is easy to learn:
%% if self.foo {
Foo was true!
%% }
%% match &self.bar {
%% Ok(ok) => {
Pretty good: {{ ok }}
%% }
%% Err(err) => {
Not so great: {{ err }}
%% }
%% }
The Boilerplate
macro provides a Display
implementation, so you can
instantiate a template context and convert it to a string:
let rendered = MyTemplateTxt .to_string;
Or use it in a format string:
println!;
boilerplate
's implementation is exceedingly simple. Try using
cargo-expand to expand the
Boilerplate
macro and inspect derived Display
implementations and debug
template issues.
Quick Start
Add boilerplate
to your project's Cargo.toml
:
[]
= "*"
Create a template in templates/my-template.txt
:
Foo is {{self.n}}!
Define, instantiate, and render the template context:
use Boilerplate;
assert_eq!;
Examples
See the docs for more information and examples.