https://github.com/phil65/jinjarope
Jinja2 utilities & loaders
https://github.com/phil65/jinjarope
Last synced: 4 months ago
JSON representation
Jinja2 utilities & loaders
- Host: GitHub
- URL: https://github.com/phil65/jinjarope
- Owner: phil65
- License: mit
- Created: 2023-11-03T15:31:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-30T02:33:45.000Z (6 months ago)
- Last Synced: 2024-10-30T05:06:56.431Z (6 months ago)
- Language: Python
- Size: 2.95 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - phil65/jinjarope - Jinja2 utilities & loaders (Python)
README
# jinjarope
![]()
[](https://pypi.org/project/jinjarope/)
[](https://pypi.org/project/jinjarope/)
[](https://pypi.org/project/jinjarope/)
[](https://pypi.org/project/jinjarope/)
[](https://pypi.org/project/jinjarope/)
[](https://pypi.org/project/jinjarope/)
[](https://pypi.org/project/jinjarope/)
[](https://pypi.org/project/jinjarope/)
[](https://pypi.org/project/jinjarope/)
[](https://github.com/phil65/jinjarope/releases)
[](https://github.com/phil65/jinjarope/graphs/contributors)
[](https://github.com/phil65/jinjarope/discussions)
[](https://github.com/phil65/jinjarope/forks)
[](https://github.com/phil65/jinjarope/issues)
[](https://github.com/phil65/jinjarope/pulls)
[](https://github.com/phil65/jinjarope/watchers)
[](https://github.com/phil65/jinjarope/stars)
[](https://github.com/phil65/jinjarope)
[](https://github.com/phil65/jinjarope/commits)
[](https://github.com/phil65/jinjarope/releases)
[](https://github.com/phil65/jinjarope)
[](https://github.com/phil65/jinjarope)
[](https://github.com/phil65/jinjarope)
[](https://github.com/phil65/jinjarope)
[](https://codecov.io/gh/phil65/jinjarope/)
[](https://github.com/psf/black)
[](https://pyup.io/repos/github/phil65/jinjarope/)[Read the documentation!](https://phil65.github.io/jinjarope/)
## How to install
### pip
The latest released version is available at the [Python package index](https://pypi.org/project/mknodes).
``` py
pip install jinjarope
```
With CLI:``` py
pip install jinjarope[cli]
```## Quick guide
Jinjarope contains a range of Jinja2 loaders (including fsspec-based ones) as well as a `jinja2.Environment` subclass with added functionality.
For debugging purposes, an FsSpec filesystem implementation for jinja2 loaders is also included.
### FsSpecFileSystemLoader
This loader can be used like a FileSystemLoader, but also works on any fsspec-supported
remote path.
Using the `dir::` prefix, any folder can be set as root.``` py
# protocol path
loader = jinjarope.FsSpecFileSystemLoader("dir::github://phil65:jinjarope@main/tests/testresources")
env = jinjarope.Environment(loader=loader)
env.get_template("testfile.jinja").render()# protocol and storage options
loader = jinjarope.FsSpecFileSystemLoader("github", org="phil65", repo="jinjarope")
env = jinjarope.Environment(loader=loader)
env.get_template("README.md").render()# fsspec filesystem
fs = fsspec.filesystem("github", org="phil65", repo="jinjarope")
loader = jinjarope.FsSpecFileSystemLoader(fs)
env = jinjarope.Environment(loader=loader)
env.get_template("README.md").render()
```### FsSpecProtocolPathLoader
This loader accepts any FsSpec protocol path to be used directly.
A complete protocol URL to the template file is required.``` py
loader = jinjarope.FsSpecProtocolPathLoader()
env = jinjarope.Environment(loader=loader)
env.get_template("github://phil65:jinjarope@main/tests/testresources/testfile.jinja").render()
```### NestedDictLoader
``` toml
[example]
template = "{{ something }}"
```
``` py
content = tomllib.load(toml_file)
loader = jinjarope.NestedDictLoader(content)
env = jinjarope.Environment(loader=loader)
env.get_template("example/template")
```### General loader information
**jinjarope** also contains subclasses for all default **jinja2** loaders. These loaders
have implementations for some magic methods (`__eq__`, `__hash__`, `__repr__`, , `__getitem__`).``` py
loader = jinjarope.FileSystemLoader(...)
template_source = loader["path/to/template.jinja"]
```The loaders can also get ORed to return a ChoiceLoader.
``` py
choice_loader = jinjarope.FileSystemLoader(..) | jinjarope.PackageLoader(...)
```Prefix loaders can get created using pathlib-style string concatenations
``` py
prefix_loader = "path_prefix" / jinjarope.FileSystemLoader(...)
```### Additional filters / tests
Check out the documentation for a list of built-in filters and tests!