Permalink
Browse files

Merge pull request #236 from johnboxall/title-filter-with-objects

`title` filter should accept objects.
  • Loading branch information...
2 parents 073fdc0 + 2fff653 commit 147472a27016bfc4e4fdc6985c8f4411a8966e28 @mitsuhiko mitsuhiko committed May 29, 2013
Showing with 9 additions and 1 deletion.
  1. +1 −1 jinja2/filters.py
  2. +8 −0 jinja2/testsuite/filters.py
View
@@ -183,7 +183,7 @@ def do_title(s):
uppercase letters, all remaining characters are lowercase.
"""
rv = []
- for item in re.compile(r'([-\s]+)(?u)').split(s):
+ for item in re.compile(r'([-\s]+)(?u)').split(soft_unicode(s)):
if not item:
continue
rv.append(item[0].upper() + item[1:])
@@ -205,6 +205,14 @@ def test_title(self):
tmpl = env.from_string('''{{ "foo\tbar"|title }}''')
assert tmpl.render() == "Foo\tBar"
+ class Foo:
+ def __str__(self):
+ return 'foo-bar'
+
+ tmpl = env.from_string('''{{ data|title }}''')
+ out = tmpl.render(data=Foo())
+ assert out == 'Foo-Bar'
+
def test_truncate(self):
tmpl = env.from_string(
'{{ data|truncate(15, true, ">>>") }}|'

0 comments on commit 147472a

Please sign in to comment.