mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 11:46:16 +00:00
ae13fdab43
Now type switches are enforced
157 lines
5.7 KiB
Plaintext
157 lines
5.7 KiB
Plaintext
{% import "net/http" %}
|
|
{% import "strings" %}
|
|
{% import "path" %}
|
|
{% import "os" %}
|
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/hyphae" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/mimetype" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/tree" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/user" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/util" %}
|
|
|
|
{% func AttachmentMenuHTML(rq *http.Request, h *hyphae.MediaHypha, u *user.User) %}
|
|
{% code
|
|
lc := l18n.FromRequest(rq)
|
|
%}
|
|
<div class="layout">
|
|
<main class="main-width attachment-tab">
|
|
<h1>{%s= lc.Get("ui.attach_title", &l18n.Replacements{"name": beautifulLink(h.CanonicalName())}) %}</h1>
|
|
{% if h.BinaryPath() == "" %}
|
|
<p class="explanation">{%s lc.Get("ui.attach_empty") %} <a href="/help/en/attachment" class="shy-link">{%s lc.Get("ui.attach_link") %}</a></p>
|
|
{% else %}
|
|
<p class="explanation">{%s lc.Get("ui.attach_tip") %} <a href="/help/en/attachment" class="shy-link">{%s lc.Get("ui.attach_link") %}</a></p>
|
|
{% endif %}
|
|
|
|
<section class="amnt-grid">
|
|
|
|
{% if h.BinaryPath() != "" %}
|
|
{% code
|
|
mime := mimetype.FromExtension(path.Ext(h.BinaryPath()))
|
|
fileinfo, err := os.Stat(h.BinaryPath()) %}
|
|
{% if err == nil %}
|
|
<fieldset class="amnt-menu-block">
|
|
<legend class="modal__title modal__title_small">{%s lc.Get("ui.attach_stat") %}</legend>
|
|
<p class="modal__confirmation-msg"><b>{%s lc.Get("ui.attach_stat_size") %}</b> {%s lc.GetPlural64("ui.attach_size_value", fileinfo.Size())%}</p>
|
|
<p><b>{%s lc.Get("ui.attach_stat_mime") %}</b> {%s mime %}</p>
|
|
</fieldset>
|
|
{% endif %}
|
|
|
|
{% if strings.HasPrefix(mime, "image/") %}
|
|
<fieldset class="amnt-menu-block">
|
|
<legend class="modal__title modal__title_small">{%s lc.Get("ui.attach_include") %}</legend>
|
|
<p class="modal__confirmation-msg">{%s lc.Get("ui.attach_include_tip") %}</p>
|
|
<pre class="codeblock"><code>img { {%s h.CanonicalName() %} }</code></pre>
|
|
</fieldset>
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
{% if u.CanProceed("upload-binary") %}
|
|
<form action="/upload-binary/{%s h.CanonicalName() %}"
|
|
method="post" enctype="multipart/form-data"
|
|
class="upload-binary modal amnt-menu-block">
|
|
<fieldset class="modal__fieldset">
|
|
<legend class="modal__title modal__title_small">{%s lc.Get("ui.attach_new") %}</legend>
|
|
<p class="modal__confirmation-msg">{%s lc.Get("ui.attach_new_tip") %}</p>
|
|
<label for="upload-binary__input"></label>
|
|
<input type="file" id="upload-binary__input" name="binary">
|
|
|
|
<button type="submit" class="btn stick-to-bottom" value="Upload">{%s lc.Get("ui.attach_upload")%}</button>
|
|
</fieldset>
|
|
</form>
|
|
{% endif %}
|
|
|
|
{% if h.BinaryPath() != "" && u.CanProceed("unattach-confirm") %}
|
|
<form action="/unattach-confirm/{%s h.CanonicalName() %}" method="post" class="modal amnt-menu-block">
|
|
<fieldset class="modal__fieldset">
|
|
<legend class="modal__title modal__title_small">{%s lc.Get("ui.attach_remove") %}</legend>
|
|
<p class="modal__confirmation-msg">{%s lc.Get("ui.attach_remove_tip") %}</p>
|
|
<button type="submit" class="btn" value="Unattach">{%s lc.Get("ui.attach_remove_button") %}</button>
|
|
</fieldset>
|
|
</form>
|
|
{% endif %}
|
|
|
|
</section>
|
|
</main>
|
|
</div>
|
|
{% endfunc %}
|
|
|
|
If `contents` == "", a helpful message is shown instead.
|
|
|
|
If you rename .prevnext, change the docs too.
|
|
{% func HyphaHTML(rq *http.Request, lc *l18n.Localizer, h hyphae.Hypher, contents string) %}
|
|
{% code
|
|
siblings, subhyphae, prevHyphaName, nextHyphaName := tree.Tree(h.CanonicalName())
|
|
u := user.FromRequest(rq)
|
|
%}
|
|
<div class="layout">
|
|
<main class="main-width">
|
|
<section id="hypha">
|
|
{% if u.CanProceed("edit") %}
|
|
<div class="btn btn_navititle">
|
|
<a class="btn__link_navititle" href="/edit/{%s h.CanonicalName() %}">{%s lc.Get("ui.edit_link") %}</a>
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if cfg.UseAuth && util.IsProfileName(h.CanonicalName()) && u.Name == strings.TrimPrefix(h.CanonicalName(), cfg.UserHypha + "/") %}
|
|
<div class="btn btn_navititle">
|
|
<a class="btn__link_navititle" href="/logout">{%s lc.Get("ui.logout_link") %}</a>
|
|
</div>
|
|
{% if u.Group == "admin" %}
|
|
<div class="btn btn_navititle">
|
|
<a class="btn__link_navititle" href="/admin">{%s lc.Get("ui.admin_panel") %}<a>
|
|
</div>
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
{%s= NaviTitleHTML(h) %}
|
|
{% switch h.(type) %}
|
|
{% case *hyphae.EmptyHypha %}
|
|
{%= nonExistentHyphaNotice(h, u, lc) %}
|
|
{% default %}
|
|
{%s= contents %}
|
|
{% endswitch %}
|
|
</section>
|
|
<section class="prevnext">
|
|
{% if prevHyphaName != "" %}
|
|
<a class="prevnext__el prevnext__prev" href="/hypha/{%s prevHyphaName %}" rel="prev">← {%s util.BeautifulName(path.Base(prevHyphaName)) %}</a>
|
|
{% endif %}
|
|
{% if nextHyphaName != "" %}
|
|
<a class="prevnext__el prevnext__next" href="/hypha/{%s nextHyphaName %}" rel="next">{%s util.BeautifulName(path.Base(nextHyphaName)) %} →</a>
|
|
{% endif %}
|
|
</section>
|
|
{%= SubhyphaeHTML(subhyphae, lc) %}
|
|
<section id="hypha-bottom">
|
|
{%= hyphaInfo(rq, h) %}
|
|
</section>
|
|
</main>
|
|
{%= siblingHyphaeHTML(siblings, lc) %}
|
|
</div>
|
|
{%= viewScripts() %}
|
|
{% endfunc %}
|
|
|
|
{% func RevisionHTML(rq *http.Request, lc *l18n.Localizer, h hyphae.Hypher, contents, revHash string) %}
|
|
{% code
|
|
siblings, subhyphae, _, _ := tree.Tree(h.CanonicalName())
|
|
%}
|
|
<div class="layout">
|
|
<main class="main-width">
|
|
<section>
|
|
<p>{%s lc.Get("ui.revision_warning") %} <a href="/rev-text/{%s revHash %}/{%s h.CanonicalName() %}">{%s lc.Get("ui.revision_link") %}</a></p>
|
|
{%s= NaviTitleHTML(h) %}
|
|
{%s= contents %}
|
|
</section>
|
|
{%= SubhyphaeHTML(subhyphae, lc) %}
|
|
</main>
|
|
{%= siblingHyphaeHTML(siblings, lc) %}
|
|
</div>
|
|
{%= viewScripts() %}
|
|
{% endfunc %}
|
|
|
|
{% func viewScripts() %}
|
|
{% for _, scriptPath := range cfg.ViewScripts %}
|
|
<script src="{%s scriptPath %}"></script>
|
|
{% endfor %}
|
|
{% endfunc %}
|