From: Armin Ronacher Date: Mon, 5 Mar 2007 17:03:32 +0000 (+0100) Subject: [svn] reversed -> reverse X-Git-Tag: 2.0rc1~465 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=dbc945d6965ccc4a86fe83fbdc43888eff677ac9;p=jinja2.git [svn] reversed -> reverse --HG-- branch : trunk --- diff --git a/jinja/filters.py b/jinja/filters.py index d548d5a..6a0bf33 100644 --- a/jinja/filters.py +++ b/jinja/filters.py @@ -190,14 +190,14 @@ def do_count(): return wrapped -def do_reversed(): +def do_reverse(): """ Return a reversed list of the sequence filtered. You can use this for example for reverse iteration: .. sourcecode:: jinja - {% for item in seq|reversed %} + {% for item in seq|reverse %} {{ item|e }} {% endfor %} """ @@ -307,7 +307,7 @@ FILTERS = { 'default': do_default, 'join': do_join, 'count': do_count, - 'reversed': do_reversed, + 'reverse': do_reverse, 'center': do_center, 'title': do_title, 'capitalize': do_capitalize, diff --git a/jinja/parser.py b/jinja/parser.py index a95dda8..1bcd0b2 100644 --- a/jinja/parser.py +++ b/jinja/parser.py @@ -342,9 +342,7 @@ class Parser(object): break # normal data else: - if replacements: - data = data.replace('%', '%%') - buf.append(data) + buf.append(data.replace('%', '%%')) except StopIteration: raise TemplateSyntaxError('unexpected end of translation section', diff --git a/jinja/utils.py b/jinja/utils.py index 44b8dc9..7cbf77e 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -9,6 +9,7 @@ :license: BSD, see LICENSE for more details. """ import re +from jinja.nodes import Trans from jinja.datastructure import safe_types, Markup @@ -24,6 +25,7 @@ _escape_res = ( re.compile('(&|<|>)') ) + def escape(x, attribute=False): """ Escape an object x which is converted to unicode first. @@ -32,3 +34,18 @@ def escape(x, attribute=False): return x return Markup(_escape_res[not attribute].sub(lambda m: _escape_pairs[m.group()], unicode(x))) + + + +def find_translations(environment, source): + """ + Find all translatable strings in a template and yield + them as (lineno, singular, plural) tuples. If a plural + section does not exist it will be None. + """ + queue = [environment.parse(source)] + while queue: + node = queue.pop() + if node.__class__ is Trans: + yield node.lineno, node.singular, node.plural + queue.extend(node.getChildNodes())