1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 19:56:16 +00:00
mycorrhiza/templates/common.qtpl
2021-01-20 18:53:30 +05:00

61 lines
1.5 KiB
Plaintext

{% import "net/http" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% import "github.com/bouncepaw/mycorrhiza/util" %}
This is the <nav> seen on top of many pages.
{% code
type navEntry struct {
path string
title string
}
var navEntries = []navEntry{
{"page", "Hypha"},
{"edit", "Edit"},
{"text", "Raw text"},
{"history", "History"},
{"revision", "NOT REACHED"},
{"rename-ask", "Rename"},
{"delete-ask", "Delete"},
}
%}
{% func navHTML(rq *http.Request, hyphaName, navType string, revisionHash ...string) %}
{% code
u := user.FromRequest(rq)
%}
<nav class="hypha-tabs">
<ul class="hypha-tabs__flex">
{%- for _, entry := range navEntries -%}
{%- if navType == "revision" && entry.path == "revision" -%}
<li class="hypha-tabs__tab hypha-tabs__tab_active">
{%s revisionHash[0] %}
</li>
{%- elseif navType == entry.path -%}
<li class="hypha-tabs__tab hypha-tabs__tab_active">
{%s entry.title %}
</li>
{%- elseif entry.path != "revision" && u.CanProceed(entry.path) -%}
<li class="hypha-tabs__tab">
<a href="/{%s entry.path %}/{%s hyphaName %}">{%s entry.title %}</a>
</li>
{%- endif -%}
{%- endfor -%}
{%s= userMenuHTML(u) %}
</ul>
</nav>
{% endfunc %}
{% func userMenuHTML(u *user.User) %}
{% if user.AuthUsed %}
<li class="hypha-tabs__tab hypha-tabs__user">
{% if u.Group == "anon" %}
<a href="/login">Login</a>
{% else %}
<a href="/page/{%s util.UserTree %}/{%s u.Name %}">{%s u.Name %}</a>
{% endif %}
</li>
{% endif %}
{% endfunc %}