{# Page header (top bar): ⌂ plugins (📅 calendar, ☀ weather, stations, …) ··· ‹ title › ··· ⚙ (a flex row, see .head) Every page but Home has it, and only these: the nav buttons (nav_btns, the page you're on marked .on), the yellow title in a fixed-width slot with round ‹ › either side (title_block — nothing in the bar moves from page to page), the cog last (settings_btn: opens that page's Settings tab). Under the bar: the grey sub-heading (subline), then a page's sections as a tab row (tabs: Week | Month, Overview | Body | …). #} {% macro home_btn() %} {% endmacro %} {# tab = the Settings tab to open (#calendar, #work, …) #} {% macro settings_btn(tab="") %} {% set me = viewer() %} {% if me.kind != "admin" %}{# not an admin: the person button — log in, or who you are + log out #} {% else %} {% endif %} {% endmacro %} {# a plugin's icon: its SVG (glyph_svg) or its glyph, in its colour #} {% macro plugin_icon(glyph, color=None, svg=None, label="") %}{% if svg %}{% else %}{{ glyph or label[:1] }}{% endif %}{% endmacro %} {# one button per enabled plugin (pluginhost.nav): its glyph, the label as tooltip #} {% macro plugin_btns() %} {% for p in plugin_nav() %}{% set here = [p.href] + p.also %}{{ plugin_icon(p.glyph, p.color, p.svg, p.label) }}{% endfor %} {% endmacro %} {# the page buttons, the same row on every page #} {% macro nav_btns() %} {% endmacro %} {% macro prev_btn(href, title="Previous", can=True) %} {% endmacro %} {% macro next_btn(href, title="Next", can=True) %} {% endmacro %} {# the yellow title in a fixed-width slot, the round ‹ › either side of it (omit an href = no arrow; its place stays empty, so the title never shifts) #} {% macro title_block(title, href=None, current=True, prev_href=None, next_href=None, can_prev=True, can_next=True, prev_title="Previous", next_title="Next", link_title=None) %}
{% if prev_href %}{{ prev_btn(prev_href, prev_title, can_prev) }}{% endif %} {% if href %}
{{ title }}
{% else %}
{{ title }}
{% endif %} {% if next_href %}{{ next_btn(next_href, next_title, can_next) }}{% endif %}
{% endmacro %} {# the grey sub-heading, under the top bar #} {% macro subline(sub) %}{% if sub %}
{{ sub }}
{% endif %}{% endmacro %} {# a plugin section's tab row (pluginhost.section: its own tabs + the plugins living inside it); the current one = `current`, else the longest href the page's address starts with #} {% macro section_tabs(name, current=None) %} {% set items = plugin_section(name).tabs %} {% set ns = namespace(cur=current) %} {# reverse order puts "/health/sleep" before "/health": the first match is the longest #} {% if not ns.cur %}{% for href, label in items | sort(attribute="0", reverse=True) %}{% if not ns.cur and (request.path == href or request.path.startswith(href ~ "/")) %}{% set ns.cur = href %}{% endif %}{% endfor %}{% endif %} {% set sec = plugin_section(name) %} {# own=True entries (e.g. "Edit layout") only on the host's own tabs #} {% set more = sec.more | selectattr("own") | list if (request.path.rstrip("/") or "/") in sec.own else [] %} {% set more = more + (sec.more | rejectattr("own") | list) %} {% endmacro %} {# a page's sections, under the top bar: items = [(href, label, on), …] #} {% macro tabs(items) %} {% endmacro %} {% macro header(title, sub, current, prev_href, next_href, mode, center_href, can_prev=True, can_next=True) %}
{{ nav_btns() }} {{ title_block(title, center_href, current, prev_href, next_href, can_prev, can_next, link_title="Today") }} {{ settings_btn("calendar") }}
{{ subline(sub) }} {{ tabs([("/week", "Week", mode == "week"), ("/month", "Month", mode == "month")]) }} {% endmacro %}