1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 05:50:27 +00:00
mycorrhiza/views/mutators.qtpl

132 lines
5.7 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 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
onclick string
display string
}{
2021-09-06 17:46:34 +00:00
{"link", "wrapLink()", fmt.Sprintf("[[%s]]", lc.Get("edit.link"))},
{"titlelink", "wrapTitleLink()", fmt.Sprintf("[[%s | %s]]", lc.Get("edit.link"), lc.Get("edit.link_title"))},
{"heading1", "insertHeading1()", fmt.Sprintf("= %s", lc.Get("edit.heading"))},
{"heading2", "insertHeading2()", fmt.Sprintf("== %s", lc.Get("edit.heading"))},
2021-09-06 17:46:34 +00:00
{"bold", "wrapBold()", fmt.Sprintf("<b>**%s**</b>", lc.Get("edit.bold"))},
{"italic", "wrapItalic()", fmt.Sprintf("<i>//%s//</i>", lc.Get("edit.italic"))},
{"highlighted", "wrapHighlighted()", fmt.Sprintf("<mark>++%s++</mark>", lc.Get("edit.highlight"))},
{"underline", "wrapUnderline()", fmt.Sprintf("<u>__%s__</u>", lc.Get("edit.underline"))},
{"monospace", "wrapMonospace()", fmt.Sprintf("<code>`%s`</code>", lc.Get("edit.mono"))},
{"lifted", "wrapLifted()", fmt.Sprintf("<sup>^^%s^^</sup>", lc.Get("edit.super"))}, // inconsistent names: lifted, supertext. How cute ❤️
{"lowered", "wrapLowered()", fmt.Sprintf("<sub>,,%s,,</sub>", lc.Get("edit.sub"))},
{"strikethrough", "wrapStrikethrough()", fmt.Sprintf("<strike>~~%s~~</strike>", lc.Get("edit.strike"))},
{"rocket", "insertRocket()", "=> " + lc.Get("edit.rocket")},
{"xcl", "insertXcl()", "<= " + lc.Get("edit.transclude")},
{"img", "insertImgBlock()", "<code>img {}</code>"},
{"table", "insertTableBlock()", "<code>table {}</code>"},
2021-09-06 17:46:34 +00:00
{"hr", "insertHorizontalBar()", lc.Get("edit.hr")},
{"codeblock", "insertCodeblock()", lc.Get("edit.code")},
{"bulletedlist", "insertBulletedList()", "* " + lc.Get("edit.bullets")},
{"numberedlist", "insertNumberedList()", "*. " + lc.Get("edit.numbers")},
} %}
<button
class="btn edit-toolbar__btn edit-toolbar__{%s el.class %}"
onclick="{%s el.onclick %}">
{%s= el.display %}
</button>
{% endfor %}
</section>
2021-09-06 17:46:34 +00:00
<p class="edit-toolbar__ad">{%s= lc.Get("edit.help", &l18n.Replacements{"link": fmt.Sprintf("<a href=\"/help/%s/mycomarkup\" target=\"_blank\" class=\"shy-link\">%s</a>", lc.Locale, lc.Get("edit.help_link"))}) %}</p>
<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
onclick string
display string
}{
2021-09-06 17:46:34 +00:00
{"date", "insertDate()", lc.Get("edit.date")},
{"time", "insertTimeUTC()", lc.Get("edit.time")},
} %}
<button
class="btn edit-toolbar__btn edit-toolbar__{%s el.class %}"
onclick="{%s el.onclick %}">
{%s= el.display %}
</button>
{% endfor %}
{% if u.Group != "anon" %}
<button
class="btn edit-toolbar__btn edit-toolbar__user-link"
onclick="insertUserlink()">
2021-09-06 17:46:34 +00:00
{%s lc.Get("edit.selflink") %}
</button>
{% endif %}
</section>
</aside>
<script src="/static/toolbar.js"></script>
{% endfunc %}
{% func EditHTML(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
2021-06-14 00:38:43 +00:00
{% func PreviewHTML(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 %}