mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-11 21:10:26 +00:00
Experiment № 2. Reimplement AboutHTML
Used a somewhat different approach this time. I'm feeling inexplicable anger. More experiments to come!
This commit is contained in:
parent
303ad8380f
commit
fc4fe4ea94
@ -90,14 +90,6 @@
|
||||
"revision_link": "Get Mycomarkup source of this revision",
|
||||
"revision_no_text": "This hypha had no text at this revision.",
|
||||
|
||||
"about_title": "About {{.name}}",
|
||||
"about_version": "{{.pre}}Mycorrhiza Wiki{{.post}} version:",
|
||||
"about_usercount": "User count:",
|
||||
"about_homepage": "Home page:",
|
||||
"about_admins": "Administrators:",
|
||||
"about_noauth": "This wiki does not use authorization",
|
||||
"about_hyphae": "See {{.link}} for information about hyphae on this wiki.",
|
||||
|
||||
"users_title": "User list",
|
||||
"users_heading": "List of users",
|
||||
"users_admins": "Admins",
|
||||
|
@ -93,14 +93,6 @@
|
||||
"revision_link": "Посмотреть код микоразметки для этой ревизии",
|
||||
"revision_no_text": "В этой ревизии гифы не было текста.",
|
||||
|
||||
"about_title": "О вики «{{.name}}»",
|
||||
"about_version": "Версия {{.pre}}Микоризы{{.post}}:",
|
||||
"about_usercount": "Число пользователей:",
|
||||
"about_homepage": "Домашняя гифа:",
|
||||
"about_admins": "Администраторы:",
|
||||
"about_noauth": "В этой вики нет авторизации",
|
||||
"about_hyphae": "См. {{.link}}, чтобы узнать о гифах в этой вики.",
|
||||
|
||||
"users_title": "Список пользователей",
|
||||
"users_heading": "Список пользователей",
|
||||
"users_admins": "Администраторы",
|
||||
|
100
views/about.go
Normal file
100
views/about.go
Normal file
@ -0,0 +1,100 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"github.com/bouncepaw/mycorrhiza/l18n"
|
||||
"github.com/bouncepaw/mycorrhiza/user"
|
||||
"log"
|
||||
"strings"
|
||||
"text/template" // sic!
|
||||
)
|
||||
|
||||
type l10nEntry struct {
|
||||
_en string
|
||||
_ru string
|
||||
}
|
||||
|
||||
func e() l10nEntry {
|
||||
return l10nEntry{}
|
||||
}
|
||||
|
||||
func (e l10nEntry) ru(v string) l10nEntry {
|
||||
e._ru = v
|
||||
return e
|
||||
}
|
||||
|
||||
func (e l10nEntry) en(v string) l10nEntry {
|
||||
e._en = v
|
||||
return e
|
||||
}
|
||||
|
||||
func (e l10nEntry) get(lang string) string {
|
||||
if lang == "ru" && e._ru != "" {
|
||||
return e._ru
|
||||
}
|
||||
return e._en
|
||||
}
|
||||
|
||||
const aboutTemplateString = `<div class="layout">
|
||||
<main class="main-width">
|
||||
<section>
|
||||
<h1>{{ printf (get .L.Title) .Cfg.WikiName }}</h1>
|
||||
<ul>
|
||||
<li><b>{{ get .L.Version }}</b> 1.8.2</li>
|
||||
{{ if .Cfg.UseAuth }}
|
||||
<li><b>{{ get .L.UserCount }}</b> {{ .UserCount }}</li>
|
||||
<li><b>{{ get .L.HomePage }}</b> <a href="/">{{ .Cfg.HomeHypha }}</a></li>
|
||||
<li><b>{{ get .L.Admins }}</b> {{$cfg := .Cfg}}{{ range $i, $username := .Admins }}
|
||||
{{ if gt $i 0 }}<span aria-hidden="true">, </span>{{ end }}
|
||||
<a href="/hypha/{{ $cfg.UserHypha }}/{{ $username }}">{{ $username }}</a>
|
||||
{{ end }}</li>
|
||||
{{ else }}
|
||||
<li>{{ get .L.NoAuth }}</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
<p>{{ get .L.AboutHyphae }}</p>
|
||||
</section>
|
||||
</main>
|
||||
</div>`
|
||||
|
||||
var aboutData = struct {
|
||||
L map[string]l10nEntry
|
||||
Cfg map[string]interface{}
|
||||
Admins []string
|
||||
UserCount uint64
|
||||
}{
|
||||
L: map[string]l10nEntry{
|
||||
"Title": e().en("About %s").ru("О %s"),
|
||||
"Version": e().en("<a href=\"https://mycorrhiza.wiki\">Mycorrhiza Wiki</a> version:").ru("Версия <a href=\"https://mycorrhiza.wiki\">Микоризы</a>:"),
|
||||
"UserCount": e().en("User count:").ru("Число пользователей:"),
|
||||
"HomePage": e().en("Home page:").ru("Домашняя гифа:"),
|
||||
"Admins": e().en("Administrators:").ru("Администраторы:"),
|
||||
"NoAuth": e().en("This wiki does not use authorization").ru("На этой вики не используется авторизация"),
|
||||
"AboutHyphae": e().en("See <a href=\"/list\">/list</a> for information about hyphae on this wiki.").ru("См. <a href=\"/list\">/list</a>, чтобы узнать о гифах в этой вики."),
|
||||
},
|
||||
}
|
||||
|
||||
func AboutHTML(lc *l18n.Localizer) string {
|
||||
get := func(e l10nEntry) string {
|
||||
return e.get(lc.Locale)
|
||||
}
|
||||
temp, err := template.New("about wiki").Funcs(template.FuncMap{"get": get}).Parse(aboutTemplateString)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
data := aboutData
|
||||
data.Admins = user.ListUsersWithGroup("admin")
|
||||
data.UserCount = user.Count()
|
||||
data.Cfg = map[string]interface{}{
|
||||
"UseAuth": cfg.UseAuth,
|
||||
"WikiName": cfg.WikiName,
|
||||
"HomeHypha": cfg.HomeHypha,
|
||||
"UserHypha": cfg.UserHypha,
|
||||
}
|
||||
var out strings.Builder
|
||||
err = temp.Execute(&out, data)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
return out.String()
|
||||
}
|
@ -244,30 +244,6 @@ sort.Strings(editors)
|
||||
</div>
|
||||
{% endfunc %}
|
||||
|
||||
{% func AboutHTML(lc *l18n.Localizer) %}
|
||||
<div class="layout">
|
||||
<main class="main-width">
|
||||
<section>
|
||||
<h1>{%s lc.Get("ui.about_title", &l18n.Replacements{"name": cfg.WikiName}) %}</h1>
|
||||
<ul>
|
||||
<li><b>{%s= lc.Get("ui.about_version", &l18n.Replacements{"pre": "<a href=\"https://mycorrhiza.wiki\">", "post": "</a>"}) %}</b> 1.8.2</li>
|
||||
{%- if cfg.UseAuth -%}
|
||||
<li><b>{%s lc.Get("ui.about_usercount") %}</b> {%dul user.Count() %}</li>
|
||||
<li><b>{%s lc.Get("ui.about_homepage") %}</b> <a href="/">{%s cfg.HomeHypha %}</a></li>
|
||||
<li><b>{%s lc.Get("ui.about_admins") %}</b> {%- for i, username := range user.ListUsersWithGroup("admin") -%}
|
||||
{%- if i > 0 -%}<span aria-hidden="true">, </span>
|
||||
{%- endif -%}
|
||||
<a href="/hypha/{%s cfg.UserHypha %}/{%s username %}">{%s username %}</a>{%- endfor -%}</li>
|
||||
{%- else -%}
|
||||
<li>{%s lc.Get("ui.about_noauth") %}</li>
|
||||
{%- endif -%}
|
||||
</ul>
|
||||
<p>{%s= lc.Get("ui.about_hyphae", &l18n.Replacements{"link": "<a href=\"/list\">/list</a>"}) %}</p>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
{% endfunc %}
|
||||
|
||||
{% func CommonScripts() %}
|
||||
{% for _, scriptPath := range cfg.CommonScripts %}
|
||||
<script src="{%s scriptPath %}"></script>
|
||||
|
@ -908,174 +908,50 @@ func HyphaListHTML(lc *l18n.Localizer) string {
|
||||
}
|
||||
|
||||
//line views/stuff.qtpl:247
|
||||
func StreamAboutHTML(qw422016 *qt422016.Writer, lc *l18n.Localizer) {
|
||||
func StreamCommonScripts(qw422016 *qt422016.Writer) {
|
||||
//line views/stuff.qtpl:247
|
||||
qw422016.N().S(`
|
||||
<div class="layout">
|
||||
<main class="main-width">
|
||||
<section>
|
||||
<h1>`)
|
||||
//line views/stuff.qtpl:251
|
||||
qw422016.E().S(lc.Get("ui.about_title", &l18n.Replacements{"name": cfg.WikiName}))
|
||||
//line views/stuff.qtpl:251
|
||||
qw422016.N().S(`</h1>
|
||||
<ul>
|
||||
<li><b>`)
|
||||
//line views/stuff.qtpl:253
|
||||
qw422016.N().S(lc.Get("ui.about_version", &l18n.Replacements{"pre": "<a href=\"https://mycorrhiza.wiki\">", "post": "</a>"}))
|
||||
//line views/stuff.qtpl:253
|
||||
qw422016.N().S(`</b> 1.8.2</li>
|
||||
`)
|
||||
//line views/stuff.qtpl:254
|
||||
if cfg.UseAuth {
|
||||
//line views/stuff.qtpl:254
|
||||
qw422016.N().S(` <li><b>`)
|
||||
//line views/stuff.qtpl:255
|
||||
qw422016.E().S(lc.Get("ui.about_usercount"))
|
||||
//line views/stuff.qtpl:255
|
||||
qw422016.N().S(`</b> `)
|
||||
//line views/stuff.qtpl:255
|
||||
qw422016.N().DUL(user.Count())
|
||||
//line views/stuff.qtpl:255
|
||||
qw422016.N().S(`</li>
|
||||
<li><b>`)
|
||||
//line views/stuff.qtpl:256
|
||||
qw422016.E().S(lc.Get("ui.about_homepage"))
|
||||
//line views/stuff.qtpl:256
|
||||
qw422016.N().S(`</b> <a href="/">`)
|
||||
//line views/stuff.qtpl:256
|
||||
qw422016.E().S(cfg.HomeHypha)
|
||||
//line views/stuff.qtpl:256
|
||||
qw422016.N().S(`</a></li>
|
||||
<li><b>`)
|
||||
//line views/stuff.qtpl:257
|
||||
qw422016.E().S(lc.Get("ui.about_admins"))
|
||||
//line views/stuff.qtpl:257
|
||||
qw422016.N().S(`</b>`)
|
||||
//line views/stuff.qtpl:257
|
||||
for i, username := range user.ListUsersWithGroup("admin") {
|
||||
//line views/stuff.qtpl:258
|
||||
if i > 0 {
|
||||
//line views/stuff.qtpl:258
|
||||
qw422016.N().S(`<span aria-hidden="true">, </span>
|
||||
`)
|
||||
//line views/stuff.qtpl:259
|
||||
}
|
||||
//line views/stuff.qtpl:259
|
||||
qw422016.N().S(` <a href="/hypha/`)
|
||||
//line views/stuff.qtpl:260
|
||||
qw422016.E().S(cfg.UserHypha)
|
||||
//line views/stuff.qtpl:260
|
||||
qw422016.N().S(`/`)
|
||||
//line views/stuff.qtpl:260
|
||||
qw422016.E().S(username)
|
||||
//line views/stuff.qtpl:260
|
||||
qw422016.N().S(`">`)
|
||||
//line views/stuff.qtpl:260
|
||||
qw422016.E().S(username)
|
||||
//line views/stuff.qtpl:260
|
||||
qw422016.N().S(`</a>`)
|
||||
//line views/stuff.qtpl:260
|
||||
}
|
||||
//line views/stuff.qtpl:260
|
||||
qw422016.N().S(`</li>
|
||||
`)
|
||||
//line views/stuff.qtpl:261
|
||||
} else {
|
||||
//line views/stuff.qtpl:261
|
||||
qw422016.N().S(` <li>`)
|
||||
//line views/stuff.qtpl:262
|
||||
qw422016.E().S(lc.Get("ui.about_noauth"))
|
||||
//line views/stuff.qtpl:262
|
||||
qw422016.N().S(`</li>
|
||||
`)
|
||||
//line views/stuff.qtpl:263
|
||||
}
|
||||
//line views/stuff.qtpl:263
|
||||
qw422016.N().S(` </ul>
|
||||
<p>`)
|
||||
//line views/stuff.qtpl:265
|
||||
qw422016.N().S(lc.Get("ui.about_hyphae", &l18n.Replacements{"link": "<a href=\"/list\">/list</a>"}))
|
||||
//line views/stuff.qtpl:265
|
||||
qw422016.N().S(`</p>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
`)
|
||||
//line views/stuff.qtpl:269
|
||||
}
|
||||
|
||||
//line views/stuff.qtpl:269
|
||||
func WriteAboutHTML(qq422016 qtio422016.Writer, lc *l18n.Localizer) {
|
||||
//line views/stuff.qtpl:269
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line views/stuff.qtpl:269
|
||||
StreamAboutHTML(qw422016, lc)
|
||||
//line views/stuff.qtpl:269
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line views/stuff.qtpl:269
|
||||
}
|
||||
|
||||
//line views/stuff.qtpl:269
|
||||
func AboutHTML(lc *l18n.Localizer) string {
|
||||
//line views/stuff.qtpl:269
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line views/stuff.qtpl:269
|
||||
WriteAboutHTML(qb422016, lc)
|
||||
//line views/stuff.qtpl:269
|
||||
qs422016 := string(qb422016.B)
|
||||
//line views/stuff.qtpl:269
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line views/stuff.qtpl:269
|
||||
return qs422016
|
||||
//line views/stuff.qtpl:269
|
||||
}
|
||||
|
||||
//line views/stuff.qtpl:271
|
||||
func StreamCommonScripts(qw422016 *qt422016.Writer) {
|
||||
//line views/stuff.qtpl:271
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line views/stuff.qtpl:272
|
||||
//line views/stuff.qtpl:248
|
||||
for _, scriptPath := range cfg.CommonScripts {
|
||||
//line views/stuff.qtpl:272
|
||||
//line views/stuff.qtpl:248
|
||||
qw422016.N().S(`
|
||||
<script src="`)
|
||||
//line views/stuff.qtpl:273
|
||||
//line views/stuff.qtpl:249
|
||||
qw422016.E().S(scriptPath)
|
||||
//line views/stuff.qtpl:273
|
||||
//line views/stuff.qtpl:249
|
||||
qw422016.N().S(`"></script>
|
||||
`)
|
||||
//line views/stuff.qtpl:274
|
||||
//line views/stuff.qtpl:250
|
||||
}
|
||||
//line views/stuff.qtpl:274
|
||||
//line views/stuff.qtpl:250
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
}
|
||||
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
func WriteCommonScripts(qq422016 qtio422016.Writer) {
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
StreamCommonScripts(qw422016)
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
}
|
||||
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
func CommonScripts() string {
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
WriteCommonScripts(qb422016)
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
qs422016 := string(qb422016.B)
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
return qs422016
|
||||
//line views/stuff.qtpl:275
|
||||
//line views/stuff.qtpl:251
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user