orellazri / renderkit

A swiss army knife CLI tool for rendering templates
GNU General Public License v3.0
22 stars 0 forks source link
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.

CodeQL Test

Features

Supported Engines

Supported Datasources

Usage

To use Render Kit, you have multiple options:

  1. 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.
  2. Install via Go:

    • Ensure that you have Go installed on your machine.
    • Run the following command:
      go install github.com/orellazri/renderkit@latest
  3. 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>

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

**Notes on datasource

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_*.tpl
datasource:
  - data.yaml
  - data2.json
engine: gotemplates
allow-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