Add non-decorator template filter methods.

Suggested by @Poincare on GitHub, on @Reisen's pull request:
https://github.com/mitsuhiko/flask/pull/272
This commit is contained in:
Ron DuPlain 2012-01-16 20:16:48 -05:00
parent 2a4d3ef116
commit ce4d589d5b
2 changed files with 30 additions and 7 deletions

View file

@ -1018,10 +1018,20 @@ class Flask(_PackageBoundObject):
function name will be used.
"""
def decorator(f):
self.jinja_env.filters[name or f.__name__] = f
self.add_template_filter(f, name=name)
return f
return decorator
@setupmethod
def add_template_filter(self, f, name=None):
"""Register a custom template filter. Works exactly like the
:meth:`template_filter` decorator.
:param name: the optional name of the filter, otherwise the
function name will be used.
"""
self.jinja_env.filters[name or f.__name__] = f
@setupmethod
def before_request(self, f):
"""Registers a function to run before each request."""