Skip to content
Myr

[svn] added `xmlattr` filter to jinja

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

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 74cd017 · Browse files · 2 files+38 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+38 added−1 removed

  • other:+38 added−1 removed

2 files+38 added−1 removed

modified:jinja/filters.py+37 added
116 unmodified lines
117 return e(env.to_unicode(s), attribute)118 return wrapped119120121def do_xmlattr():122 """123 Create an SGML/XML attribute string based on the items in a dict.124 All values that are neither `none` nor `undefined` are automatically125 escaped:126127 .. sourcecode:: html128129 <ul{{ {'class': 'my_list', 'missing': None,130 'id': 'list-%d'|format(variable) }}>131 ...132 </ul>133134 Results in something like this:135136 <ul class="my_list" id="list-42">137 ...138 </ul>139140 *New in Jinja 1.1*141 """142 e = escape143 def wrapped(env, context, d):144 if not hasattr(d, 'iteritems'):145 raise TypeError('a dict is required')146 result = []147 for key, value in d.iteritems():148 if value not in (None, Undefined):149 result.append(u'%s="%s"' % (150 e(env.to_unicode(key)),151 e(env.to_unicode(value), True)152 ))153 return u' '.join(result)154 return wrapped155156157def do_capitalize(s):158 """159 Capitalize a value. The first character will be uppercase, all others160 lowercase.
646 unmodified lines
807 'upper': do_upper,808 'lower': do_lower,809 'escape': do_escape,810 'e': do_escape,811 'xmlattr': do_xmlattr,812 'capitalize': do_capitalize,813 'title': do_title,814 'default': do_default,815 'join': do_join,
35 unmodified lines
modified:CHANGES+1 added-1 removed
42 unmodified lines
43- added `batch` and `slice` filters for batching or slicing sequences4445- added `sum`, `abs` and `round` filters. This fixes #2384647- added `striptags` filter.47- added `striptags` and `xmlattr` filters for easier SGML/XML processing484950Version 1.051-----------
3 unmodified lines