Code Monkey home page Code Monkey logo

telegrinder_templating's Introduction

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

telegrinder_templating's People

Contributors

luwqz1 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.