mirror of
https://gitee.com/openharmony/third_party_jinja2
synced 2024-11-27 09:20:49 +00:00
Priority of not
raised. It's now possible to write not foo in bar
as an alias to `foo not in bar` like in python. Previously the grammar required parentheses (`not (foo in bar)`) which was odd. --HG-- branch : trunk
This commit is contained in:
parent
8de6f18b9d
commit
d89f0f3def
3
CHANGES
3
CHANGES
@ -7,6 +7,9 @@ Version 2.2
|
||||
|
||||
- Include statements can now be marked with ``ignore missing`` to skip
|
||||
non existing templates.
|
||||
- Priority of `not` raised. It's now possible to write `not foo in bar`
|
||||
as an alias to `foo not in bar` like in python. Previously the grammar
|
||||
required parentheses (`not (foo in bar)`) which was odd.
|
||||
|
||||
Version 2.1.1
|
||||
-------------
|
||||
|
1
docs/_static/style.css
vendored
1
docs/_static/style.css
vendored
@ -253,6 +253,7 @@ h3:hover > a.headerlink,
|
||||
h4:hover > a.headerlink,
|
||||
h5:hover > a.headerlink,
|
||||
h6:hover > a.headerlink,
|
||||
dt:hover > a.headerlink,
|
||||
dt:hover > a.headerlink {
|
||||
visibility: visible;
|
||||
}
|
||||
|
@ -51,6 +51,6 @@ class FragmentCacheExtension(Extension):
|
||||
rv = self.environment.fragment_cache.get(key)
|
||||
if rv is None:
|
||||
return rv
|
||||
rv = caller()
|
||||
self.environment.fragment_cache.add(key, rv, timeout)
|
||||
rv = caller()
|
||||
self.environment.fragment_cache.add(key, rv, timeout)
|
||||
return rv
|
||||
|
@ -333,13 +333,19 @@ class Parser(object):
|
||||
|
||||
def parse_and(self):
|
||||
lineno = self.stream.current.lineno
|
||||
left = self.parse_compare()
|
||||
left = self.parse_not()
|
||||
while self.stream.skip_if('name:and'):
|
||||
right = self.parse_compare()
|
||||
right = self.parse_not()
|
||||
left = nodes.And(left, right, lineno=lineno)
|
||||
lineno = self.stream.current.lineno
|
||||
return left
|
||||
|
||||
def parse_not(self):
|
||||
if self.stream.current.test('name:not'):
|
||||
lineno = self.stream.next().lineno
|
||||
return nodes.Not(self.parse_not(), lineno=lineno)
|
||||
return self.parse_compare()
|
||||
|
||||
def parse_compare(self):
|
||||
lineno = self.stream.current.lineno
|
||||
expr = self.parse_add()
|
||||
@ -445,10 +451,6 @@ class Parser(object):
|
||||
def parse_unary(self):
|
||||
token_type = self.stream.current.type
|
||||
lineno = self.stream.current.lineno
|
||||
if token_type == 'name' and self.stream.current.value == 'not':
|
||||
self.stream.next()
|
||||
node = self.parse_unary()
|
||||
return nodes.Not(node, lineno=lineno)
|
||||
if token_type == 'sub':
|
||||
self.stream.next()
|
||||
node = self.parse_unary()
|
||||
|
@ -189,3 +189,9 @@ def test_test_chaining(env):
|
||||
def test_string_concatenation(env):
|
||||
tmpl = env.from_string('{{ "foo" "bar" "baz" }}')
|
||||
assert tmpl.render() == 'foobarbaz'
|
||||
|
||||
|
||||
def test_notin(env):
|
||||
bar = xrange(100)
|
||||
tmpl = env.from_string('''{{ not 42 in bar }}''')
|
||||
assert tmpl.render(bar=bar) == unicode(not 42 in bar)
|
||||
|
Loading…
Reference in New Issue
Block a user