- `filesizeformat` filter uses decimal prefixes now per default and can be
set to binary mode with the second parameter.
+- fixed bug in finalizer
+
Version 2.0rc1
--------------
(no codename, released on June 9th 2008)
if self.has_known_extends and frame.toplevel:
return
+ if self.environment.finalize:
+ finalize = lambda x: unicode(self.environment.finalize(x))
+ else:
+ finalize = unicode
+
self.newline(node)
# if we are in the toplevel scope and there was already an extends
const = const.__html__()
else:
const = escape(const)
- const = unicode(const)
+ const = finalize(const)
except:
# if something goes wrong here we evaluate the node
# at runtime for easier debugging
assert tmpl.render(foo={'items': 42}) == "[('items', 42)]"
tmpl = env.from_string('{{ foo["items"] }}')
assert tmpl.render(foo={'items': 42}) == '42'
+
+
+def test_finalizer():
+ from jinja2 import Environment
+ def finalize_none_empty(value):
+ if value is None:
+ value = u''
+ return value
+ env = Environment(finalize=finalize_none_empty)
+ tmpl = env.from_string('{% for item in seq %}|{{ item }}{% endfor %}')
+ assert tmpl.render(seq=(None, 1, "foo")) == '||1|foo'
+ tmpl = env.from_string('<{{ none }}>')
+ assert tmpl.render() == '<>'