li7y/templates/macros.html
Simon Bruder c4a73204aa
Make item name optional
This vastly changes how item names are displayed. To make this more
ergonomic, it adds some helper macros. This also aids in adhering to
DRY.
2024-07-11 01:16:45 +02:00

37 lines
1.3 KiB
HTML

{#
SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
SPDX-License-Identifier: AGPL-3.0-or-later
#}
{% macro emphasize(text, html) %}
{%- if html %}<em>{{ text }}</em>{% else %}*{{ text }}*{% endif %}
{%- endmacro %}
{% macro item_name_generic(name, fallback, html) %}
{%- if let Some(name) = name %}{{ name }}{% else %}{% call emphasize(fallback, html) %}{% endif %}
{%- endmacro %}
{% macro item_name(item, item_class, html) %}
{%- call item_name_generic(item.name, item_class.name, html) %}
{%- endmacro %}
{% macro item_name_terse(item, html) %}
{%- call item_name_generic(item.name, "[no name]", html) %}
{%- endmacro %}
{% macro parents_breadcrumb(item, parents, parents_item_classes, full) %}
{%- let limit = 3 %}
{%- let limited = parents.len() > limit && !full %}
{%- let parents = parents.iter().rev().take(limit.into()).rev() %}
<ol class="breadcrumb mb-0">
{%- if limited %}
<li class="breadcrumb-item"></li>
{%- endif %}
{%- for parent in parents %}
<li class="breadcrumb-item"><a href="/item/{{ parent.id }}">{% call item_name(parent, parents_item_classes.get(parent.class).unwrap(), true) %}</a></li>
{%- endfor %}
<li class="breadcrumb-item active">{% call item_name(item, item_classes.get(item.class).unwrap(), true) %}</li>
</ol>
{%- endmacro %}