Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

j2templify

j2templify is a minimal, fast, and flexible CLI tool written in Rust that renders Jinja2-style templates using YAML configuration files.

It supports variable overrides, whitespace cleanup, autoescaping, and portable deployment (including musl-based static builds). Ideal for configuration file generation, Dockerfile templating, and CI/CD workflows.


✨ Features

  • 🧠 Simple CLI: Just --template and --vars
  • 🎯 Supports nested YAML structures
  • 🔄 Command-line variable overrides via --set key=value
  • 🧼 Optional blank-line cleanup with --clean-newlines
  • 🔒 Optional autoescaping with --enable-autoescape
  • 🧳 Easy cross-compilation with musl for Linux portability

📦 Installation

Clone the project and build with Rust:

git clone https://github.com/your-username/j2templify.git
cd j2templify
cargo build --release

To install the binary globally (optional):

sudo cp target/release/j2templify /usr/local/bin/

For static musl binary (fully portable Linux build):

rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-musl

🚀 Usage

Basic Template Rendering:

j2templify -t template.j2 -v config.yaml

Output to File:

j2templify -t template.j2 -v config.yaml -o output.txt

Override Variables via CLI:

j2templify -t template.j2 -v config.yaml \
  --set os=alinux \
  --set alinux.base_image='"alinux3:dev"'

Note: Values passed to --set are parsed as YAML, so use "..." for strings.

Remove Extra Blank Lines:

j2templify -t template.j2 -v config.yaml --clean-newlines

Enable Autoescaping:

j2templify -t template.j2 -v config.yaml --enable-autoescape

Autoescaping is disabled by default. Use this flag to enable it for safer HTML or XML output.


📄 Template Example

  • Dockerfile.j2:
# syntax=docker/dockerfile:1
{% if os == "alinux" %}
FROM {{ alinux.base_image }}
{% else %}
FROM {{ ubuntu.base_image }}
{% endif %}
  • config.yaml:
os: "ubuntu"
alinux:
  base_image: "alinux3:latest"
ubuntu:
  base_image: "ubuntu:22.04"

🧪 Development

To run with test files during development:

cargo run -- -t Dockerfile.j2 -v config.yaml --clean-newlines

To run with CLI overrides:

cargo run -- -t Dockerfile.j2 -v config.yaml \
  --set os=alinux \
  --set alinux.base_image='"alinux3:preview"'

To test with autoescaping enabled:

cargo run -- -t template.j2 -v config.yaml --enable-autoescape

🙌 Acknowledgements

Inspired by Jinja2, tera, and jintemplify. Built for real-world template generation needs, with control over output and flexibility for automation pipelines.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages