Render Kit is a versatile and powerful command-line interface (CLI) tool designed for comprehensive template rendering. It supports multiple template engines and data sources, providing both flexibility and efficiency.
To use Render Kit, you have multiple options:
Download the latest release binary:
PATH
to make it easier to run such as /usr/local/bin
.Install via Go:
go install github.com/orellazri/renderkit@latest
Run the Docker image:
reaperberri/renderkit
Docker image.docker run --rm reaperberri/renderkit <args>
You need to run the renderkit
command with the following arguments as either command-line flags, or as a YAML configuration file passed via --config
.
Name | Description | Type |
---|---|---|
config |
Load configuration from YAML file | string |
input |
Template string to render | string |
input-file |
Template input file to render | string |
input-dir |
Template input directory to render | string |
exclude |
Exclude files/directories using path-based glob or file glob patterns | list |
output |
Output directory to write to | string |
datasource |
Datasource to use for rendering (scheme://path) ** | list |
data |
Data to use for rendering. Can be used to provide data directly | list |
engine |
Templating engine to use for rendering (Go Templates by default) | string |
allow-duplicate-keys |
Allow duplicate keys in datasources. If set, the last value found will be used | bool |
datasource
<scheme>://
, etc.) will be interpreted as plain files. Refer to Supported Datasources for available formats.env
scheme is supported for datasources.env://
will load all your environment variables as keys you can use in your templates.env://<env_var>
will load only that specific environment variable.path/to/myvars.env
will load the variables from an .env
file (the file must have a .env
suffix).Below are practical examples demonstrating the usage of renderkit
:
# Using a specific env var as a datasource
$ cat ds.yml
FN: "Doe"
$ echo 'Hello {{.FN}} {{.LN}}' | renderkit -ds env://LN -ds ds.yml
Hello John Doe
# Using a template string and envsubst engine
$ export LN="Doe"
$ echo 'Hello $FN $LN' | renderkit -i 'Hello $FN $LN' -e envsubst --data "FN=John"
Hello John Doe
# Using a template file with data from a JSON file
$ cat data.json
{
"names": {
"FN": "John",
"LN": "Doe"
}
}
$ cat file.tpl
Hello {{ lower .names.FN }} {{ upper .names.LN }}
$ renderkit -f file.tpl -ds data.json
Hello john DOE
# Render input directory [1.tpl, 2.tpl, 3.tpl] to output directory
$ renderkit --input-dir in/ --exclude 'in/[1-2].tpl' --output out/ --datasource data.yml --data myKey=myValue --engine jinja
# Output directory will contain [3.tpl] rendered files
# Use the two supported exclude patterns (path-based Render input directory [1.tpl, 2.tpl, 3.tpl, 1.txt] to output directory
$ renderkit --input-dir in/ --exclude 'in/[1-2].tpl' --exclude '*.txt' --datasource data.yml
# Output directory will contain [3.tpl] rendered files
input-dir: input/
output: output/
exclude:
- input/exclude[1-2].tpl
- input/other_*.tpl
datasource:
- data.yaml
- data2.json
engine: gotemplates
allow-duplicate-keys: true
Fork and clone the repository
Install pre-commit hooks:
pre-commit install
Run with:
go run .
task test # Run all tests (including integration)
task test SHORT=true # Run only unit tests