/j2y

A Jinja2 Template CLI

Primary LanguagePythonApache License 2.0Apache-2.0

j2y - A Jinja2 CLI

Code Style: Black

Render Jinja2 templates on the command line using a YAML, JSON or HCL file as input for the render context.

This is a fork of Christian Haudum's great Jinja2 CLI tool j2y. The purpose of this fork is to provide active maintenance, bug fixes and new features.

Installation

j2y is installed using pip:

$ pip install -e git+https://github.com/crate/j2y.git@master#egg=j2y

Note

The name of this Python package is j2y, but it will be renamed to j2-cli with the next major release.

Usage

By default, the j2cli command takes a YAML file as input:

$ j2cli template.j2 < values.yaml

Alternatively you can use JSON or HCL as input format:

$ j2cli template.j2 -f json < values.json
$ j2cli template.j2 -f hcl < values.hcl

It's also possible to provide multiple input files:

$ j2cli template.j2 --context v1.yaml --context v2.yaml

Run j2cli -h to see all available options.

Template Variables

Additionally to the variables provided by the input file, j2cli also provides built-in default variables. These variables are:

meta.date:

Type: datetime

Value: Current UTC datetime object

meta.platform:

Type: dict

Value: Output of platform.uname()

env:

Type: dict

Value: All environment variables (output of os.environ).

Documentation

The tests located in the docs/ folder can also be built into HTML using Sphinx:

(env) $ sphinx-build -E -W docs/ _build/