Skip to content
Myr

void -> do

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent a78d276 · Browse files · 5 files+37 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+37 added−3 removed

  • other:+37 added−3 removed

5 files+37 added−3 removed

modified:docs/extensions.rst+12 added
23 unmodified lines
2425i18n Extension26--------------2728**Import name:** `jinja2.ext.i18n`2930Jinja2 currently comes with one extension, the i18n extension. It can be31used in combination with `gettext`_ or `babel`_. If the i18n extension is32enabled Jinja2 provides a `trans` statement that marks the wrapped string as33translatable and calls `gettext`.
57 unmodified lines
91.. _gettext: http://docs.python.org/dev/library/gettext92.. _Babel: http://babel.edgewall.org/939495do96~~9798**Import name:** `jinja2.ext.do`99100The do aka expression-statement extension adds a simple `do` tag to the101template engine that works like a variable expression but ignores the102return value.103104105.. _writing-extensions:106107Writing Extensions108------------------
115 unmodified lines
modified:docs/templates.rst+10 added
1010 unmodified lines
1011 {{ _('Hello %s')|format(user.username) }}10121013For multiple placeholders always use keyword arguments to `format` as other1014languages may not use the words in the same order.101510161017do1018~~10191020If the expression-statement extension is loaded a tag called `do` is available1021that works exactly like the regular variable expression (``{{ ... }}``) just1022that it doesn't print anything. This can be used to modify lists:10231024 {% do navigation.append('a string') %}
modified:jinja2/defaults.py+1 added-2 removed
23 unmodified lines
2425DEFAULT_NAMESPACE = {26 'range': xrange,27 'dict': lambda **kw: kw,28 'lipsum': generate_lorem_ipsum,29 'void': lambda *a: u''28 'lipsum': generate_lorem_ipsum29}303132# export all constants
1 unmodified line
modified:jinja2/ext.py+13 added
275 unmodified lines
276 node = nodes.Mod(node, variables)277 return nodes.Output([node])278279280class ExprStmtExtension(Extension):281 """Adds a `do` tag to Jinja2 that works like the print statement just282 that it doesn't print the return value.283 """284 tags = set(['do'])285286 def parse(self, parser):287 node = nodes.ExprStmt(lineno=parser.stream.next().lineno)288 node.node = parser.parse_tuple()289 return node290291292def extract_from_ast(node, gettext_functions=GETTEXT_FUNCTIONS):293 """Extract localizable strings from the given template node.294295 For every string found this function yields a ``(lineno, function,
75 unmodified lines
371372373#: nicer import names374i18n = InternationalizationExtension375do = ExprStmtExtension
modified:jinja2-debug.py+1 added-1 removed
11 unmodified lines
12import sys13import jinja214from werkzeug import script1516env = jinja2.Environment(extensions=['jinja2.ext.i18n'])16env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do'])1718def shell_init_func():19 def _compile(x):20 print env.compile(x, raw=True)
19 unmodified lines