Use Jinja2 templates via cli
Project description
Jinja2 tools
Use Jinja2 templates via cli
Install
$ pip install jinja2-tools
Usage
Usage: jinja render [OPTIONS]
Options:
-d, --data TEXT PATH to YAML or JSON data file, URL or '-' for
stdin
-t, --template TEXT PATH to any file that uses Jinja, URL or '-' for
stdin
-v, --verbose
-tb, --no-trim-blocks Disable trim blocks
-lb, --no-lstrip-blocks Disable lstrip blocks
-o, --output PATH PATH for output, stdout by default
--help Show this message and exit.
Whitespace Control
trim_blocks
and lstrip_blocks
are used by default, to disable them use -tb
or -lb
respectively.
Examples
-
Use path from the filesystem for data & template:
➜ jinja2-tools git:(master) jinja render -d examples/data.yaml -t examples/template.sh (1) ip access-list extended al-hq-in (2) (3) remark Allow traffic from hq to local office (4)(2) (3) permit 10.0.0.0/22 10.100.0.0/24 (5)(6) (7) # All ACLs have been generated
-
Use stdin for data & URL for template, also disable trim blocks & lstrip blocks:
➜ jinja2-tools git:(master) jinja render -d - -t https://raw.githubusercontent.com/Avielyo10/jinja2-tools/master/examples/template.sh -lb -tb < examples/data.yaml (1) ip access-list extended al-hq-in (2) (3) remark Allow traffic from hq to local office (4) (2) (3) permit 10.0.0.0/22 10.100.0.0/24 (5) (6) (7) # All ACLs have been generated
-
Verbose:
➜ jinja2-tools git:(master) jinja render -d examples/data.yaml -t examples/template.sh -v ---------- [Data] ---------- { "access_lists": { "al-hq-in": [ { "action": "remark", "text": "Allow traffic from hq to local office" }, { "action": "permit", "src": "10.0.0.0/22", "dst": "10.100.0.0/24" } ] } } ---------- [Template] ---------- {% for acl, acl_lines in access_lists.items() %}(1) ip access-list extended {{ acl }} {% for line in acl_lines %}(2) (3){% if line.action == "remark" %} remark {{ line.text }} (4){% elif line.action == "permit" %} permit {{ line.src }} {{ line.dst }} (5){% endif %} {% endfor %}(6) {% endfor %}(7) # All ACLs have been generated (1) ip access-list extended al-hq-in (2) (3) remark Allow traffic from hq to local office (4)(2) (3) permit 10.0.0.0/22 10.100.0.0/24 (5)(6) (7) # All ACLs have been generated
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jinja2-tools-1.0.3.tar.gz
(3.8 kB
view details)
Built Distribution
File details
Details for the file jinja2-tools-1.0.3.tar.gz
.
File metadata
- Download URL: jinja2-tools-1.0.3.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7863ca33194dc28991a69f935a7aa41e7cfe9409782443ad17d1996d4680cc2d |
|
MD5 | 485766e69958a1176b36624c71bb47be |
|
BLAKE2b-256 | 76be79a829e1896036ec0d141cd1a58fa86104134d0bf6db25f93df5373ed2ee |
File details
Details for the file jinja2_tools-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: jinja2_tools-1.0.3-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5eb0ea0ddce7fb662b12b041806ed167c42522f0b7968f6d9d20087fbbf0d01 |
|
MD5 | d133e739632132329fd5912e748a9197 |
|
BLAKE2b-256 | d4922e20b38eaf837f2e8cb658cce7f8d63670a25393bda83c8a06d0ad45a8ed |