Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes Issue #93 by implementing a title algorithm

The stdlib title function provides a fundamentally correct and
completely useless version of the title function, that defines
words as things seperated by not letters. This changes the semantics to
make words things that are seperated by spaces.
  • Loading branch information...
commit 7fe70fd7af092fb350f823fab703a270d5c0eaec 1 parent 1305cfd
@njl njl authored
Showing with 13 additions and 1 deletion.
  1. +7 −1 jinja2/filters.py
  2. +6 −0 jinja2/testsuite/filters.py
View
8 jinja2/filters.py
@@ -176,7 +176,13 @@ 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 word in soft_unicode(s).split(' '):
+ if not word:
+ rv.append(word)
+ continue
+ rv.append(word[0].upper() + word[1:])
+ return ' '.join(rv)
def do_dictsort(value, case_sensitive=False, by='key'):
View
6 jinja2/testsuite/filters.py
@@ -193,6 +193,12 @@ 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"
def test_truncate(self):
tmpl = env.from_string(

0 comments on commit 7fe70fd

Please sign in to comment.
Something went wrong with that request. Please try again.