Singleton class that provides decorators to create custom **`filters`** and **`tags`** for Jinja templates
Project description
Dinja: Jinja Tool-Kit
Dinja
is a singleton class that provides decorators to create custom filters
and tags
for Jinja templates. It also allows you to load these filters and tags into a Jinja environment.
Usage
- Create custom
filters
using the@Dinja.filter
decorator. - Create custom
tags
using the@Dinja.tag
decorator. - Load custom filters and tags into a Jinja environment using
Dinja.load
.
Method: filter
Decorator to create custom filters for Jinja templates.
Parameters:
method
(function): The filter function.params
(dict): Optional arguments for the filter.
Usage:
from dinja import Dinja
dinja = Dinja()
@dinja.filter(is_safe=True)
def my_filter(value):
return "Filtered: " + value
@dinja.filter
def my_other_filter(value):
return "Other Filtered: " + value
Returns:
- function: The wrapped filter function.
Method: tag
Decorator to create custom tags for Jinja templates.
Parameters:
method
(function): The tag function.params
(dict): Optional arguments for the tag.
Usage:
from dinja import Dinja
dinja = Dinja()
@dinja.tag(is_safe=True)
def my_tag(content, caller):
return '<h1>' + content + '</h1>'
@dinja.tag
def my_other_tag(content, caller):
return '<div>' + content + '</div>'
Returns:
- Extension: The custom Jinja2 extension class.
Method: load
Load custom filters and tags into a Jinja environment.
Parameters:
jinja_env
(jinja2.Environment): The Jinja environment to load into.
Example
from jinja2 import Environment
dinja = Dinja()
env = Environment()
dinja.load(env)
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
dinja-0.1.0.tar.gz
(3.1 kB
view details)
Built Distribution
dinja-0.1.0-py3-none-any.whl
(3.6 kB
view details)
File details
Details for the file dinja-0.1.0.tar.gz
.
File metadata
- Download URL: dinja-0.1.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87a1e0a09dbb5c237ff4788ded7c3f68f49f5c88414340017743e9397472ae4c |
|
MD5 | a93a189e20faac5103be5363740f6aeb |
|
BLAKE2b-256 | bd978fbd175baa2b26cb44e20519751a75dc8b8298458eb932e791ac677dee8f |
Provenance
File details
Details for the file dinja-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: dinja-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f6702ebc6f53643c9f742991bf41fcfb329d902b26bb776491b3b9c2e9015dc |
|
MD5 | 6bd66370e8290cdf4399a75a6f0cd3f7 |
|
BLAKE2b-256 | 8a4ac47f379df5c6b4863fa69157a40b19fcd1fc1e6c9838c7d9b5198c92e303 |