terender
- Render tera templates from data filesterender
is a simple command-line tool for rendering template files in
tera template format simply using structured
input data from a file.
The only supported file format for the structured data is JSON for now, but this is likely to change. If you're interested in adding a new format that is supported by serde, please either submit an issue or create a merge request.
For information on how to write tera
templates, take a look at their
documentation.
A short usage example for transforming from a simple markdown template file with some json data into the rendered markdown.
Contents of products.template.md
:
```markdown
{% for category in categories %}
{% for article in category.articles -%} * {{ article }} {% endfor -%}
{% endfor -%} ```
Contents of products.json
:
json
{
"categories": [
{
"name": "Sports",
"articles": [
"Training shoes",
"Bicycle"
]
},
{
"name": "Electronics",
"articles": [
"Mobile phone",
"USB memory stick",
"E-Book reader"
]
},
{
"name": "Food",
"articles": [
"Cheese",
"Apple",
"Milk"
]
}
]
}
Running terender
:
```
$ terender products.template.md products.json
You need a working installation of the rust development environment, namely
rustc
and cargo
. These can either be obtained from your operating
system if it provides it (e.g. apt install rustc
on Debian-based
operating systems), or through https://rustup.rs.
The typical command for installation is:
cargo install terender
If you already have a version of the tool installed and want to overwrite
it, you need to add the -f
parameter:
cargo install -f terender
This tool is just a very small implementation plumbing what already exists. The heavy lifting is done in library crates used by this tool: * tera * serde, serde_json * structopt * anyhow
It is all because of these excellent implementations that this crate can be short and easily implemented.