Convenience wrapper around Jinja for scripts
Project description
j2scr: Avoid Jinja2 boilerplate for small scripts
This is a very simple package that wraps Jinja2.
The purpose is to avoid boilerplate for micro-scripts that use jinja.
This is achieved by setting a default jinja environment, and a loader searching relatively (unless
an absolute path is given), and providing utility functions render, render_to_file, and
set_options.
Use as such:
from j2scr import render, render_to_file, set_options
# You can render into a variable
string_with_content = render("../my_template.txt.j2", var=2, var2='Michael')
# Or into a file
render_to_file("../my_template.txt.j2", "my_content.txt" var=2, var2='Michael')
# You can change the loader/environment parameters (do it before rendering, of course):
set_options(encoding="latin-1", trim_blocks=True)
# Alternatively the environment and loaders are available as attributes.
If for some reason you want the minimalism of j2scr but without the global settings (eg. for a
class), you can use the j2scr.J2Scr class which works the same way but has it's own env and loader.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
j2scr-1.0.1.tar.gz
(2.6 kB
view details)
File details
Details for the file j2scr-1.0.1.tar.gz.
File metadata
- Download URL: j2scr-1.0.1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.2 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69cae5a9495d68d45cb2b87907d3bcedb1b5104a6be30985654ae06aade596c0
|
|
| MD5 |
497eea7095d2d002a3bb7fa33dc77782
|
|
| BLAKE2b-256 |
714b9118430428c844778df35b66f91723073e12807e8162bf34dc5234b29530
|