Skip to content

Commit

Permalink
Merge pull request pallets#103 from njl/fix-issue-93
Browse files Browse the repository at this point in the history
Fix to pallets#93, this time respecting whitespace
  • Loading branch information
rduplain committed Mar 13, 2012
2 parents e5763b3 + 8f0c8ee commit 796ee3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion jinja2/filters.py
Expand Up @@ -176,7 +176,12 @@ def do_title(s):
"""Return a titlecased version of the value. I.e. words will start with
uppercase letters, all remaining characters are lowercase.
"""
return soft_unicode(s).title()
rv = []
for item in re.compile(r'([-\s]+)(?u)').split(s):
if not item:
continue
rv.append(item[0].upper() + item[1:])
return ''.join(rv)


def do_dictsort(value, case_sensitive=False, by='key'):
Expand Down
10 changes: 10 additions & 0 deletions jinja2/testsuite/filters.py
Expand Up @@ -193,6 +193,16 @@ def test_string(self):
def test_title(self):
tmpl = env.from_string('''{{ "foo bar"|title }}''')
assert tmpl.render() == "Foo Bar"
tmpl = env.from_string('''{{ "foo's bar"|title }}''')
assert tmpl.render() == "Foo's Bar"
tmpl = env.from_string('''{{ "foo bar"|title }}''')
assert tmpl.render() == "Foo Bar"
tmpl = env.from_string('''{{ "f bar f"|title }}''')
assert tmpl.render() == "F Bar F"
tmpl = env.from_string('''{{ "foo-bar"|title }}''')
assert tmpl.render() == "Foo-Bar"
tmpl = env.from_string('''{{ "foo\tbar"|title }}''')
assert tmpl.render() == "Foo\tBar"

def test_truncate(self):
tmpl = env.from_string(
Expand Down

0 comments on commit 796ee3f

Please sign in to comment.