muffin-jinja2


Namemuffin-jinja2 JSON
Version 1.8.1 PyPI version JSON
download
home_pagehttps://github.com/klen/muffin-jinja2
SummarySupport Jinja2 templates for Muffin Framework
upload_time2024-07-31 17:30:47
maintainerNone
docs_urlNone
authorKirill Klenov
requires_python<4.0,>=3.9
licenseMIT
keywords asyncio trio asgi web muffin jinja jinja2
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Muffin-Jinja2
#############

.. _description:

**Muffin-Jinja2** -- Support Jinja2 templates for Muffin_ Framework

.. _badges:

.. image:: https://github.com/klen/muffin-jinja2/workflows/tests/badge.svg
    :target: https://github.com/klen/muffin-jinja2/actions
    :alt: Tests Status

.. image:: https://img.shields.io/pypi/v/muffin-jinja2
    :target: https://pypi.org/project/muffin-jinja2/
    :alt: PYPI Version

.. _contents:

.. contents::

.. _requirements:

Requirements
=============

- python >= 3.9

.. _installation:

Installation
=============

**Muffin-Jinja2** should be installed using pip: ::

    pip install muffin-jinja2

.. _usage:

Usage
=====

.. code-block:: python

    import muffin
    import muffin_jinja2

    # Create Muffin Application
    app = muffin.Application('example')

    # Initialize the plugin
    # As alternative: jinja2 = Jinja2(app, **options)
    jinja2 = muffin_jinja2.Plugin()
    jinja2.setup(app, template_folders=['src/templates'])

    # Use it inside your handlers
    @app.route('/')
    async def index(request):
        context = {'var': 42}
        return await jinja2.render('index.html', **context)


Options
-------

==================== ==================== ====================
Name                 Default value        Description
-------------------- -------------------- --------------------
**auto_reload**      ``False``            Auto reload changed templates
**cache_size**       ``50``               Cache templates
**extensions**       ``None``             Enable Jinja2 Extensions (``None | list``)
**loader**           ``FileSystemLoader`` Template loader
**encoding**         ``utf-8``            Default encoding for file loader
**template_folders** ``['templates']``    List of template folders
==================== ==================== ====================


You are able to provide the options when you are initiliazing the plugin:

.. code-block:: python

    jinja2.init(app, template_folders=['src/templates'], auto_reload=True)


Or setup it inside ``Muffin.Application`` config using the `jinja2_` prefix for example:

.. code-block:: python

   JINJA2_AUTO_RELOAD = True

   JINJA2_TEMPLATE_FOLDERS = ['tmpls']

``Muffin.Application`` configuration options are case insensitive


Tunning
-------

.. code-block:: python

    # Register custom context processor
    # could be a function/coroutine
    @jinja2.add_context
    def custom_context():
        return { 'VAR': 'VALUE' }

    # Register a function into global context
    @jinja2.add_global
    def sum(a, b):
        return a + b

    # Register a function with a different name
    @jinja2.add_global('div')
    def mod(a, b):
        return a // b

    # Register a filter
    @jinja2.add_filter
    def test(value, a, b=None):
        return a if value else b

    # Register a filter with a different name
    @jinja2.add_filter('bool')
    def boolean(value):
        return bool(value)

    @app.route('/')
    async def index(request):
        """ Check for user is admin. """
        local_context = {'key': 'value'}
        return await jinja2.render('index.html', **local_context)


.. _bugtracker:

Bug tracker
===========

If you have any suggestions, bug reports or
annoyances please report them to the issue tracker
at https://github.com/klen/muffin-jinja2/issues

.. _contributing:

Contributing
============

Development of Muffin-Jinja2 happens at: https://github.com/klen/muffin-jinja2


Contributors
=============

* klen_ (Kirill Klenov)

.. _license:

License
========

Licensed under a `MIT license`_.

.. _links:


.. _klen: https://github.com/klen
.. _Muffin: https://github.com/klen/muffin

.. _MIT license: http://opensource.org/licenses/MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/klen/muffin-jinja2",
    "name": "muffin-jinja2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "asyncio, trio, asgi, web, muffin, jinja, jinja2",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/50/03/46606703d026578df334106f72ea5cc32f4bc0244bfa150f783f1d9ea1fd/muffin_jinja2-1.8.1.tar.gz",
    "platform": null,
    "description": "Muffin-Jinja2\n#############\n\n.. _description:\n\n**Muffin-Jinja2** -- Support Jinja2 templates for Muffin_ Framework\n\n.. _badges:\n\n.. image:: https://github.com/klen/muffin-jinja2/workflows/tests/badge.svg\n    :target: https://github.com/klen/muffin-jinja2/actions\n    :alt: Tests Status\n\n.. image:: https://img.shields.io/pypi/v/muffin-jinja2\n    :target: https://pypi.org/project/muffin-jinja2/\n    :alt: PYPI Version\n\n.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.9\n\n.. _installation:\n\nInstallation\n=============\n\n**Muffin-Jinja2** should be installed using pip: ::\n\n    pip install muffin-jinja2\n\n.. _usage:\n\nUsage\n=====\n\n.. code-block:: python\n\n    import muffin\n    import muffin_jinja2\n\n    # Create Muffin Application\n    app = muffin.Application('example')\n\n    # Initialize the plugin\n    # As alternative: jinja2 = Jinja2(app, **options)\n    jinja2 = muffin_jinja2.Plugin()\n    jinja2.setup(app, template_folders=['src/templates'])\n\n    # Use it inside your handlers\n    @app.route('/')\n    async def index(request):\n        context = {'var': 42}\n        return await jinja2.render('index.html', **context)\n\n\nOptions\n-------\n\n==================== ==================== ====================\nName                 Default value        Description\n-------------------- -------------------- --------------------\n**auto_reload**      ``False``            Auto reload changed templates\n**cache_size**       ``50``               Cache templates\n**extensions**       ``None``             Enable Jinja2 Extensions (``None | list``)\n**loader**           ``FileSystemLoader`` Template loader\n**encoding**         ``utf-8``            Default encoding for file loader\n**template_folders** ``['templates']``    List of template folders\n==================== ==================== ====================\n\n\nYou are able to provide the options when you are initiliazing the plugin:\n\n.. code-block:: python\n\n    jinja2.init(app, template_folders=['src/templates'], auto_reload=True)\n\n\nOr setup it inside ``Muffin.Application`` config using the `jinja2_` prefix for example:\n\n.. code-block:: python\n\n   JINJA2_AUTO_RELOAD = True\n\n   JINJA2_TEMPLATE_FOLDERS = ['tmpls']\n\n``Muffin.Application`` configuration options are case insensitive\n\n\nTunning\n-------\n\n.. code-block:: python\n\n    # Register custom context processor\n    # could be a function/coroutine\n    @jinja2.add_context\n    def custom_context():\n        return { 'VAR': 'VALUE' }\n\n    # Register a function into global context\n    @jinja2.add_global\n    def sum(a, b):\n        return a + b\n\n    # Register a function with a different name\n    @jinja2.add_global('div')\n    def mod(a, b):\n        return a // b\n\n    # Register a filter\n    @jinja2.add_filter\n    def test(value, a, b=None):\n        return a if value else b\n\n    # Register a filter with a different name\n    @jinja2.add_filter('bool')\n    def boolean(value):\n        return bool(value)\n\n    @app.route('/')\n    async def index(request):\n        \"\"\" Check for user is admin. \"\"\"\n        local_context = {'key': 'value'}\n        return await jinja2.render('index.html', **local_context)\n\n\n.. _bugtracker:\n\nBug tracker\n===========\n\nIf you have any suggestions, bug reports or\nannoyances please report them to the issue tracker\nat https://github.com/klen/muffin-jinja2/issues\n\n.. _contributing:\n\nContributing\n============\n\nDevelopment of Muffin-Jinja2 happens at: https://github.com/klen/muffin-jinja2\n\n\nContributors\n=============\n\n* klen_ (Kirill Klenov)\n\n.. _license:\n\nLicense\n========\n\nLicensed under a `MIT license`_.\n\n.. _links:\n\n\n.. _klen: https://github.com/klen\n.. _Muffin: https://github.com/klen/muffin\n\n.. _MIT license: http://opensource.org/licenses/MIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Support Jinja2 templates for Muffin Framework",
    "version": "1.8.1",
    "project_urls": {
        "Homepage": "https://github.com/klen/muffin-jinja2",
        "Repository": "https://github.com/klen/muffin-jinja2"
    },
    "split_keywords": [
        "asyncio",
        " trio",
        " asgi",
        " web",
        " muffin",
        " jinja",
        " jinja2"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "409636ae1f0ad5527f30856a8d177e29116ba1a214330e860b3cfd6c126f59da",
                "md5": "b920da4d8c74b344e034a3d225b2f2db",
                "sha256": "7e2fab285c414c303af18527931f85051e95e6ad91006c1b4bb8a25cfccd5e99"
            },
            "downloads": -1,
            "filename": "muffin_jinja2-1.8.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b920da4d8c74b344e034a3d225b2f2db",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 5289,
            "upload_time": "2024-07-31T17:30:46",
            "upload_time_iso_8601": "2024-07-31T17:30:46.119592Z",
            "url": "https://files.pythonhosted.org/packages/40/96/36ae1f0ad5527f30856a8d177e29116ba1a214330e860b3cfd6c126f59da/muffin_jinja2-1.8.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "500346606703d026578df334106f72ea5cc32f4bc0244bfa150f783f1d9ea1fd",
                "md5": "9271b81ada8eed99a9aae62e32ef7b66",
                "sha256": "20dd5c7842aed4c796f061aacfd826fce0b07598a47e5e9ca1cca6c95d208083"
            },
            "downloads": -1,
            "filename": "muffin_jinja2-1.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9271b81ada8eed99a9aae62e32ef7b66",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 4975,
            "upload_time": "2024-07-31T17:30:47",
            "upload_time_iso_8601": "2024-07-31T17:30:47.826170Z",
            "url": "https://files.pythonhosted.org/packages/50/03/46606703d026578df334106f72ea5cc32f4bc0244bfa150f783f1d9ea1fd/muffin_jinja2-1.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-31 17:30:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "klen",
    "github_project": "muffin-jinja2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "muffin-jinja2"
}
        
Elapsed time: 0.68084s