mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-08 10:51:09 +00:00
b1cdb1e279
All the remaining QTPL files were spread across the codebase. The plan is to get rid of them step by step and migrate to the new l10n approach, all based on Go std templates.
124 lines
5.3 KiB
Plaintext
124 lines
5.3 KiB
Plaintext
{% import "fmt" %}
|
|
{% import "net/http" %}
|
|
|
|
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
|
|
{% import "github.com/bouncepaw/mycorrhiza/user" %}
|
|
|
|
{% func Toolbar(u *user.User, lc *l18n.Localizer) %}
|
|
<aside class="edit-toolbar markup-toolbar layout-card">
|
|
<h2 class="edit-toolbar__title layout-card__title">{%s lc.Get("edit.markup")%}</h2>
|
|
<section class="edit-toolbar__buttons">
|
|
{% for _, el := range []struct{
|
|
class string
|
|
display string
|
|
}{
|
|
{"link", fmt.Sprintf("[[%s]]", lc.Get("edit.link"))},
|
|
{"titlelink", fmt.Sprintf("[[%s | %s]]", lc.Get("edit.link"), lc.Get("edit.link_title"))},
|
|
{"heading1", fmt.Sprintf("= %s", lc.Get("edit.heading"))},
|
|
{"heading2", fmt.Sprintf("== %s", lc.Get("edit.heading"))},
|
|
{"bold", fmt.Sprintf("<b>**%s**</b>", lc.Get("edit.bold"))},
|
|
{"italic", fmt.Sprintf("<i>//%s//</i>", lc.Get("edit.italic"))},
|
|
{"highlighted", fmt.Sprintf("<mark>++%s++</mark>", lc.Get("edit.highlight"))},
|
|
{"underline", fmt.Sprintf("<u>__%s__</u>", lc.Get("edit.underline"))},
|
|
{"monospace", fmt.Sprintf("<code>`%s`</code>", lc.Get("edit.mono"))},
|
|
{"lifted", fmt.Sprintf("<sup>^^%s^^</sup>", lc.Get("edit.super"))}, // inconsistent names: lifted, supertext. How cute ❤️
|
|
{"lowered", fmt.Sprintf("<sub>,,%s,,</sub>", lc.Get("edit.sub"))},
|
|
{"strikethrough", fmt.Sprintf("<strike>~~%s~~</strike>", lc.Get("edit.strike"))},
|
|
{"rocket", "=> " + lc.Get("edit.rocket")},
|
|
{"xcl", "<= " + lc.Get("edit.transclude")},
|
|
{"img", "<code>img {}</code>"},
|
|
{"table", "<code>table {}</code>"},
|
|
{"hr", lc.Get("edit.hr")},
|
|
{"codeblock", lc.Get("edit.code")},
|
|
{"bulletedlist", "* " + lc.Get("edit.bullets")},
|
|
{"numberedlist", "*. " + lc.Get("edit.numbers")},
|
|
} %}
|
|
<button class="btn edit-toolbar__btn edit-toolbar__{%s el.class %}">
|
|
{%s= el.display %}
|
|
</button>
|
|
{% endfor %}
|
|
</section>
|
|
<p class="edit-toolbar__ad">{%s= lc.Get("edit.help", &l18n.Replacements{"link": fmt.Sprintf("<a href=\"/help/en/mycomarkup\" target=\"_blank\" class=\"shy-link\">%s</a>", lc.Get("edit.help_link"))}) %}</p>
|
|
</aside>
|
|
<aside class="edit-toolbar action-toolbar layout-card">
|
|
<h2 class="edit-toolbar__title layout-card__title">{%s lc.Get("edit.actions")%}</h2>
|
|
<section class="edit-toolbar__buttons">
|
|
{% for _, el := range []struct{
|
|
class string
|
|
display string
|
|
}{
|
|
{"date", lc.Get("edit.date")},
|
|
{"time", lc.Get("edit.time")},
|
|
} %}
|
|
<button class="btn edit-toolbar__btn edit-toolbar__{%s el.class %}">
|
|
{%s= el.display %}
|
|
</button>
|
|
{% endfor %}
|
|
{% if u.Group != "anon" %}
|
|
<button class="btn edit-toolbar__btn edit-toolbar__user-link">
|
|
{%s lc.Get("edit.selflink") %}
|
|
</button>
|
|
{% endif %}
|
|
</section>
|
|
</aside>
|
|
<script src="/static/toolbar.js"></script>
|
|
{% endfunc %}
|
|
|
|
{% func Editor(rq *http.Request, hyphaName, textAreaFill, warning string) %}
|
|
{% code
|
|
lc := l18n.FromRequest(rq)
|
|
%}
|
|
<main class="main-width edit edit_no-preview">
|
|
<form method="post" class="edit-form"
|
|
action="/upload-text/{%s hyphaName %}">
|
|
<h1 class="edit__title">{%s= fmt.Sprintf(lc.Get("edit.title"), beautifulLink(hyphaName)) %}</h1>
|
|
{%s= warning %}
|
|
<textarea name="text" class="edit-form__textarea" autofocus>{%s textAreaFill %}</textarea>
|
|
<p class="edit-form__message-zone">
|
|
<input id="text" type="text" name="message" class="edit-form__message" placeholder="{%s lc.Get("edit.tag") %}" aria-label="{%s lc.Get("edit.tag") %}">
|
|
</p>
|
|
<p class="edit-form__buttons">
|
|
<button type="submit" name="action" class="btn btn_accent edit-form__save" value="Save">{%s lc.Get("edit.save") %}</button>
|
|
<button type="submit" name="action" class="btn edit-form__preview" value="Preview">{%s lc.Get("edit.preview") %}</button>
|
|
<a href="/hypha/{%s hyphaName %}" class="btn btn_weak">{%s lc.Get("ui.cancel") %}</a>
|
|
</p>
|
|
</form>
|
|
</main>
|
|
{%s= Toolbar(user.FromRequest(rq), lc) %}
|
|
{%= editScripts() %}
|
|
{% endfunc %}
|
|
|
|
{% func Preview(rq *http.Request, hyphaName, textAreaFill, message, warning string, renderedPage string) %}
|
|
{% code
|
|
lc := l18n.FromRequest(rq)
|
|
%}
|
|
<main class="main-width edit edit_with-preview">
|
|
<form method="post" class="edit-form"
|
|
action="/upload-text/{%s hyphaName %}">
|
|
<h1 class="edit__title">{%s= fmt.Sprintf(lc.Get("edit.title"), beautifulLink(hyphaName)) %}</h1>
|
|
{%s= warning %}
|
|
<textarea name="text" class="edit-form__textarea" autofocus>{%s textAreaFill %}</textarea>
|
|
<p class="edit-form__message-zone">
|
|
<input id="text" type="text" name="message" class="edit-form__message" placeholder="{%s lc.Get("edit.tag") %}" aria-label="{%s lc.Get("edit.tag") %}">
|
|
</p>
|
|
<p class="edit-form__buttons">
|
|
<button type="submit" name="action" class="btn btn_accent edit-form__save" value="Save">{%s lc.Get("edit.save") %}</button>
|
|
<button type="submit" name="action" class="btn edit-form__preview" value="Preview">{%s lc.Get("edit.preview") %}</button>
|
|
<a href="/hypha/{%s hyphaName %}" class="btn btn_weak">{%s lc.Get("ui.cancel") %}</a>
|
|
</p>
|
|
</form>
|
|
<p class="warning">{%s lc.Get("edit.preview_tip") %}</p>
|
|
<article class="edit__preview">{%s= renderedPage %}</article>
|
|
</main>
|
|
{%s= Toolbar(user.FromRequest(rq), lc) %}
|
|
{%= editScripts() %}
|
|
{% endfunc %}
|
|
|
|
{% func editScripts() %}
|
|
<script src="/static/editor.js"></script>
|
|
{% for _, scriptPath := range cfg.EditScripts %}
|
|
<script src="{%s scriptPath %}"></script>
|
|
{% endfor %}
|
|
{% endfunc %}
|