Skip to content
Myr

Merge pull request #439 from jgmize/title-filter-capitalize-inside-parens

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

Make title filter capitalize words inside parens and other brackets

authored by Jeff Widman · committed by Jeff Widman · parents 4de1487, 62e7e70 · 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
153 unmodified lines
183def do_title(s):184 """Return a titlecased version of the value. I.e. words will start with185 uppercase letters, all remaining characters are lowercase.186 """186 rv = []187 for item in re.compile(r'([-\s]+)(?u)').split(soft_unicode(s)):188 if not item:189 continue190 rv.append(item[0].upper() + item[1:].lower())191 return ''.join(rv)187 return ''.join(188 [item[0].upper() + item[1:].lower()189 for item in _word_beginning_split_re.split(soft_unicode(s))190 if item])191192193def do_dictsort(value, case_sensitive=False, by='key'):194 """Sort a dict and yield (key, value) pairs. Because python dicts are
796 unmodified lines
modified:tests/test_filters.py+8 added
211 unmodified lines
212 tmpl = env.from_string('''{{ "foo\tbar"|title }}''')213 assert tmpl.render() == "Foo\tBar"214 tmpl = env.from_string('''{{ "FOO\tBAR"|title }}''')215 assert tmpl.render() == "Foo\tBar"216 tmpl = env.from_string('''{{ "foo (bar)"|title }}''')217 assert tmpl.render() == "Foo (Bar)"218 tmpl = env.from_string('''{{ "foo {bar}"|title }}''')219 assert tmpl.render() == "Foo {Bar}"220 tmpl = env.from_string('''{{ "foo [bar]"|title }}''')221 assert tmpl.render() == "Foo [Bar]"222 tmpl = env.from_string('''{{ "foo <bar>"|title }}''')223 assert tmpl.render() == "Foo <Bar>"224225 class Foo:226 def __str__(self):227 return 'foo-bar'
344 unmodified lines