mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 11:46:16 +00:00
9950956654
Better usage of space, actually
134 lines
5.7 KiB
Plaintext
134 lines
5.7 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
|
|
onclick string
|
|
display string
|
|
}{
|
|
{"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"))},
|
|
{"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>"},
|
|
{"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>
|
|
<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>
|
|
</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
|
|
onclick string
|
|
display string
|
|
}{
|
|
{"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()">
|
|
{%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) %}
|
|
{% code
|
|
lc := l18n.FromRequest(rq)
|
|
%}
|
|
<div class="layout">
|
|
<main class="main-width edit edit_no-preview">
|
|
<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>
|
|
<br><br>
|
|
<label for="text">{%s lc.Get("edit.tag") %}</label><br>
|
|
<input id="text" type="text" name="message" class="edit-form__message">
|
|
<br><br>
|
|
<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>
|
|
{%s= Toolbar(user.FromRequest(rq), lc) %}
|
|
</div>
|
|
{%= editScripts() %}
|
|
{% endfunc %}
|
|
|
|
{% func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, message, warning string, renderedPage string) %}
|
|
{% code
|
|
lc := l18n.FromRequest(rq)
|
|
%}
|
|
<div class="layout">
|
|
<main class="main-width edit edit_with-preview">
|
|
<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>
|
|
<br><br>
|
|
<label for="text">{%s lc.Get("edit.tag") %}</label><br>
|
|
<input id="text" type="text" name="message" class="edit-form__message" value="{%s message %}">
|
|
<br><br>
|
|
<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>
|
|
<p class="warning">{%s lc.Get("edit.preview_tip") %}</p>
|
|
<article class="edit__preview">{%s= renderedPage %}</article>
|
|
</main>
|
|
{%s= Toolbar(user.FromRequest(rq), lc) %}
|
|
</div>
|
|
{%= editScripts() %}
|
|
{% endfunc %}
|
|
|
|
{% func editScripts() %}
|
|
<script src="/static/editor.js"></script>
|
|
{% for _, scriptPath := range cfg.EditScripts %}
|
|
<script src="{%s scriptPath %}"></script>
|
|
{% endfor %}
|
|
{% endfunc %}
|