mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Make components for nicely formatted lists
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.
This commit is contained in:
37
app/templates/components/list.html
Normal file
37
app/templates/components/list.html
Normal file
@@ -0,0 +1,37 @@
|
||||
{% 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 %}
|
||||
Reference in New Issue
Block a user