- added `groupby` filter.
+- added `sameas` test function.
+
Version 1.1
-----------
As you can see the item we're grouping by is stored in the `grouper`
attribute and the `list` contains all the objects that have this grouper
in common.
+
+ *New in Jinja 1.2*
"""
def wrapped(env, context, value):
expr = lambda x: env.get_attribute(x, attribute)
return wrapped
+def test_sameas(other):
+ """
+ Check if an object points to the same memory address than another
+ object:
+
+ .. sourcecode:: jinja
+
+ {% if foo.attribute is sameas(false) %}
+ the foo attribute really is the `False` singleton
+ {% endif %}
+
+ *New in Jinja 1.2*
+ """
+ return lambda e, c, v: v is other
+
+
TESTS = {
'odd': test_odd,
'even': test_even,
'upper': test_upper,
'numeric': test_numeric,
'sequence': test_sequence,
- 'matching': test_matching
+ 'matching': test_matching,
+ 'sameas': test_sameas
}
{{ "foo" is sequence }}|\
{{ 42 is sequence }}'''
UPPER = '''{{ "FOO" is upper }}|{{ "foo" is upper }}'''
+SAMEAS = '''{{ foo is sameas(false) }}|{{ 0 is sameas(false) }}'''
def test_defined(env):
def test_upper(env):
tmpl = env.from_string(UPPER)
assert tmpl.render() == 'True|False'
+
+
+def test_sameas(env):
+ tmpl = env.from_string(SAMEAS)
+ assert tmpl.render(foo=False) == 'True|False'