1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00

Merge pull request #49 from DanInSpace104/toolbar

#47 Insert current date button
This commit is contained in:
Timur Ismagilov 2021-03-20 20:56:10 +05:00 committed by GitHub
commit 107b525eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 258 additions and 178 deletions

View File

@ -10,6 +10,10 @@ Usage of %s:
{% cat "default.css" %}
{% endfunc %}
{% func ToolbarJS() %}
{% cat "toolbar.js" %}
{% endfunc %}
Next three are from https://remixicon.com/
{% func IconHTTP() %}
{% cat "icon/http-protocol-icon.svg" %}

View File

@ -414,136 +414,186 @@ func DefaultCSS() string {
//line assets/assets.qtpl:11
}
//line assets/assets.qtpl:13
func StreamToolbarJS(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:13
qw422016.N().S(`
`)
//line assets/assets.qtpl:14
qw422016.N().S(`const editTextarea = document.getElementsByClassName('edit-form__textarea')[0]
function insertTextAtCursor(text, el = editTextarea) {
const [start, end] = [el.selectionStart, el.selectionEnd];
el.setRangeText(text, start, end, 'select');
}
function insertDate() {
let date = new Date().toISOString().split('T')[0]
insertTextAtCursor(date)
}
`)
//line assets/assets.qtpl:14
qw422016.N().S(`
`)
//line assets/assets.qtpl:15
}
//line assets/assets.qtpl:15
func WriteToolbarJS(qq422016 qtio422016.Writer) {
//line assets/assets.qtpl:15
qw422016 := qt422016.AcquireWriter(qq422016)
//line assets/assets.qtpl:15
StreamToolbarJS(qw422016)
//line assets/assets.qtpl:15
qt422016.ReleaseWriter(qw422016)
//line assets/assets.qtpl:15
}
//line assets/assets.qtpl:15
func ToolbarJS() string {
//line assets/assets.qtpl:15
qb422016 := qt422016.AcquireByteBuffer()
//line assets/assets.qtpl:15
WriteToolbarJS(qb422016)
//line assets/assets.qtpl:15
qs422016 := string(qb422016.B)
//line assets/assets.qtpl:15
qt422016.ReleaseByteBuffer(qb422016)
//line assets/assets.qtpl:15
return qs422016
//line assets/assets.qtpl:15
}
// Next three are from https://remixicon.com/
//line assets/assets.qtpl:14
//line assets/assets.qtpl:18
func StreamIconHTTP(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:14
//line assets/assets.qtpl:18
qw422016.N().S(`
`)
//line assets/assets.qtpl:15
//line assets/assets.qtpl:19
qw422016.N().S(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16"><path fill="#999" d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-2.29-2.333A17.9 17.9 0 0 1 8.027 13H4.062a8.008 8.008 0 0 0 5.648 6.667zM10.03 13c.151 2.439.848 4.73 1.97 6.752A15.905 15.905 0 0 0 13.97 13h-3.94zm9.908 0h-3.965a17.9 17.9 0 0 1-1.683 6.667A8.008 8.008 0 0 0 19.938 13zM4.062 11h3.965A17.9 17.9 0 0 1 9.71 4.333 8.008 8.008 0 0 0 4.062 11zm5.969 0h3.938A15.905 15.905 0 0 0 12 4.248 15.905 15.905 0 0 0 10.03 11zm4.259-6.667A17.9 17.9 0 0 1 15.973 11h3.965a8.008 8.008 0 0 0-5.648-6.667z"/></svg>
`)
//line assets/assets.qtpl:15
qw422016.N().S(`
`)
//line assets/assets.qtpl:16
}
//line assets/assets.qtpl:16
func WriteIconHTTP(qq422016 qtio422016.Writer) {
//line assets/assets.qtpl:16
qw422016 := qt422016.AcquireWriter(qq422016)
//line assets/assets.qtpl:16
StreamIconHTTP(qw422016)
//line assets/assets.qtpl:16
qt422016.ReleaseWriter(qw422016)
//line assets/assets.qtpl:16
}
//line assets/assets.qtpl:16
func IconHTTP() string {
//line assets/assets.qtpl:16
qb422016 := qt422016.AcquireByteBuffer()
//line assets/assets.qtpl:16
WriteIconHTTP(qb422016)
//line assets/assets.qtpl:16
qs422016 := string(qb422016.B)
//line assets/assets.qtpl:16
qt422016.ReleaseByteBuffer(qb422016)
//line assets/assets.qtpl:16
return qs422016
//line assets/assets.qtpl:16
}
//line assets/assets.qtpl:18
func StreamIconGemini(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:18
qw422016.N().S(`
`)
//line assets/assets.qtpl:19
qw422016.N().S(`
`)
//line assets/assets.qtpl:20
}
//line assets/assets.qtpl:20
func WriteIconHTTP(qq422016 qtio422016.Writer) {
//line assets/assets.qtpl:20
qw422016 := qt422016.AcquireWriter(qq422016)
//line assets/assets.qtpl:20
StreamIconHTTP(qw422016)
//line assets/assets.qtpl:20
qt422016.ReleaseWriter(qw422016)
//line assets/assets.qtpl:20
}
//line assets/assets.qtpl:20
func IconHTTP() string {
//line assets/assets.qtpl:20
qb422016 := qt422016.AcquireByteBuffer()
//line assets/assets.qtpl:20
WriteIconHTTP(qb422016)
//line assets/assets.qtpl:20
qs422016 := string(qb422016.B)
//line assets/assets.qtpl:20
qt422016.ReleaseByteBuffer(qb422016)
//line assets/assets.qtpl:20
return qs422016
//line assets/assets.qtpl:20
}
//line assets/assets.qtpl:22
func StreamIconGemini(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:22
qw422016.N().S(`
`)
//line assets/assets.qtpl:23
qw422016.N().S(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16"><path fill="#999" d="M15.502 20A6.523 6.523 0 0 1 12 23.502 6.523 6.523 0 0 1 8.498 20h2.26c.326.489.747.912 1.242 1.243.495-.33.916-.754 1.243-1.243h2.259zM18 14.805l2 2.268V19H4v-1.927l2-2.268V9c0-3.483 2.504-6.447 6-7.545C15.496 2.553 18 5.517 18 9v5.805zM17.27 17L16 15.56V9c0-2.318-1.57-4.43-4-5.42C9.57 4.57 8 6.681 8 9v6.56L6.73 17h10.54zM12 11a2 2 0 1 1 0-4 2 2 0 0 1 0 4z"/></svg>
`)
//line assets/assets.qtpl:19
qw422016.N().S(`
`)
//line assets/assets.qtpl:20
}
//line assets/assets.qtpl:20
func WriteIconGemini(qq422016 qtio422016.Writer) {
//line assets/assets.qtpl:20
qw422016 := qt422016.AcquireWriter(qq422016)
//line assets/assets.qtpl:20
StreamIconGemini(qw422016)
//line assets/assets.qtpl:20
qt422016.ReleaseWriter(qw422016)
//line assets/assets.qtpl:20
}
//line assets/assets.qtpl:20
func IconGemini() string {
//line assets/assets.qtpl:20
qb422016 := qt422016.AcquireByteBuffer()
//line assets/assets.qtpl:20
WriteIconGemini(qb422016)
//line assets/assets.qtpl:20
qs422016 := string(qb422016.B)
//line assets/assets.qtpl:20
qt422016.ReleaseByteBuffer(qb422016)
//line assets/assets.qtpl:20
return qs422016
//line assets/assets.qtpl:20
}
//line assets/assets.qtpl:22
func StreamIconMailto(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:22
qw422016.N().S(`
`)
//line assets/assets.qtpl:23
qw422016.N().S(`
`)
//line assets/assets.qtpl:24
}
//line assets/assets.qtpl:24
func WriteIconGemini(qq422016 qtio422016.Writer) {
//line assets/assets.qtpl:24
qw422016 := qt422016.AcquireWriter(qq422016)
//line assets/assets.qtpl:24
StreamIconGemini(qw422016)
//line assets/assets.qtpl:24
qt422016.ReleaseWriter(qw422016)
//line assets/assets.qtpl:24
}
//line assets/assets.qtpl:24
func IconGemini() string {
//line assets/assets.qtpl:24
qb422016 := qt422016.AcquireByteBuffer()
//line assets/assets.qtpl:24
WriteIconGemini(qb422016)
//line assets/assets.qtpl:24
qs422016 := string(qb422016.B)
//line assets/assets.qtpl:24
qt422016.ReleaseByteBuffer(qb422016)
//line assets/assets.qtpl:24
return qs422016
//line assets/assets.qtpl:24
}
//line assets/assets.qtpl:26
func StreamIconMailto(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:26
qw422016.N().S(`
`)
//line assets/assets.qtpl:27
qw422016.N().S(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16"><path fill="#999" d="M3 3h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1zm17 4.238l-7.928 7.1L4 7.216V19h16V7.238zM4.511 5l7.55 6.662L19.502 5H4.511z"/></svg>
`)
//line assets/assets.qtpl:23
qw422016.N().S(`
`)
//line assets/assets.qtpl:24
}
//line assets/assets.qtpl:24
func WriteIconMailto(qq422016 qtio422016.Writer) {
//line assets/assets.qtpl:24
qw422016 := qt422016.AcquireWriter(qq422016)
//line assets/assets.qtpl:24
StreamIconMailto(qw422016)
//line assets/assets.qtpl:24
qt422016.ReleaseWriter(qw422016)
//line assets/assets.qtpl:24
}
//line assets/assets.qtpl:24
func IconMailto() string {
//line assets/assets.qtpl:24
qb422016 := qt422016.AcquireByteBuffer()
//line assets/assets.qtpl:24
WriteIconMailto(qb422016)
//line assets/assets.qtpl:24
qs422016 := string(qb422016.B)
//line assets/assets.qtpl:24
qt422016.ReleaseByteBuffer(qb422016)
//line assets/assets.qtpl:24
return qs422016
//line assets/assets.qtpl:24
}
// This is a modified version of https://www.svgrepo.com/svg/232085/rat
//line assets/assets.qtpl:27
func StreamIconGopher(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:27
qw422016.N().S(`
`)
//line assets/assets.qtpl:28
}
//line assets/assets.qtpl:28
func WriteIconMailto(qq422016 qtio422016.Writer) {
//line assets/assets.qtpl:28
qw422016 := qt422016.AcquireWriter(qq422016)
//line assets/assets.qtpl:28
StreamIconMailto(qw422016)
//line assets/assets.qtpl:28
qt422016.ReleaseWriter(qw422016)
//line assets/assets.qtpl:28
}
//line assets/assets.qtpl:28
func IconMailto() string {
//line assets/assets.qtpl:28
qb422016 := qt422016.AcquireByteBuffer()
//line assets/assets.qtpl:28
WriteIconMailto(qb422016)
//line assets/assets.qtpl:28
qs422016 := string(qb422016.B)
//line assets/assets.qtpl:28
qt422016.ReleaseByteBuffer(qb422016)
//line assets/assets.qtpl:28
return qs422016
//line assets/assets.qtpl:28
}
// This is a modified version of https://www.svgrepo.com/svg/232085/rat
//line assets/assets.qtpl:31
func StreamIconGopher(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:31
qw422016.N().S(`
`)
//line assets/assets.qtpl:32
qw422016.N().S(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="16" height="16">
<path fill="#999" d="M447.238,204.944v-70.459c0-8.836-7.164-16-16-16c-34.051,0-64.414,21.118-75.079,55.286
C226.094,41.594,0,133.882,0,319.435c0,0.071,0.01,0.14,0.011,0.21c0.116,44.591,36.423,80.833,81.04,80.833h171.203
@ -556,34 +606,34 @@ c55.425-8.382,107.014,29.269,115.759,84.394H295.484z"/>
<circle fill="#999" cx="415.238" cy="260.05" r="21.166"/>
</svg>
`)
//line assets/assets.qtpl:28
//line assets/assets.qtpl:32
qw422016.N().S(`
`)
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
}
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
func WriteIconGopher(qq422016 qtio422016.Writer) {
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
qw422016 := qt422016.AcquireWriter(qq422016)
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
StreamIconGopher(qw422016)
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
qt422016.ReleaseWriter(qw422016)
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
}
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
func IconGopher() string {
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
qb422016 := qt422016.AcquireByteBuffer()
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
WriteIconGopher(qb422016)
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
qs422016 := string(qb422016.B)
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
qt422016.ReleaseByteBuffer(qb422016)
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
return qs422016
//line assets/assets.qtpl:29
//line assets/assets.qtpl:33
}

11
assets/toolbar.js Normal file
View File

@ -0,0 +1,11 @@
const editTextarea = document.getElementsByClassName('edit-form__textarea')[0]
function insertTextAtCursor(text, el = editTextarea) {
const [start, end] = [el.selectionStart, el.selectionEnd];
el.setRangeText(text, start, end, 'select');
}
function insertDate() {
let date = new Date().toISOString().split('T')[0]
insertTextAtCursor(date)
}

View File

@ -117,6 +117,12 @@ func handlerStyle(w http.ResponseWriter, rq *http.Request) {
}
}
func handlerToolbar(w http.ResponseWriter, rq *http.Request) {
log.Println(rq.URL)
w.Header().Set("Content-Type", "text/javascript;charset=utf-8")
w.Write([]byte(assets.ToolbarJS()))
}
func handlerIcon(w http.ResponseWriter, rq *http.Request) {
iconName := strings.TrimPrefix(rq.URL.Path, "/static/icon/")
if iconName == "https" {
@ -199,6 +205,7 @@ func main() {
http.ServeFile(w, rq, WikiDir+"/static/favicon.ico")
})
http.HandleFunc("/static/common.css", handlerStyle)
http.HandleFunc("/static/toolbar.js", handlerToolbar)
http.HandleFunc("/static/icon/", handlerIcon)
http.HandleFunc("/robots.txt", handlerRobotsTxt)
http.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) {

View File

@ -7,9 +7,12 @@
<main class="main-width edit edit_no-preview">
<h1 class="edit__title">Edit {%s util.BeautifulName(hyphaName) %}</h1>
{%s= warning %}
<div class="edit__toolbar">
<button onclick="insertDate()">Insert Date</button>
</div>
<form method="post" class="edit-form"
action="/upload-text/{%s hyphaName %}">
<textarea name="text">{%s textAreaFill %}</textarea>
<textarea name="text" class="edit-form__textarea">{%s textAreaFill %}</textarea>
<br/>
<input type="submit" name="action" value="Save" class="edit-form__save"/>
<input type="submit" name="action" value="Preview" class="edit-form__preview">
@ -17,6 +20,7 @@
</form>
</main>
</div>
<script src="/static/toolbar.js"></script>
{% endfunc %}
{% func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) %}

View File

@ -44,133 +44,137 @@ func StreamEditHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, text
qw422016.N().S(warning)
//line views/mutators.qtpl:9
qw422016.N().S(`
<div class="edit__toolbar">
<button onclick="insertDate()">Insert Date</button>
</div>
<form method="post" class="edit-form"
action="/upload-text/`)
//line views/mutators.qtpl:11
//line views/mutators.qtpl:14
qw422016.E().S(hyphaName)
//line views/mutators.qtpl:11
//line views/mutators.qtpl:14
qw422016.N().S(`">
<textarea name="text">`)
//line views/mutators.qtpl:12
<textarea name="text" class="edit-form__textarea">`)
//line views/mutators.qtpl:15
qw422016.E().S(textAreaFill)
//line views/mutators.qtpl:12
//line views/mutators.qtpl:15
qw422016.N().S(`</textarea>
<br/>
<input type="submit" name="action" value="Save" class="edit-form__save"/>
<input type="submit" name="action" value="Preview" class="edit-form__preview">
<a href="/page/`)
//line views/mutators.qtpl:16
//line views/mutators.qtpl:19
qw422016.E().S(hyphaName)
//line views/mutators.qtpl:16
//line views/mutators.qtpl:19
qw422016.N().S(`" class="edit-form__cancel">Cancel</a>
</form>
</main>
</div>
<script src="/static/toolbar.js"></script>
`)
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
}
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
func WriteEditHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) {
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
StreamEditHTML(qw422016, rq, hyphaName, textAreaFill, warning)
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
qt422016.ReleaseWriter(qw422016)
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
}
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
func EditHTML(rq *http.Request, hyphaName, textAreaFill, warning string) string {
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
qb422016 := qt422016.AcquireByteBuffer()
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
WriteEditHTML(qb422016, rq, hyphaName, textAreaFill, warning)
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
qs422016 := string(qb422016.B)
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
qt422016.ReleaseByteBuffer(qb422016)
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
return qs422016
//line views/mutators.qtpl:20
//line views/mutators.qtpl:24
}
//line views/mutators.qtpl:22
//line views/mutators.qtpl:26
func StreamPreviewHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) {
//line views/mutators.qtpl:22
//line views/mutators.qtpl:26
qw422016.N().S(`
`)
//line views/mutators.qtpl:23
//line views/mutators.qtpl:27
qw422016.N().S(NavHTML(rq, hyphaName, "edit"))
//line views/mutators.qtpl:23
//line views/mutators.qtpl:27
qw422016.N().S(`
<div class="layout">
<main class="main-width edit edit_with-preview">
<h1>Edit `)
//line views/mutators.qtpl:26
//line views/mutators.qtpl:30
qw422016.E().S(util.BeautifulName(hyphaName))
//line views/mutators.qtpl:26
//line views/mutators.qtpl:30
qw422016.N().S(` (preview)</h1>
`)
//line views/mutators.qtpl:27
//line views/mutators.qtpl:31
qw422016.N().S(warning)
//line views/mutators.qtpl:27
//line views/mutators.qtpl:31
qw422016.N().S(`
<form method="post" class="edit-form"
action="/upload-text/`)
//line views/mutators.qtpl:29
//line views/mutators.qtpl:33
qw422016.E().S(hyphaName)
//line views/mutators.qtpl:29
//line views/mutators.qtpl:33
qw422016.N().S(`">
<textarea name="text">`)
//line views/mutators.qtpl:30
//line views/mutators.qtpl:34
qw422016.E().S(textAreaFill)
//line views/mutators.qtpl:30
//line views/mutators.qtpl:34
qw422016.N().S(`</textarea>
<br/>
<input type="submit" name="action" value="Save" class="edit-form__save"/>
<input type="submit" name="action" value="Preview" class="edit-form__preview">
<a href="/page/`)
//line views/mutators.qtpl:34
//line views/mutators.qtpl:38
qw422016.E().S(hyphaName)
//line views/mutators.qtpl:34
//line views/mutators.qtpl:38
qw422016.N().S(`" class="edit-form__cancel">Cancel</a>
</form>
<p class="warning">Note that the hypha is not saved yet. You can preview the changes </p>
<article class="edit__preview">`)
//line views/mutators.qtpl:37
//line views/mutators.qtpl:41
qw422016.N().S(renderedPage)
//line views/mutators.qtpl:37
//line views/mutators.qtpl:41
qw422016.N().S(`</article>
</main>
</div>
`)
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
}
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
func WritePreviewHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) {
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
StreamPreviewHTML(qw422016, rq, hyphaName, textAreaFill, warning, renderedPage)
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
qt422016.ReleaseWriter(qw422016)
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
}
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) string {
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
qb422016 := qt422016.AcquireByteBuffer()
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
WritePreviewHTML(qb422016, rq, hyphaName, textAreaFill, warning, renderedPage)
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
qs422016 := string(qb422016.B)
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
qt422016.ReleaseByteBuffer(qb422016)
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
return qs422016
//line views/mutators.qtpl:40
//line views/mutators.qtpl:44
}

View File

@ -352,7 +352,7 @@ func StreamAboutHTML(qw422016 *qt422016.Writer) {
//line views/stuff.qtpl:98
qw422016.N().S(`</h1>
<ul>
<li><b><a href="https://mycorrhiza.lesarbr.es">MycorrhizaWiki</a> version:</b> β 0.13</li>
<li><b><a href="https://mycorrhiza.lesarbr.es">MycorrhizaWiki</a> version:</b> 1.1.0</li>
`)
//line views/stuff.qtpl:101
if user.AuthUsed {