This module is used with telegrinder framework. It is used to create text templates.
Project description
telegrinder templating tool
This module is used with telegrinder framework. It is used to create text templates.
Install using PyPI:
pip install telegrinder-templating
Documentation
There is templating in order to avoid using large text. Module telegrinder_templating
has an ABCTemplating
interface for creating templating classes.
from telegrinder_templating import ABCTemplating
telegrinder_templating
has class JinjaTemplating
to work with jinja templates.
from telegrinder_templating import JinjaTemplating
JinjaTemplating
methods:
render(template_name: str, **data: Any) -> str
render_from_string(template_source: str, **data: Any) -> str
@add_filter(key: str | None) -> wrapper(func: JinjaFilter)
Example:
import asyncio
import pathlib
import jinja2
from telegrinder_templating import JinjaTemplating
jt = JinjaTemplating(pathlib.Path(__file__).resolve().parent / "templates")
@jt.add_filter("title")
def title_string(value: str, must_strip: bool = False) -> str:
if must_strip:
return value.strip().title()
return value.title()
async def main():
await jt.render("template.j2", digits=[1, 2, 3])
await jt.render_from_string("{{ name|title(must_strip=True) }}", name=" alex")
asyncio.run(main())
More details about Jinja
can be found HERE
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
Built Distribution
File details
Details for the file telegrinder_templating-1.0.4.tar.gz
.
File metadata
- Download URL: telegrinder_templating-1.0.4.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/6.2.0-26-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92bdd5bb869fba69d55c8d8835aa4ec4145a4bc0598f54b114fa1f69c0e1f54f |
|
MD5 | bac2b005bf7531a09ee533be7767dba2 |
|
BLAKE2b-256 | b728deeeb6168ea9c1882a410d3780a090a320ec4eb59f28785a1ebfc6da2952 |
File details
Details for the file telegrinder_templating-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: telegrinder_templating-1.0.4-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/6.2.0-26-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 141183728fbc05fdda1fd54053338762714f27d82b1a642289f8c12dd037afad |
|
MD5 | 00323288915a555225265846503c746c |
|
BLAKE2b-256 | 4e8a09ff1ebd050d09bcf18469a05e4875adc184e85e26906848019a9eb65e83 |