1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 19:56:16 +00:00
mycorrhiza/views/nav.qtpl
2021-09-01 19:25:47 +05:00

61 lines
1.6 KiB
Plaintext

{% import "net/http" %}
{% import "fmt" %}
{% import "strings" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% import "github.com/bouncepaw/mycorrhiza/hyphae" %}
{% func hyphaInfoEntry(h *hyphae.Hypha, u *user.User, action, displayText string) %}
{% if u.CanProceed(action) %}
<li class="hypha-info__entry hypha-info__entry_{%s action %}">
<a class="hypha-info__link" href="/{%s action %}/{%s h.Name %}">{%s displayText %}</a>
</li>
{% endif %}
{% endfunc %}
{% code
func backlinksDisplay(h *hyphae.Hypha) string {
n := hyphae.BacklinksCount(h)
suffix := "s"
if n % 10 == 1 {
suffix = ""
}
return fmt.Sprintf("%d backlink%s", n, suffix)
}
%}
{% func hyphaInfo(rq *http.Request, h *hyphae.Hypha) %}
{% code
u := user.FromRequest(rq)
%}
<nav class="hypha-info">
<ul class="hypha-info__list">
{%= hyphaInfoEntry(h, u, "history", "View history") %}
{%= hyphaInfoEntry(h, u, "rename-ask", "Rename") %}
{%= hyphaInfoEntry(h, u, "delete-ask", "Delete") %}
{%= hyphaInfoEntry(h, u, "text", "View markup") %}
{%= hyphaInfoEntry(h, u, "attachment", "Manage attachment") %}
{%= hyphaInfoEntry(h, u, "backlinks", backlinksDisplay(h)) %}
</ul>
</nav>
{% endfunc %}
{% func siblingHyphaeHTML(siblings string) %}
<aside class="sibling-hyphae layout-card">
<h2 class="sibling-hyphae__title layout-card__title">Sibling hyphae</h2>
{%s= siblings %}
</aside>
{% endfunc %}
{% func SubhyphaeHTML(subhyphae string) %}
{% if strings.TrimSpace(subhyphae) != "" %}
<section class="subhyphae">
<h2 class="subhyphae__title">Subhyphae</h2>
<nav class="subhyphae__nav">
<ul class="subhyphae__list">
{%s= subhyphae %}
</ul>
</nav>
</section>
{% endif %}
{% endfunc %}