cyberstorm/book/macros.tera

75 lines
2.5 KiB
Plaintext

{% macro content(content) %}
{%- set trimmed = content | trim -%}
{%- if trimmed | length == 0 %}No description{% else %}{{ trimmed }}{% endif -%}
{% endmacro content %}
{% macro references(refs) %}
{%- if refs | length == 0 %}No references{% endif -%}
{%- for ref in refs -%}
{%- if ref is url -%}
- <{{ ref }}>
{%- else -%}
- {{ ref }}
{%- endif -%}
{% endfor -%}
{% endmacro references %}
{% macro doc_title(doc) -%}
{{ document.name }} <small>([edit]({{ link_for(for="document", id=document.id, edit=true) }}))</small>
{%- endmacro doc_title %}
{% macro model_title(domain, model) -%}
{{ model | capitalize }}
{%- endmacro model_title %}
{% macro doc_details(doc) -%}
| Title | {{ document.name }} |
|:---------------------------:|:------------------------|
{{ self::doc_details_next(title="ID", value=document.id) }}
{%- endmacro doc_details %}
{% macro doc_details_next(title, value) -%}
| **{{ title }}** | {{ value }} |
{%- endmacro doc_details_next %}
{% macro doc_details_authors(authors) -%}
{{ self::doc_details_next(title="Authors", value=authors | join )}}
{%- endmacro doc_details_authors %}
{% macro doc_details_tags(tags) -%}
{% if tags | length == 0 -%}
{{ self::doc_details_next(title="Tags", value="No tags") }}
{%- else -%}
{{ self::doc_details_next(title="Tags", value=tags | join) }}
{%- endif %}
{%- endmacro doc_details_tags %}
{% macro doc_rich_link(doc) -%}
{{ document.name }} ([{{ document.id }}]({{ link_for(for="document", id=document.id) }}))
{%- endmacro doc_rich_link %}
{% macro summary_table(items) -%}
| ID | Name |
|:---------------------------:|:------------------------|
{% for item in items -%}
| [{{ item.id }}]({{ link_for(for="document", id=item.id) }}) | {{ item.name }} |
{% endfor %}
{%- endmacro summary_table %}
{% macro summary_list(items) %}
{%- set last_domain = "" -%}
{%- set last_model = "" -%}
{%- for item in items -%}
{%- set id_parts = item.id | domain_id -%}
{%- if last_domain != id_parts.domain -%}
{%- set_global last_domain = id_parts.domain %}
# {{ id_parts.domain | capitalize }}
{%- endif -%}
{%- if last_model != id_parts.model -%}
{%- set_global last_model = id_parts.model %}
- [{{ id_parts.model | capitalize }}]({{ id_parts.domain ~ "/" ~ id_parts.model ~ ".md" }})
{%- endif %}
- [{{ item.name }}]({{ id_parts.domain ~ "/" ~ id_parts.model ~ "/" ~id_parts.instance ~ ".md" }})
{%- endfor -%}
{% endmacro summary_list %}