mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
126 lines
5.2 KiB
Plaintext
126 lines
5.2 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)
|
|
%}
|
|
<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 Preview(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 %}
|