misuzu/templates/macros.twig
2023-09-08 20:40:48 +00:00

98 lines
4.4 KiB
Twig

{% macro navigation(links, current, top, fmt, align) %}
{% set top = top|default(false) == true %}
{% set align = align|default('centre') %}
{% set current = current|default(null) %}
{% set fmt = fmt|default('%s') %}
<ul class="navigation{% if top %} navigation--top{% endif %}{% if align != 'centre' %} navigation--{{ align }}{% endif %}">
{% for name, url in links %}
<li class="navigation__option{% if url == current or name == current %} navigation__option--selected{% endif %}"><a href="{{ fmt|format(url) }}" class="navigation__link">{{ name }}</a></li>
{% endfor %}
</ul>
{% endmacro %}
{% macro pagination(info, name, params, range) %}
{% if info.page is defined and info.pages > 1 %}
{% set params = params is iterable ? params : {} %}
{% set range = range|default(3) %}
<div class="pagination">
<div class="pagination__section pagination__section--first">
{% if info.page <= 1 %}
<div class="pagination__link pagination__link--first pagination__link--disabled">
<i class="fas fa-angle-double-left"></i>
</div>
<div class="pagination__link pagination__link--prev pagination__link--disabled">
<i class="fas fa-angle-left"></i>
</div>
{% else %}
<a href="{{ url(name, params) }}" class="pagination__link pagination__link--first" rel="first">
<i class="fas fa-angle-double-left"></i>
</a>
<a href="{{ url(name, params|merge({'page': info.page - 1})) }}" class="pagination__link pagination__link--prev" rel="prev">
<i class="fas fa-angle-left"></i>
</a>
{% endif %}
</div>
<div class="pagination__section pagination__section--pages">
{% set p_start = max(info.page - range, 1) %}
{% set p_stop = min(info.page + range, info.pages) %}
{% for i in p_start..p_stop %}
<a href="{{ url(name, params|merge({'page': i})) }}" class="pagination__link{{ info.page == i ? ' pagination__link--current' : '' }}">
{{ i }}
</a>
{% endfor %}
</div>
<div class="pagination__section pagination__section--last">
{% if info.page >= info.pages %}
<div class="pagination__link pagination__link--next pagination__link--disabled">
<i class="fas fa-angle-right"></i>
</div>
<div class="pagination__link pagination__link--last pagination__link--disabled">
<i class="fas fa-angle-double-right"></i>
</div>
{% else %}
<a href="{{ url(name, params|merge({'page': info.page + 1})) }}" class="pagination__link pagination__link--next" rel="next">
<i class="fas fa-angle-right"></i>
</a>
<a href="{{ url(name, params|merge({'page': info.pages})) }}" class="pagination__link pagination__link--last" rel="last">
<i class="fas fa-angle-double-right"></i>
</a>
{% endif %}
</div>
</div>
{% endif %}
{% endmacro %}
{% macro container_title(title, unsafe, url) %}
{% set has_url = url is not null and url|length > 0 %}
<div class="container__title">
<div class="container__title__background"></div>
{% if has_url %}<a href="{{ url }}" class="container__title__link">{% endif %}
<div class="container__title__text">
{% if unsafe %}
{{ title }}
{% else %}
{{ title|raw }}
{% endif %}
</div>
{% if has_url %}</a>{% endif %}
</div>
{% endmacro %}
{% macro avatar(user_id, resolution, alt_text, attrs) %}
{% apply spaceless %}
<img src="{{ url('user-avatar', { 'user': user_id, 'res': resolution * 2 }) }}"
alt="{{ alt_text|default('') }}"
width="{{ attrs.width|default(resolution) }}"
height="{{ attrs.height|default(resolution) }}"
class="avatar{% if attrs.class is defined %} {{ attrs.class }}{% endif %}"
{% if attrs.id is defined %}
id="{{ attrs.id }}"
{% endif %}>
{% endapply %}
{% endmacro %}