Skip to content
Myr

Merge pull request #236 from johnboxall/title-filter-with-objects

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

`title` filter should accept objects.

authored by Armin Ronacher · committed by Armin Ronacher · parents 073fdc0, 2fff653 · Browse files · 2 files+9 added−1 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+9 added−1 removed

  • other:+9 added−1 removed

2 files+9 added−1 removed

modified:jinja2/testsuite/filters.py+8 added
203 unmodified lines
204 assert tmpl.render() == "Foo-Bar"205 tmpl = env.from_string('''{{ "foo\tbar"|title }}''')206 assert tmpl.render() == "Foo\tBar"207208 class Foo:209 def __str__(self):210 return 'foo-bar'211212 tmpl = env.from_string('''{{ data|title }}''')213 out = tmpl.render(data=Foo())214 assert out == 'Foo-Bar'215216 def test_truncate(self):217 tmpl = env.from_string(218 '{{ data|truncate(15, true, ">>>") }}|'219 '{{ data|truncate(15, false, ">>>") }}|'
298 unmodified lines
modified:jinja2/filters.py+1 added-1 removed
181 unmodified lines
182 """Return a titlecased version of the value. I.e. words will start with183 uppercase letters, all remaining characters are lowercase.184 """185 rv = []186 for item in re.compile(r'([-\s]+)(?u)').split(s):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:])190 return ''.join(rv)
797 unmodified lines