Metadata-Version: 2.1
Name: telegrinder-templating
Version: 1.0.2
Summary: This module is intended for the Telegrinder framework. It allows for text templating.
Home-page: https://github.com/luwqz1/telegrinder_templating
License: MIT
Keywords: python,telegrinder framework,tool,templating,telegrinder tool,jinja2
Author: Geogry howl
Author-email: howluwqz1@gmail.com
Requires-Python: >=3.11,<4.0
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: jinja2 (>=3.1.2,<4.0.0)
Project-URL: Repository, https://github.com/luwqz1/telegrinder_templating
Description-Content-Type: text/markdown

# telegrinder templating tool

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

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.

```python
from telegrinder_templating import ABCTemplating
```

`telegrinder_templating` has class `JinjaTemplating` to work with jinja templates.

```python
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:
```python
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*](https://jinja.palletsprojects.com/en)

