Add and refine template tags for working with image srcsets.
Review Request #9440 — Created Dec. 14, 2017 and submitted — Latest diff uploaded
The existing
{% srcset %}
template tag has been made more robust,
sanity-checking the sources passed in and sorting the resulting list, in
order to guarantee that the data being passed into the template is
valid. It also no longer trusts that the values provided are HTML-safe,
instead usingformat_html_join
to more intelligently handle safe vs.
non-safe values.A new template tag was also added,
{% image_source_attrs %}
, which
takes a multi-line source definition list with items in the form of
<descriptor> <URL>
and builds asrc="..." srcset="..."
string for
adding to an<img>
tag. This is a convenient way of building these
values in HTML templates without worrying about long lines, duplicate
information, and redundant calls to{% static %}
.Unit tests were added for both functions.
Unit tests pass.
Made use of this in some upcoming work in RBCommons.