Skip to content
Myr

the template_filter now expects the parentheses

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastien Estienne · committed by Armin Ronacher · parent a9bb965 · Browse files · 2 files+4 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+4 added−17 removed

  • tests:+1 added−10 removed
  • other:+3 added−7 removed

2 files+4 added−17 removed

modified:tests/flask_tests.py+1 added-10 removed
309 unmodified lines
310 with app.test_request_context():311 macro = flask.get_template_attribute('_macro.html', 'hello')312 assert macro('World') == 'Hello World!'313314 def test_template_filter_not_called(self):314 def test_template_filter(self):315 app = flask.Flask(__name__)316 @app.template_filter317 def my_reverse(s):318 return s[::-1]319 assert 'my_reverse' in app.jinja_env.filters.keys()320 assert app.jinja_env.filters['my_reverse'] == my_reverse321 assert app.jinja_env.filters['my_reverse']('abcd') == 'dcba'322323 def test_template_filter_called(self):324 app = flask.Flask(__name__)316 @app.template_filter()317 def my_reverse(s):318 return s[::-1]319 assert 'my_reverse' in app.jinja_env.filters.keys()
28 unmodified lines
modified:flask.py+3 added-7 removed
638 unmodified lines
639 self.error_handlers[code] = f640 return f641 return decorator642643 def template_filter(self, arg=None):643 def template_filter(self, name=None):644 """A decorator that is used to register custom template filter.645 You can specify a name for the filter, otherwise the function646 name will be used. Example::647648 @app.template_filter648 @app.template_filter()649 def reverse(s):650 return s[::-1]651652 :param name: the optional name of the filter, otherwise the653 function name will be used.654 """655 if type(arg) is types.FunctionType:656 self.jinja_env.filters[arg.__name__] = arg657 return arg658655 def decorator(f):660 self.jinja_env.filters[arg or f.__name__] = f656 self.jinja_env.filters[name or f.__name__] = f657 return f658 return decorator659660 def before_request(self, f):
164 unmodified lines