1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Migrate to quicktemplates

This commit is contained in:
bouncepaw 2020-08-31 22:52:26 +05:00
parent aeee451044
commit 41551fd63b
15 changed files with 676 additions and 146 deletions

View File

@ -2,6 +2,7 @@ run: build
./mycorrhiza metarrhiza ./mycorrhiza metarrhiza
build: build:
go generate
go build . go build .
test: test:

2
go.mod
View File

@ -1,3 +1,5 @@
module github.com/bouncepaw/mycorrhiza module github.com/bouncepaw/mycorrhiza
go 1.14 go 1.14
require github.com/valyala/quicktemplate v1.6.2

15
go.sum
View File

@ -0,0 +1,15 @@
github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.15.1/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
github.com/valyala/quicktemplate v1.6.2 h1:k0vgK7zlmFzqAoIBIOrhrfmZ6JoTGJlLRPLbkPGr2/M=
github.com/valyala/quicktemplate v1.6.2/go.mod h1:mtEJpQtUiBV0SHhMX6RtiJtqxncgrfmjcUy5T68X8TM=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@ -48,8 +48,7 @@ func (rev *Revision) AsHtmlTableRow(hyphaName string) string {
<td><time>%s</time></td> <td><time>%s</time></td>
<td><a href="/rev/%s/%s">%s</a></td> <td><a href="/rev/%s/%s">%s</a></td>
<td>%s</td> <td>%s</td>
<td>%s</td> </tr>`, rev.Time.Format(time.RFC822), rev.Hash, hyphaName, rev.Hash, rev.Message)
</tr>`, rev.Time.Format(time.RFC822), rev.Hash, hyphaName, rev.Hash, rev.Username, rev.Message)
} }
// See how the file with `filepath` looked at commit with `hash`. // See how the file with `filepath` looked at commit with `hash`.

View File

@ -9,6 +9,8 @@ import (
"path/filepath" "path/filepath"
"github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/history"
"github.com/bouncepaw/mycorrhiza/templates"
"github.com/bouncepaw/mycorrhiza/util"
) )
func init() { func init() {
@ -38,24 +40,7 @@ func handlerEdit(w http.ResponseWriter, rq *http.Request) {
} else { } else {
warning = `<p>You are creating a new hypha.</p>` warning = `<p>You are creating a new hypha.</p>`
} }
form := fmt.Sprintf(` util.HTTP200Page(w, base("Edit"+hyphaName, templates.EditHTML(hyphaName, textAreaFill, warning)))
<main>
<h1>Edit %[1]s</h1>
%[3]s
<form method="post" class="upload-text-form"
action="/upload-text/%[1]s">
<textarea name="text">%[2]s</textarea>
<br/>
<input type="submit"/>
<a href="/page/%[1]s">Cancel</a>
</form>
</main>
`, hyphaName, textAreaFill, warning)
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(base(
"Edit "+hyphaName, form)))
} }
// handlerUploadText uploads a new text part for the hypha. // handlerUploadText uploads a new text part for the hypha.

View File

@ -11,7 +11,9 @@ import (
"github.com/bouncepaw/mycorrhiza/gemtext" "github.com/bouncepaw/mycorrhiza/gemtext"
"github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/history"
"github.com/bouncepaw/mycorrhiza/templates"
"github.com/bouncepaw/mycorrhiza/tree" "github.com/bouncepaw/mycorrhiza/tree"
"github.com/bouncepaw/mycorrhiza/util"
) )
func init() { func init() {
@ -36,35 +38,16 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) {
if err == nil { if err == nil {
contents = gemtext.ToHtml(hyphaName, textContents) contents = gemtext.ToHtml(hyphaName, textContents)
} }
form := fmt.Sprintf(` page := templates.RevisionHTML(
<main> hyphaName,
<nav>
<ul>
<li><a href="/page/%[1]s">Hypha</a></li>
<li><a href="/edit/%[1]s">Edit</a></li>
<li><a href="/text/%[1]s">Raw text</a></li>
<li><a href="/history/%[1]s">History</a></li>
<li><b>%[5]s</b></li>
</ul>
</nav>
<article>
<p>Please note that viewing binary parts of hyphae is not supported in history for now.</p>
%[2]s
%[3]s
</article>
<hr/>
<aside>
%[4]s
</aside>
</main>
`, hyphaName,
naviTitle(hyphaName), naviTitle(hyphaName),
contents, contents,
tree.TreeAsHtml(hyphaName, IterateHyphaNamesWith), tree.TreeAsHtml(hyphaName, IterateHyphaNamesWith),
revHash) revHash,
)
w.Header().Set("Content-Type", "text/html;charset=utf-8") w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte(base(hyphaName, form))) w.Write([]byte(base(hyphaName, page)))
} }
// handlerHistory lists all revisions of a hypha // handlerHistory lists all revisions of a hypha
@ -82,33 +65,8 @@ func handlerHistory(w http.ResponseWriter, rq *http.Request) {
log.Println(revs) log.Println(revs)
} }
table := fmt.Sprintf(` util.HTTP200Page(w,
<main> base(hyphaName, templates.HistoryHTML(hyphaName, tbody)))
<nav>
<ul>
<li><a href="/page/%[1]s">Hypha</a></li>
<li><a href="/edit/%[1]s">Edit</a></li>
<li><a href="/text/%[1]s">Raw text</a></li>
<li><b>History</b></li>
</ul>
</nav>
<table>
<thead>
<tr>
<th>Time</th>
<th>Hash</th>
<th>Username</th>
<th>Message</th>
</tr>
</thead>
<tbody>
%[2]s
</tbody>
</table>
</main>`, hyphaName, tbody)
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(base(hyphaName, table)))
} }
// handlerText serves raw source text of the hypha. // handlerText serves raw source text of the hypha.
@ -138,8 +96,8 @@ func handlerPage(w http.ResponseWriter, rq *http.Request) {
log.Println(rq.URL) log.Println(rq.URL)
var ( var (
hyphaName = HyphaNameFromRq(rq, "page") hyphaName = HyphaNameFromRq(rq, "page")
contents = fmt.Sprintf(`<p>This hypha has no text. Why not <a href="/edit/%s">create it</a>?</p>`, hyphaName)
data, hyphaExists = HyphaStorage[hyphaName] data, hyphaExists = HyphaStorage[hyphaName]
contents string
) )
if hyphaExists { if hyphaExists {
fileContentsT, errT := ioutil.ReadFile(data.textPath) fileContentsT, errT := ioutil.ReadFile(data.textPath)
@ -151,38 +109,8 @@ func handlerPage(w http.ResponseWriter, rq *http.Request) {
contents = binaryHtmlBlock(hyphaName, data) + contents contents = binaryHtmlBlock(hyphaName, data) + contents
} }
} }
form := fmt.Sprintf(` util.HTTP200Page(w, base(hyphaName, templates.PageHTML(hyphaName,
<main>
<nav>
<ul>
<li><b>Hypha</b></li>
<li><a href="/edit/%[1]s">Edit</a></li>
<li><a href="/text/%[1]s">Raw text</a></li>
<li><a href="/history/%[1]s">History</a></li>
</ul>
</nav>
<article>
%[2]s
%[3]s
</article>
<hr/>
<form action="/upload-binary/%[1]s"
method="post" enctype="multipart/form-data">
<label for="upload-binary__input">Upload new binary part</label>
<br>
<input type="file" id="upload-binary__input" name="binary"/>
<input type="submit"/>
</form>
<hr/>
<aside>
%[4]s
</aside>
</main>
`, hyphaName,
naviTitle(hyphaName), naviTitle(hyphaName),
contents, contents,
tree.TreeAsHtml(hyphaName, IterateHyphaNamesWith)) tree.TreeAsHtml(hyphaName, IterateHyphaNamesWith))))
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(base(hyphaName, form)))
} }

51
main.go
View File

@ -1,3 +1,5 @@
//go:generate go get -u github.com/valyala/quicktemplate/qtc
//go:generate qtc -dir=templates
package main package main
import ( import (
@ -9,6 +11,7 @@ import (
"regexp" "regexp"
"github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/history"
"github.com/bouncepaw/mycorrhiza/templates"
"github.com/bouncepaw/mycorrhiza/util" "github.com/bouncepaw/mycorrhiza/util"
) )
@ -38,29 +41,13 @@ func HttpErr(w http.ResponseWriter, status int, name, title, errMsg string) {
errMsg, name))) errMsg, name)))
} }
// shorterPath is used by handlerList to display shorter path to the files. It simply strips WikiDir. It was moved to util package, this is an alias. TODO: demolish.
var shorterPath = util.ShorterPath
// Show all hyphae // Show all hyphae
func handlerList(w http.ResponseWriter, rq *http.Request) { func handlerList(w http.ResponseWriter, rq *http.Request) {
log.Println(rq.URL) log.Println(rq.URL)
w.Header().Set("Content-Type", "text/html;charset=utf-8") var tbody string
w.WriteHeader(http.StatusOK) // It should be moved to templates too, right?
buf := `
<h1>List of pages</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Text path</th>
<th>Text type</th>
<th>Binary path</th>
<th>Binary type</th>
</tr>
</thead>
<tbody>`
for name, data := range HyphaStorage { for name, data := range HyphaStorage {
buf += fmt.Sprintf(` tbody += fmt.Sprintf(`
<tr> <tr>
<td><a href="/page/%s">%s</a></td> <td><a href="/page/%s">%s</a></td>
<td>%s</td> <td>%s</td>
@ -69,33 +56,15 @@ func handlerList(w http.ResponseWriter, rq *http.Request) {
<td>%d</td> <td>%d</td>
</tr>`, </tr>`,
name, name, name, name,
shorterPath(data.textPath), data.textType, util.ShorterPath(data.textPath), data.textType,
shorterPath(data.binaryPath), data.binaryType, util.ShorterPath(data.binaryPath), data.binaryType,
) )
} }
buf += ` util.HTTP200Page(w, base("List of pages", templates.PageListHTML(tbody)))
</tbody>
</table>
`
w.Write([]byte(base("List of pages", buf)))
} }
// This part is present in all html documents. // This part is present in all html documents.
func base(title, body string) string { var base = templates.BaseHTML
return fmt.Sprintf(`
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/static/common.css">
<title>%s</title>
</head>
<body>
%s
</body>
</html>
`, title, body)
}
// Reindex all hyphae by checking the wiki storage directory anew. // Reindex all hyphae by checking the wiki storage directory anew.
func handlerReindex(w http.ResponseWriter, rq *http.Request) { func handlerReindex(w http.ResponseWriter, rq *http.Request) {

@ -1 +1 @@
Subproject commit 2a36350d4248610d7e09119d03a602414252abe4 Subproject commit ce6ffcdb83be6d5d5d15f0a8d240db5430889d45

View File

@ -0,0 +1,14 @@
{% func EditHTML(hyphaName, textAreaFill, warning string) %}
<main>
<h1>Edit {%s hyphaName %}</h1>
{%s= warning %}
<form method="post" class="upload-text-form"
action="/upload-text/{%s hyphaName %}">
<textarea name="text">{%s textAreaFill %}</textarea>
<br/>
<input type="submit"/>
<a href="/page/{%s hyphaName %}">Cancel</a>
</form>
</main>
{% endfunc %}

View File

@ -0,0 +1,83 @@
// Code generated by qtc from "http_mutators.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.
//line templates/http_mutators.qtpl:2
package templates
//line templates/http_mutators.qtpl:2
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line templates/http_mutators.qtpl:2
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line templates/http_mutators.qtpl:2
func StreamEditHTML(qw422016 *qt422016.Writer, hyphaName, textAreaFill, warning string) {
//line templates/http_mutators.qtpl:2
qw422016.N().S(`
<main>
<h1>Edit `)
//line templates/http_mutators.qtpl:4
qw422016.E().S(hyphaName)
//line templates/http_mutators.qtpl:4
qw422016.N().S(`</h1>
`)
//line templates/http_mutators.qtpl:5
qw422016.N().S(warning)
//line templates/http_mutators.qtpl:5
qw422016.N().S(`
<form method="post" class="upload-text-form"
action="/upload-text/`)
//line templates/http_mutators.qtpl:7
qw422016.E().S(hyphaName)
//line templates/http_mutators.qtpl:7
qw422016.N().S(`">
<textarea name="text">`)
//line templates/http_mutators.qtpl:8
qw422016.E().S(textAreaFill)
//line templates/http_mutators.qtpl:8
qw422016.N().S(`</textarea>
<br/>
<input type="submit"/>
<a href="/page/`)
//line templates/http_mutators.qtpl:11
qw422016.E().S(hyphaName)
//line templates/http_mutators.qtpl:11
qw422016.N().S(`">Cancel</a>
</form>
</main>
`)
//line templates/http_mutators.qtpl:14
}
//line templates/http_mutators.qtpl:14
func WriteEditHTML(qq422016 qtio422016.Writer, hyphaName, textAreaFill, warning string) {
//line templates/http_mutators.qtpl:14
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_mutators.qtpl:14
StreamEditHTML(qw422016, hyphaName, textAreaFill, warning)
//line templates/http_mutators.qtpl:14
qt422016.ReleaseWriter(qw422016)
//line templates/http_mutators.qtpl:14
}
//line templates/http_mutators.qtpl:14
func EditHTML(hyphaName, textAreaFill, warning string) string {
//line templates/http_mutators.qtpl:14
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_mutators.qtpl:14
WriteEditHTML(qb422016, hyphaName, textAreaFill, warning)
//line templates/http_mutators.qtpl:14
qs422016 := string(qb422016.B)
//line templates/http_mutators.qtpl:14
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_mutators.qtpl:14
return qs422016
//line templates/http_mutators.qtpl:14
}

View File

@ -0,0 +1,81 @@
{% func HistoryHTML(hyphaName, tbody string) %}
<main>
<nav>
<ul>
<li><a href="/page/{%s hyphaName %}">Hypha</a></li>
<li><a href="/edit/{%s hyphaName %}">Edit</a></li>
<li><a href="/text/{%s hyphaName %}">Raw text</a></li>
<li><b>History</b></li>
</ul>
</nav>
<table>
<thead>
<tr>
<th>Time</th>
<th>Hash</th>
<th>Message</th>
</tr>
</thead>
<tbody>
{%s= tbody %}
</tbody>
</table>
</main>
{% endfunc %}
{% func RevisionHTML(hyphaName, naviTitle, contents, tree, revHash string) %}
<main>
<nav>
<ul>
<li><a href="/page/{%s hyphaName %}">Hypha</a></li>
<li><a href="/edit/{%s hyphaName %}">Edit</a></li>
<li><a href="/text/{%s hyphaName %}">Raw text</a></li>
<li><a href="/history/{%s hyphaName %}">History</a></li>
<li><b>{%s revHash %}</b></li>
</ul>
</nav>
<article>
<p>Please note that viewing binary parts of hyphae is not supported in history for now.</p>
{%s= naviTitle %}
{%s= contents %}
</article>
<hr/>
<aside>
{%s= tree %}
</aside>
</main>
{% endfunc %}
If `contents` == "", a helpful message is shown instead.
{% func PageHTML(hyphaName, naviTitle, contents, tree string) %}
<main>
<nav>
<ul>
<li><b>Hypha</b></li>
<li><a href="/edit/{%s hyphaName %}">Edit</a></li>
<li><a href="/text/{%s hyphaName %}">Raw text</a></li>
<li><a href="/history/{%s hyphaName %}">History</a></li>
</ul>
</nav>
<article>
{%s= naviTitle %}
{% if contents == "" %}
<p>This hypha has no text. Why not <a href="/edit/{%s hyphaName %}">create it</a>?</p>
{% else %}
{%s= contents %}
{% endif %}
</article>
<hr/>
<form action="/upload-binary/{%s hyphaName %}"
method="post" enctype="multipart/form-data">
<label for="upload-binary__input">Upload new binary part</label>
<br>
<input type="file" id="upload-binary__input" name="binary"/>
<input type="submit"/>
</form>
<hr/>
<aside>
{%s= tree %}
</aside>
</main>
{% endfunc %}

View File

@ -0,0 +1,286 @@
// Code generated by qtc from "http_readers.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.
//line templates/http_readers.qtpl:1
package templates
//line templates/http_readers.qtpl:1
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line templates/http_readers.qtpl:1
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line templates/http_readers.qtpl:1
func StreamHistoryHTML(qw422016 *qt422016.Writer, hyphaName, tbody string) {
//line templates/http_readers.qtpl:1
qw422016.N().S(`
<main>
<nav>
<ul>
<li><a href="/page/`)
//line templates/http_readers.qtpl:5
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:5
qw422016.N().S(`">Hypha</a></li>
<li><a href="/edit/`)
//line templates/http_readers.qtpl:6
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:6
qw422016.N().S(`">Edit</a></li>
<li><a href="/text/`)
//line templates/http_readers.qtpl:7
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:7
qw422016.N().S(`">Raw text</a></li>
<li><b>History</b></li>
</ul>
</nav>
<table>
<thead>
<tr>
<th>Time</th>
<th>Hash</th>
<th>Message</th>
</tr>
</thead>
<tbody>
`)
//line templates/http_readers.qtpl:20
qw422016.N().S(tbody)
//line templates/http_readers.qtpl:20
qw422016.N().S(`
</tbody>
</table>
</main>
`)
//line templates/http_readers.qtpl:24
}
//line templates/http_readers.qtpl:24
func WriteHistoryHTML(qq422016 qtio422016.Writer, hyphaName, tbody string) {
//line templates/http_readers.qtpl:24
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_readers.qtpl:24
StreamHistoryHTML(qw422016, hyphaName, tbody)
//line templates/http_readers.qtpl:24
qt422016.ReleaseWriter(qw422016)
//line templates/http_readers.qtpl:24
}
//line templates/http_readers.qtpl:24
func HistoryHTML(hyphaName, tbody string) string {
//line templates/http_readers.qtpl:24
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_readers.qtpl:24
WriteHistoryHTML(qb422016, hyphaName, tbody)
//line templates/http_readers.qtpl:24
qs422016 := string(qb422016.B)
//line templates/http_readers.qtpl:24
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_readers.qtpl:24
return qs422016
//line templates/http_readers.qtpl:24
}
//line templates/http_readers.qtpl:26
func StreamRevisionHTML(qw422016 *qt422016.Writer, hyphaName, naviTitle, contents, tree, revHash string) {
//line templates/http_readers.qtpl:26
qw422016.N().S(`
<main>
<nav>
<ul>
<li><a href="/page/`)
//line templates/http_readers.qtpl:30
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:30
qw422016.N().S(`">Hypha</a></li>
<li><a href="/edit/`)
//line templates/http_readers.qtpl:31
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:31
qw422016.N().S(`">Edit</a></li>
<li><a href="/text/`)
//line templates/http_readers.qtpl:32
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:32
qw422016.N().S(`">Raw text</a></li>
<li><a href="/history/`)
//line templates/http_readers.qtpl:33
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:33
qw422016.N().S(`">History</a></li>
<li><b>`)
//line templates/http_readers.qtpl:34
qw422016.E().S(revHash)
//line templates/http_readers.qtpl:34
qw422016.N().S(`</b></li>
</ul>
</nav>
<article>
<p>Please note that viewing binary parts of hyphae is not supported in history for now.</p>
`)
//line templates/http_readers.qtpl:39
qw422016.N().S(naviTitle)
//line templates/http_readers.qtpl:39
qw422016.N().S(`
`)
//line templates/http_readers.qtpl:40
qw422016.N().S(contents)
//line templates/http_readers.qtpl:40
qw422016.N().S(`
</article>
<hr/>
<aside>
`)
//line templates/http_readers.qtpl:44
qw422016.N().S(tree)
//line templates/http_readers.qtpl:44
qw422016.N().S(`
</aside>
</main>
`)
//line templates/http_readers.qtpl:47
}
//line templates/http_readers.qtpl:47
func WriteRevisionHTML(qq422016 qtio422016.Writer, hyphaName, naviTitle, contents, tree, revHash string) {
//line templates/http_readers.qtpl:47
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_readers.qtpl:47
StreamRevisionHTML(qw422016, hyphaName, naviTitle, contents, tree, revHash)
//line templates/http_readers.qtpl:47
qt422016.ReleaseWriter(qw422016)
//line templates/http_readers.qtpl:47
}
//line templates/http_readers.qtpl:47
func RevisionHTML(hyphaName, naviTitle, contents, tree, revHash string) string {
//line templates/http_readers.qtpl:47
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_readers.qtpl:47
WriteRevisionHTML(qb422016, hyphaName, naviTitle, contents, tree, revHash)
//line templates/http_readers.qtpl:47
qs422016 := string(qb422016.B)
//line templates/http_readers.qtpl:47
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_readers.qtpl:47
return qs422016
//line templates/http_readers.qtpl:47
}
// If `contents` == "", a helpful message is shown instead.
//line templates/http_readers.qtpl:50
func StreamPageHTML(qw422016 *qt422016.Writer, hyphaName, naviTitle, contents, tree string) {
//line templates/http_readers.qtpl:50
qw422016.N().S(`
<main>
<nav>
<ul>
<li><b>Hypha</b></li>
<li><a href="/edit/`)
//line templates/http_readers.qtpl:55
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:55
qw422016.N().S(`">Edit</a></li>
<li><a href="/text/`)
//line templates/http_readers.qtpl:56
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:56
qw422016.N().S(`">Raw text</a></li>
<li><a href="/history/`)
//line templates/http_readers.qtpl:57
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:57
qw422016.N().S(`">History</a></li>
</ul>
</nav>
<article>
`)
//line templates/http_readers.qtpl:61
qw422016.N().S(naviTitle)
//line templates/http_readers.qtpl:61
qw422016.N().S(`
`)
//line templates/http_readers.qtpl:62
if contents == "" {
//line templates/http_readers.qtpl:62
qw422016.N().S(`
<p>This hypha has no text. Why not <a href="/edit/`)
//line templates/http_readers.qtpl:63
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:63
qw422016.N().S(`">create it</a>?</p>
`)
//line templates/http_readers.qtpl:64
} else {
//line templates/http_readers.qtpl:64
qw422016.N().S(`
`)
//line templates/http_readers.qtpl:65
qw422016.N().S(contents)
//line templates/http_readers.qtpl:65
qw422016.N().S(`
`)
//line templates/http_readers.qtpl:66
}
//line templates/http_readers.qtpl:66
qw422016.N().S(`
</article>
<hr/>
<form action="/upload-binary/`)
//line templates/http_readers.qtpl:69
qw422016.E().S(hyphaName)
//line templates/http_readers.qtpl:69
qw422016.N().S(`"
method="post" enctype="multipart/form-data">
<label for="upload-binary__input">Upload new binary part</label>
<br>
<input type="file" id="upload-binary__input" name="binary"/>
<input type="submit"/>
</form>
<hr/>
<aside>
`)
//line templates/http_readers.qtpl:78
qw422016.N().S(tree)
//line templates/http_readers.qtpl:78
qw422016.N().S(`
</aside>
</main>
`)
//line templates/http_readers.qtpl:81
}
//line templates/http_readers.qtpl:81
func WritePageHTML(qq422016 qtio422016.Writer, hyphaName, naviTitle, contents, tree string) {
//line templates/http_readers.qtpl:81
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_readers.qtpl:81
StreamPageHTML(qw422016, hyphaName, naviTitle, contents, tree)
//line templates/http_readers.qtpl:81
qt422016.ReleaseWriter(qw422016)
//line templates/http_readers.qtpl:81
}
//line templates/http_readers.qtpl:81
func PageHTML(hyphaName, naviTitle, contents, tree string) string {
//line templates/http_readers.qtpl:81
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_readers.qtpl:81
WritePageHTML(qb422016, hyphaName, naviTitle, contents, tree)
//line templates/http_readers.qtpl:81
qs422016 := string(qb422016.B)
//line templates/http_readers.qtpl:81
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_readers.qtpl:81
return qs422016
//line templates/http_readers.qtpl:81
}

33
templates/http_stuff.qtpl Normal file
View File

@ -0,0 +1,33 @@
{% func BaseHTML(title, body string) %}
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/static/common.css">
<title>{%s title %}</title>
</head>
<body>
{%s= body %}
</body>
</html>
{% endfunc %}
{% func PageListHTML(tbody string) %}
<main>
<h1>List of pages</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Text path</th>
<th>Text type</th>
<th>Binary path</th>
<th>Binary type</th>
</tr>
</thead>
<tbody>
{%s= tbody %}
</tbody>
</table>
</main>
{% endfunc %}

View File

@ -0,0 +1,126 @@
// Code generated by qtc from "http_stuff.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.
//line templates/http_stuff.qtpl:1
package templates
//line templates/http_stuff.qtpl:1
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line templates/http_stuff.qtpl:1
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line templates/http_stuff.qtpl:1
func StreamBaseHTML(qw422016 *qt422016.Writer, title, body string) {
//line templates/http_stuff.qtpl:1
qw422016.N().S(`
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/static/common.css">
<title>`)
//line templates/http_stuff.qtpl:7
qw422016.E().S(title)
//line templates/http_stuff.qtpl:7
qw422016.N().S(`</title>
</head>
<body>
`)
//line templates/http_stuff.qtpl:10
qw422016.N().S(body)
//line templates/http_stuff.qtpl:10
qw422016.N().S(`
</body>
</html>
`)
//line templates/http_stuff.qtpl:13
}
//line templates/http_stuff.qtpl:13
func WriteBaseHTML(qq422016 qtio422016.Writer, title, body string) {
//line templates/http_stuff.qtpl:13
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_stuff.qtpl:13
StreamBaseHTML(qw422016, title, body)
//line templates/http_stuff.qtpl:13
qt422016.ReleaseWriter(qw422016)
//line templates/http_stuff.qtpl:13
}
//line templates/http_stuff.qtpl:13
func BaseHTML(title, body string) string {
//line templates/http_stuff.qtpl:13
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_stuff.qtpl:13
WriteBaseHTML(qb422016, title, body)
//line templates/http_stuff.qtpl:13
qs422016 := string(qb422016.B)
//line templates/http_stuff.qtpl:13
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_stuff.qtpl:13
return qs422016
//line templates/http_stuff.qtpl:13
}
//line templates/http_stuff.qtpl:15
func StreamPageListHTML(qw422016 *qt422016.Writer, tbody string) {
//line templates/http_stuff.qtpl:15
qw422016.N().S(`
<main>
<h1>List of pages</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Text path</th>
<th>Text type</th>
<th>Binary path</th>
<th>Binary type</th>
</tr>
</thead>
<tbody>
`)
//line templates/http_stuff.qtpl:29
qw422016.N().S(tbody)
//line templates/http_stuff.qtpl:29
qw422016.N().S(`
</tbody>
</table>
</main>
`)
//line templates/http_stuff.qtpl:33
}
//line templates/http_stuff.qtpl:33
func WritePageListHTML(qq422016 qtio422016.Writer, tbody string) {
//line templates/http_stuff.qtpl:33
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_stuff.qtpl:33
StreamPageListHTML(qw422016, tbody)
//line templates/http_stuff.qtpl:33
qt422016.ReleaseWriter(qw422016)
//line templates/http_stuff.qtpl:33
}
//line templates/http_stuff.qtpl:33
func PageListHTML(tbody string) string {
//line templates/http_stuff.qtpl:33
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_stuff.qtpl:33
WritePageListHTML(qb422016, tbody)
//line templates/http_stuff.qtpl:33
qs422016 := string(qb422016.B)
//line templates/http_stuff.qtpl:33
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_stuff.qtpl:33
return qs422016
//line templates/http_stuff.qtpl:33
}

View File

@ -1,6 +1,7 @@
package util package util
import ( import (
"net/http"
"strings" "strings"
) )
@ -17,3 +18,10 @@ func ShorterPath(path string) string {
} }
return path return path
} }
// HTTP200Page wraps some frequently used things for successful 200 responses.
func HTTP200Page(w http.ResponseWriter, page string) {
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(page))
}