telegrinder-templating 1.0.4

Creator: bradpython12

Last updated:

0 purchases

telegrinder-templating 1.0.4 Image
telegrinder-templating 1.0.4 Images

Languages

Categories

Add to Cart

Description:

telegrindertemplating 1.0.4

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

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.