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
Provenance
- Commit
5d2733f- Tree
a30bc0e- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
a78d276
5 files changed+37 added−3 removed
modified:docs/extensions.rst+12 added
23 unmodified lines24 25 i18n Extension26 --------------27 28+**Import name:** `jinja2.ext.i18n`29+30 Jinja2 currently comes with one extension, the i18n extension. It can be31 used in combination with `gettext`_ or `babel`_. If the i18n extension is32 enabled Jinja2 provides a `trans` statement that marks the wrapped string as33 translatable and calls `gettext`.57 unmodified lines91 .. _gettext: http://docs.python.org/dev/library/gettext92 .. _Babel: http://babel.edgewall.org/93 94 95+do96+~~97+98+**Import name:** `jinja2.ext.do`99+100+The do aka expression-statement extension adds a simple `do` tag to the101+template engine that works like a variable expression but ignores the102+return value.103+104+105 .. _writing-extensions:106 107 Writing Extensions108 ------------------115 unmodified linesmodified:docs/templates.rst+10 added
1010 unmodified lines1011 {{ _('Hello %s')|format(user.username) }}1012 1013 For multiple placeholders always use keyword arguments to `format` as other1014 languages may not use the words in the same order.1015+1016+1017+do1018+~~1019+1020+If the expression-statement extension is loaded a tag called `do` is available1021+that works exactly like the regular variable expression (``{{ ... }}``) just1022+that it doesn't print anything. This can be used to modify lists:1023+1024+ {% do navigation.append('a string') %}modified:jinja2/defaults.py+1 added-2 removed
23 unmodified lines24 25 DEFAULT_NAMESPACE = {26 'range': xrange,27 'dict': lambda **kw: kw,28- 'lipsum': generate_lorem_ipsum,29- 'void': lambda *a: u''28+ 'lipsum': generate_lorem_ipsum29 }30 31 32 # export all constants1 unmodified linemodified:jinja2/ext.py+13 added
275 unmodified lines276 node = nodes.Mod(node, variables)277 return nodes.Output([node])278 279 280+class 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'])285+286+ def parse(self, parser):287+ node = nodes.ExprStmt(lineno=parser.stream.next().lineno)288+ node.node = parser.parse_tuple()289+ return node290+291+292 def extract_from_ast(node, gettext_functions=GETTEXT_FUNCTIONS):293 """Extract localizable strings from the given template node.294 295 For every string found this function yields a ``(lineno, function,75 unmodified lines371 372 373 #: nicer import names374 i18n = InternationalizationExtension375+do = ExprStmtExtensionmodified:jinja2-debug.py+1 added-1 removed
11 unmodified lines12 import sys13 import jinja214 from werkzeug import script15 16-env = jinja2.Environment(extensions=['jinja2.ext.i18n'])16+env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do'])17 18 def shell_init_func():19 def _compile(x):20 print env.compile(x, raw=True)19 unmodified lines