Metadata-Version: 2.0
Name: japronto-jinja2
Version: 0.0.1
Summary: jinja2 async template renderer for japronto web server
Home-page: UNKNOWN
Author: Misha Behersky
Author-email: bmwant@gmail.com
License: Apache 2
Platform: UNKNOWN
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Dist: japronto (<0.2,>=0.1.1)
Requires-Dist: jinja2 (>=2.7)
Provides-Extra: dev
Requires-Dist: alabaster (>=0.6.2); extra == 'dev'
Requires-Dist: coverage (==4.3.4); extra == 'dev'
Requires-Dist: flake8 (==3.3.0); extra == 'dev'
Requires-Dist: japronto (<0.2,>=0.1.1); extra == 'dev'
Requires-Dist: jinja2 (>=2.7); extra == 'dev'
Requires-Dist: pytest (>=3.0.7); extra == 'dev'
Requires-Dist: pytest-cov (==2.4.0); extra == 'dev'
Requires-Dist: sphinx (==1.5.5); extra == 'dev'
Requires-Dist: twine (==1.8.1); extra == 'dev'

## japronto_jinja2

[jinja2](http://jinja.pocoo.org) asynchronous template renderer for 
[japronto](https://github.com/squeaky-pl/japronto).

### Installation

Install from PyPI:
```
pip install japronto-jinja2
```

### Developing

Install requirement and launch tests:
```
pip install -e .[dev]
pytest
```

### Usage

Before template rendering you have to setup *jinja2 environment* first::

    import jinja2
    from japronto import Application

    app = Application()
    japronto_jinja2.setup(app, loader=jinja2.FileSystemLoader('/path/to/templates/folder'))


After that you may to use template engine in your *web-handlers*. The
most convenient way is to decorate a *web-handler*.

Using the function based web handlers::

    @ajapronto_jinja2.template('tmpl.jinja2')
    def handler(request):
        return {'action': 'follow', 'person': 'me'}


On handler call the `japronto_jinja2.template` decorator will pass
returned dictionary `{'action': 'follow', 'person': 'me'}` into
template named `tmpl.jinja2` for getting resulting HTML text.

If you need more complex processing (modify response on your own)
you may call `render_template` function.

Using a function based web handler::

    async def handler(request):
        context = {'action': 'unsubscribe', 'from': 'channel'}
        response = aiohttp_jinja2.render_template('tmpl.jinja2',
                                                  request,
                                                  context)
        # do smth with your response
        return response

See [examples](https://github.com/bmwant/japronto-jinja2/tree/master/examples) 
directory for more complete snippets.

### License

`japronto_jinja2` is offered under the Apache 2 license.

CHANGES
=======

0.0.1 (2016-05-10)
------------------

- Initial release

