Skip to content
Myr

Make title filter capitalize words in (),{},[],<>

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

authored by Josh Mize · committed by Josh Mize · parent bd93bf3 · Browse files · 2 files+13 added−6 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+13 added−6 removed

  • tests:+8 added−0 removed
  • other:+5 added−6 removed

2 files+13 added−6 removed

modified:jinja2/filters.py+5 added-6 removed
20 unmodified lines
21from jinja2._compat import imap, string_types, text_type, iteritems222324_word_re = re.compile(r'\w+(?u)')25_word_beginning_split_re = re.compile(r'([-\s\(\{\[\<]+)(?u)')262728def contextfilter(f):29 """Decorator for marking context dependent filters. The current
152 unmodified lines
182def do_title(s):183 """Return a titlecased version of the value. I.e. words will start with184 uppercase letters, all remaining characters are lowercase.185 """185 rv = []186 for item in re.compile(r'([-\s]+)(?u)').split(soft_unicode(s)):187 if not item:188 continue189 rv.append(item[0].upper() + item[1:].lower())190 return ''.join(rv)186 return ''.join(187 [item[0].upper() + item[1:].lower()188 for item in _word_beginning_split_re.split(soft_unicode(s))189 if item])190191192def do_dictsort(value, case_sensitive=False, by='key'):193 """Sort a dict and yield (key, value) pairs. Because python dicts are
800 unmodified lines
modified:tests/test_filters.py+8 added
205 unmodified lines
206 tmpl = env.from_string('''{{ "foo\tbar"|title }}''')207 assert tmpl.render() == "Foo\tBar"208 tmpl = env.from_string('''{{ "FOO\tBAR"|title }}''')209 assert tmpl.render() == "Foo\tBar"210 tmpl = env.from_string('''{{ "foo (bar)"|title }}''')211 assert tmpl.render() == "Foo (Bar)"212 tmpl = env.from_string('''{{ "foo {bar}"|title }}''')213 assert tmpl.render() == "Foo {Bar}"214 tmpl = env.from_string('''{{ "foo [bar]"|title }}''')215 assert tmpl.render() == "Foo [Bar]"216 tmpl = env.from_string('''{{ "foo <bar>"|title }}''')217 assert tmpl.render() == "Foo <Bar>"218219 class Foo:220 def __str__(self):221 return 'foo-bar'
344 unmodified lines