integration.rst
This file
Path
docs/integration.rst
88 lines · 2.9 KiB
Last changed by
some small documentation fixesArmin Ronacherbefore adoption2b22874
History of this fileTake it
some documentation updatesArmin Ronacherbefore adoptioned98cac
lines 1–23why, one step back1Integration2===========34Jinja2 provides some code for integration into other tools such as frameworks,5the `Babel`_ library or your favourite editor for fancy code highlighting.6This is a brief description of whats included.78.. _babel-integration:910Babel Integration11-----------------1213Jinja provides support for extracting gettext messages from templates via a14`Babel`_ extractor entry point called `jinja2.ext.babel_extract`. The Babel15support is implemented as part of the :ref:`i18n-extension` extension.1617Gettext messages extracted from both `trans` tags and code expressions.1819To extract gettext messages from templates, the project needs a Jinja2 section20in its Babel extraction method `mapping file`_:2122.. sourcecode:: ini23some small documentation fixesArmin Ronacherbefore adoption2b22874
line 24why, one step back24 [jinja2: **/templates/**.html]some documentation updatesArmin Ronacherbefore adoptioned98cac
lines 25–32why, one step back25 encoding = utf-82627The syntax related options of the :class:`Environment` are also available as28configuration values in the mapping file. For example to tell the extraction29that templates use ``%`` as `line_statement_prefix` you can use this code:3031.. sourcecode:: ini32some small documentation fixesArmin Ronacherbefore adoption2b22874
line 33why, one step back33 [jinja2: **/templates/**.html]some documentation updatesArmin Ronacherbefore adoptioned98cac
lines 34–42why, one step back34 encoding = utf-835 line_statement_prefix = %3637:ref:`jinja-extensions` may also be defined by passing a comma separated list38of import paths as `extensions` value. The i18n extension is added39automatically.4041.. _mapping file: http://babel.edgewall.org/wiki/Documentation/messages.html#extraction-method-mapping-and-configuration42removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826
line 43why, one step back43Pylonssome documentation updatesArmin Ronacherbefore adoptioned98cac
lines 44–45why, one step back44------45removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826
lines 46–47why, one step back46With `Pylons`_ 0.9.7 onwards it's incredible easy to integrate Jinja into a47Pylons powered application.some documentation updatesArmin Ronacherbefore adoptioned98cac
line 48why, one step back48removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826
lines 49–50why, one step back49The template engine is configured in `config/environment.py`. The configuration50for Jinja2 looks something like that::some documentation updatesArmin Ronacherbefore adoptioned98cac
line 51why, one step back51removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826
lines 52–55why, one step back52 from jinja2 import Environment, PackageLoader53 config['pylons.app_globals'].jinja_env = Environment(54 loader=PackageLoader('yourapplication', 'templates')55 )some documentation updatesArmin Ronacherbefore adoptioned98cac
line 56why, one step back56removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826
lines 57–58why, one step back57After that you can render Jinja templates by using the `render_jinja` function58from the `pylons.templating` module.some documentation updatesArmin Ronacherbefore adoptioned98cac
line 59why, one step back59removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826
lines 60–67why, one step back60Additionally it's a good idea to set the Pylons' `c` object into strict mode.61Per default any attribute to not existing attributes on the `c` object return62an empty string and not an undefined object. To change this just use this63snippet and add it into your `config/environment.py`::6465 config['pylons.strict_c'] = True6667.. _Pylons: http://www.pylonshq.com/some documentation updatesArmin Ronacherbefore adoptioned98cac
lines 68–71why, one step back6869TextMate70--------71added TextMate bundle and vim syntax filesArmin Ronacherbefore adoptiondecf7e3
lines 72–74why, one step back72Inside the `ext` folder of Jinja2 there is a bundle for TextMate that supports73syntax highlighting for Jinja1 and Jinja2 for text based templates as well as74HTML. It also contains a few often used snippets.some documentation updatesArmin Ronacherbefore adoptioned98cac
lines 75–78why, one step back7576Vim77---78added TextMate bundle and vim syntax filesArmin Ronacherbefore adoptiondecf7e3
lines 79–83why, one step back79A syntax plugin for `Vim`_ exists in the Vim-scripts directory as well as the80ext folder of Jinja2. `The script <http://www.vim.org/scripts/script.php?script_id=1856>`_81supports Jinja1 and Jinja2. Once installed two file types are available `jinja`82and `htmljinja`. The first one for text based templates, the latter for HTML83templates.some documentation updatesArmin Ronacherbefore adoptioned98cac
line 84why, one step back84added TextMate bundle and vim syntax filesArmin Ronacherbefore adoptiondecf7e3
lines 85–86why, one step back85Copy the files into your `syntax` folder.86some documentation updatesArmin Ronacherbefore adoptioned98cac
line 87why, one step back87.. _Babel: http://babel.edgewall.org/added TextMate bundle and vim syntax filesArmin Ronacherbefore adoptiondecf7e3
line 88why, one step back88.. _Vim: http://www.vim.org/