Skip to content

Repository files navigation

Render Kit Logo

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.

CodeQLTest

Features

  • 🛠️ Supports multiple template engines
  • 🌐 Integrates with various data sources
  • 🎛️ Customizable rendering options
  • ⚡ Lightweight and fast
  • 🌍 Cross-platform compatibility
  • 📦 Single binary

Supported Engines

Supported Datasources

  • Environment variables
  • YAML
  • JSON
  • TOML
  • HTTP/S URL (For web URLs, ensure the response's Content-Type matches the file format's MIME type. Environment variable file types are not supported yet)

Usage

To use Render Kit, you have multiple options:

  • Download the latest release binary:

    • Visit the releases page and download the latest binary for your operating system. It's recommended to move the binary to a directory in your PATH to make it easier to run such as /usr/local/bin.
  • Run the Docker image:

    • If you prefer using Docker, you can run the reaperberri/renderkit Docker image.
    • Make sure you have Docker installed on your machine.
    • Run the following command:
      docker run --rm reaperberri/renderkit <args>
  • Install with go install:

    • Ensure that you have Go installed on your machine.
    • Run the following command:
      go install github.com/orellazri/renderkit@latest

    Please note that this method produces a binary that may not be versioned correctly.

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.

NameDescriptionType
configLoad configuration from YAML filestring
inputTemplate string to renderstring
input-fileTemplate input file to renderstring
input-dirTemplate input directory to renderstring
excludeExclude files/directories using path-based glob or file glob patternslist
outputOutput directory to write tostring
datasourceDatasource to use for rendering (scheme://path) **list
dataData to use for rendering. Can be used to provide data directlylist
engineTemplating engine to use for rendering (Go Templates by default)string
allow-duplicate-keysAllow duplicate keys in datasources. If set, the last value found will be usedbool

**Notes on datasource

  • Inputs not utilizing a URL scheme (<scheme>://, etc.) will be interpreted as plain files. Refer to Supported Datasources for available formats.
  • For now, only the env scheme is supported for datasources.
  • Using just env:// will load all your environment variables as keys you can use in your templates.
  • Using env://<env_var> will load only that specific environment variable.
  • Specifying a path like 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

Example YAML Configuration File

input-dir: input/output: output/exclude:
- input/exclude[1-2].tpl
- input/other_*.tpldatasource:
- data.yaml
- data2.jsonengine: gotemplatesallow-duplicate-keys: true

Development

Prerequisites

Running locally

  1. Fork and clone the repository

  2. Install pre-commit hooks:

    pre-commit install
  3. Run with:

    go run .

Running tests

task test# Run all tests (including integration)
task test SHORT=true # Run only unit tests

About

A swiss army knife CLI tool for rendering templates

Resources

Stars

27 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages