Skip to main content

This module is intended for the Telegrinder framework. It allows for text templating.

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

telegrinder_templating-1.0.3.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

telegrinder_templating-1.0.3-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page