telegrinder-templating

This module is used with telegrinder framework. It is used to create text templates.


Keywords
python, telegrinder, framework, tool, templating, jinja2
License
MIT
Install
pip install telegrinder-templating==1.0.4

Documentation

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