mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-10 05:14:05 -05:00
We have a couple of places now where we want nice lists made from `list`s, eg - ‘name’, ‘date’ and ‘phone number’ - ((firstname)) ((lastname)) or ((date)) This commit adds a more generic component for doing this, which can handle: - 1, 2, and n items - comma (or other character) separated lists - a conjunction between the last and one-before-last item - characters to be inserted before and after each item, eg an opening and closing HTML tag It also pulls the `list_of_placeholders` component from the breaking change page, and makes it use the `formatted_list` component under the hood.
38 lines
855 B
HTML
38 lines
855 B
HTML
{% macro formatted_list(
|
||
items,
|
||
conjunction='and',
|
||
before_each='‘',
|
||
after_each='’',
|
||
separator=', ',
|
||
prefix='',
|
||
prefix_plural=''
|
||
) %}
|
||
{% if items|length == 1 %}
|
||
{{ prefix }} {{ before_each|safe }}{{ (items|list)[0] }}{{ after_each|safe }}
|
||
{% elif items %}
|
||
{{ prefix_plural }}
|
||
{% for item in (items|list)[0:-1] -%}
|
||
{{ before_each|safe -}}
|
||
{{ item -}}
|
||
{{ after_each|safe -}}
|
||
{% if not loop.last -%}
|
||
{{ separator -}}
|
||
{% endif -%}
|
||
{% endfor %}
|
||
{{ conjunction }}
|
||
{{ before_each|safe -}}
|
||
{{ (items|list)[-1] -}}
|
||
{{ after_each|safe }}
|
||
{%- endif %}
|
||
{%- endmacro %}
|
||
|
||
|
||
{% macro list_of_placeholders(placeholders) %}
|
||
{{ formatted_list(
|
||
placeholders,
|
||
before_each="<span class='placeholder'>((",
|
||
after_each='))</span>',
|
||
separator=' '
|
||
) }}
|
||
{%- endmacro %}
|