1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00
mycorrhiza/templates/common.qtpl

55 lines
1.3 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="navlinks">
<ul>
{%- for _, entry := range navEntries -%}
{%- if navType == "revision" && entry.path == "revision" -%}
<li><b>{%s revisionHash[0] %}</b></li>
{%- elseif navType == entry.path -%}
<li><b>{%s entry.title %}</b></li>
{%- elseif entry.path != "revision" && u.CanProceed(entry.path) -%}
<li><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="navlinks__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 %}