Skip to content

Commit

Permalink
Fix to #93, this time respecting whitespace
Browse files Browse the repository at this point in the history
Rejigger of title split to respect whitespace, also capitalize follow-on
hyphenated words.
  • Loading branch information
njl committed Mar 12, 2012
1 parent 37bcc69 commit c4b6fd3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions jinja2/filters.py
Expand Up @@ -177,12 +177,12 @@ def do_title(s):
uppercase letters, all remaining characters are lowercase.
"""
rv = []
for word in soft_unicode(s).split(' '):
if not word:
rv.append(word)
for item in re.compile(r'([-\s]+)(?u)').split(s):
if not item:
rv.append(item)
continue
rv.append(word[0].upper() + word[1:])
return ' '.join(rv)
rv.append(item[0].upper() + item[1:])
return ''.join(rv)


def do_dictsort(value, case_sensitive=False, by='key'):
Expand Down
4 changes: 4 additions & 0 deletions jinja2/testsuite/filters.py
Expand Up @@ -199,6 +199,10 @@ def test_title(self):
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 c4b6fd3

Please sign in to comment.