Skip to content
Myr

[svn] added filters "capture" and "format"

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 c1e3040 · Browse files · 1 file+34 added−1 removed
This commit

State

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

Diff stats

1 file+34 added−1 removed

  • other:+34 added−1 removed

1 file+34 added−1 removed

modified:jinja/filters.py+34 added-1 removed
546 unmodified lines
547 """548 return lambda e, c, v: e.to_unicode(v)549550551def do_format(*args):552 """553 Apply python string formatting on an object:554555 .. sourcecode:: jinja556557 {{ "%s - %s"|format("Hello?", "Foo!") }}558 -> Hello? - Foo!559560 Note that you cannot use the mapping syntax (``%(name)s``)561 like in python.562 """563 def wrapped(env, context, value):564 return env.to_unicode(value) % args565 return wrapped566567568def do_capture(name='captured'):569 """570 Store the value in a variable called ``captured`` or a variable571 with the name provided. Useful for filter blocks:572573 .. sourcecode:: jinja574575 {% filter capture('foo') %}576 ....577 {% endfilter %}578 {{ foo }}579 """580581582FILTERS = {583 'replace': do_replace,584 'upper': do_upper,585 'lower': do_lower,
26 unmodified lines
612 'rst': do_rst,613 'int': do_int,614 'float': do_float,615 'string': do_string,585 'urlize': do_urlize616 'urlize': do_urlize,617 'format': do_format,618 'capture': do_capture619}