1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-16 06:50:26 +00:00
mycorrhiza/views/mutators.qtpl

126 lines
5.2 KiB
Plaintext
Raw Normal View History

2021-09-06 17:46:34 +00:00
{% import "fmt" %}
{% import "net/http" %}
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
2021-09-06 17:46:34 +00:00
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
2021-09-06 17:46:34 +00:00
{% func Toolbar(u *user.User, lc *l18n.Localizer) %}
<aside class="edit-toolbar markup-toolbar layout-card">
2021-09-06 17:46:34 +00:00
<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">
2021-09-06 17:46:34 +00:00
<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">
2021-09-06 17:46:34 +00:00
{%s lc.Get("edit.selflink") %}
</button>
{% endif %}
</section>
</aside>
<script src="/static/toolbar.js"></script>
{% endfunc %}
2022-03-20 21:24:40 +00:00
{% func Editor(rq *http.Request, hyphaName, textAreaFill, warning string) %}
2021-09-06 17:46:34 +00:00
{% code
lc := l18n.FromRequest(rq)
%}
2021-01-26 05:41:57 +00:00
<div class="layout">
<main class="main-width edit edit_no-preview">
2021-09-06 17:46:34 +00:00
<h1 class="edit__title">{%s= fmt.Sprintf(lc.Get("edit.title"), beautifulLink(hyphaName)) %}</h1>
{%s= warning %}
<form method="post" class="edit-form"
action="/upload-text/{%s hyphaName %}">
<textarea name="text" class="edit-form__textarea" autofocus>{%s textAreaFill %}</textarea>
2021-06-21 04:52:38 +00:00
<br><br>
2021-09-06 17:46:34 +00:00
<label for="text">{%s lc.Get("edit.tag") %}</label><br>
2021-06-21 04:52:38 +00:00
<input id="text" type="text" name="message" class="edit-form__message">
<br><br>
2021-09-06 17:46:34 +00:00
<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>
</form>
</main>
2021-09-06 17:46:34 +00:00
{%s= Toolbar(user.FromRequest(rq), lc) %}
2021-01-26 05:41:57 +00:00
</div>
{%= editScripts() %}
2020-08-31 17:52:26 +00:00
{% endfunc %}
2021-01-16 16:42:18 +00:00
2022-03-20 21:24:40 +00:00
{% func Preview(rq *http.Request, hyphaName, textAreaFill, message, warning string, renderedPage string) %}
2021-09-06 17:46:34 +00:00
{% code
lc := l18n.FromRequest(rq)
%}
2021-01-26 05:41:57 +00:00
<div class="layout">
<main class="main-width edit edit_with-preview">
2021-09-06 17:46:34 +00:00
<h1 class="edit__title">{%s= fmt.Sprintf(lc.Get("edit.title"), beautifulLink(hyphaName)) %}</h1>
2021-01-16 16:42:18 +00:00
{%s= warning %}
<form method="post" class="edit-form"
action="/upload-text/{%s hyphaName %}">
<textarea name="text" class="edit-form__textarea" autofocus>{%s textAreaFill %}</textarea>
2021-06-21 04:52:38 +00:00
<br><br>
2021-09-06 17:46:34 +00:00
<label for="text">{%s lc.Get("edit.tag") %}</label><br>
2021-06-14 00:38:43 +00:00
<input id="text" type="text" name="message" class="edit-form__message" value="{%s message %}">
2021-06-21 04:52:38 +00:00
<br><br>
2021-09-06 17:46:34 +00:00
<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>
2021-01-16 16:42:18 +00:00
</form>
2021-09-06 17:46:34 +00:00
<p class="warning">{%s lc.Get("edit.preview_tip") %}</p>
2021-03-09 15:51:37 +00:00
<article class="edit__preview">{%s= renderedPage %}</article>
2021-01-16 16:42:18 +00:00
</main>
2021-09-06 17:46:34 +00:00
{%s= Toolbar(user.FromRequest(rq), lc) %}
2021-01-26 05:41:57 +00:00
</div>
{%= editScripts() %}
2021-01-16 16:42:18 +00:00
{% endfunc %}
{% func editScripts() %}
<script src="/static/editor.js"></script>
{% for _, scriptPath := range cfg.EditScripts %}
<script src="{%s scriptPath %}"></script>
{% endfor %}
{% endfunc %}