diff --git a/l18n/en/ui.json b/l18n/en/ui.json index 1f199d3..1c10548 100644 --- a/l18n/en/ui.json +++ b/l18n/en/ui.json @@ -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", diff --git a/l18n/ru/ui.json b/l18n/ru/ui.json index 015b2bc..1f539a7 100644 --- a/l18n/ru/ui.json +++ b/l18n/ru/ui.json @@ -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": "Администраторы", diff --git a/views/about.go b/views/about.go new file mode 100644 index 0000000..b07d3d7 --- /dev/null +++ b/views/about.go @@ -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 = `
+
+
+

{{ printf (get .L.Title) .Cfg.WikiName }}

+
    +
  • {{ get .L.Version }} 1.8.2
  • + {{ if .Cfg.UseAuth }} +
  • {{ get .L.UserCount }} {{ .UserCount }}
  • +
  • {{ get .L.HomePage }} {{ .Cfg.HomeHypha }}
  • +
  • {{ get .L.Admins }} {{$cfg := .Cfg}}{{ range $i, $username := .Admins }} + {{ if gt $i 0 }}{{ end }} + {{ $username }} + {{ end }}
  • + {{ else }} +
  • {{ get .L.NoAuth }}
  • + {{ end }} +
+

{{ get .L.AboutHyphae }}

+
+
+
` + +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("Mycorrhiza Wiki version:").ru("Версия Микоризы:"), + "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 /list for information about hyphae on this wiki.").ru("См. /list, чтобы узнать о гифах в этой вики."), + }, +} + +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() +} diff --git a/views/stuff.qtpl b/views/stuff.qtpl index a42fc4e..70a599b 100644 --- a/views/stuff.qtpl +++ b/views/stuff.qtpl @@ -244,30 +244,6 @@ sort.Strings(editors) {% endfunc %} -{% func AboutHTML(lc *l18n.Localizer) %} -
-
-
-

{%s lc.Get("ui.about_title", &l18n.Replacements{"name": cfg.WikiName}) %}

-
    -
  • {%s= lc.Get("ui.about_version", &l18n.Replacements{"pre": "", "post": ""}) %} 1.8.2
  • - {%- if cfg.UseAuth -%} -
  • {%s lc.Get("ui.about_usercount") %} {%dul user.Count() %}
  • -
  • {%s lc.Get("ui.about_homepage") %} {%s cfg.HomeHypha %}
  • -
  • {%s lc.Get("ui.about_admins") %} {%- for i, username := range user.ListUsersWithGroup("admin") -%} - {%- if i > 0 -%} - {%- endif -%} - {%s username %}{%- endfor -%}
  • - {%- else -%} -
  • {%s lc.Get("ui.about_noauth") %}
  • - {%- endif -%} -
-

{%s= lc.Get("ui.about_hyphae", &l18n.Replacements{"link": "/list"}) %}

-
-
-
-{% endfunc %} - {% func CommonScripts() %} {% for _, scriptPath := range cfg.CommonScripts %} diff --git a/views/stuff.qtpl.go b/views/stuff.qtpl.go index 47c96cf..8d2f74a 100644 --- a/views/stuff.qtpl.go +++ b/views/stuff.qtpl.go @@ -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(` -
-
-
-

`) -//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(`

-
    -
  • `) -//line views/stuff.qtpl:253 - qw422016.N().S(lc.Get("ui.about_version", &l18n.Replacements{"pre": "", "post": ""})) -//line views/stuff.qtpl:253 - qw422016.N().S(` 1.8.2
  • `) -//line views/stuff.qtpl:254 - if cfg.UseAuth { -//line views/stuff.qtpl:254 - qw422016.N().S(`
  • `) -//line views/stuff.qtpl:255 - qw422016.E().S(lc.Get("ui.about_usercount")) -//line views/stuff.qtpl:255 - qw422016.N().S(` `) -//line views/stuff.qtpl:255 - qw422016.N().DUL(user.Count()) -//line views/stuff.qtpl:255 - qw422016.N().S(`
  • -
  • `) -//line views/stuff.qtpl:256 - qw422016.E().S(lc.Get("ui.about_homepage")) -//line views/stuff.qtpl:256 - qw422016.N().S(` `) -//line views/stuff.qtpl:256 - qw422016.E().S(cfg.HomeHypha) -//line views/stuff.qtpl:256 - qw422016.N().S(`
  • -
  • `) -//line views/stuff.qtpl:257 - qw422016.E().S(lc.Get("ui.about_admins")) -//line views/stuff.qtpl:257 - qw422016.N().S(``) -//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(` -`) -//line views/stuff.qtpl:259 - } -//line views/stuff.qtpl:259 - 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 - } -//line views/stuff.qtpl:260 - qw422016.N().S(`
  • -`) -//line views/stuff.qtpl:261 - } else { -//line views/stuff.qtpl:261 - qw422016.N().S(`
  • `) -//line views/stuff.qtpl:262 - qw422016.E().S(lc.Get("ui.about_noauth")) -//line views/stuff.qtpl:262 - qw422016.N().S(`
  • -`) -//line views/stuff.qtpl:263 - } -//line views/stuff.qtpl:263 - qw422016.N().S(`
-

`) -//line views/stuff.qtpl:265 - qw422016.N().S(lc.Get("ui.about_hyphae", &l18n.Replacements{"link": "/list"})) -//line views/stuff.qtpl:265 - qw422016.N().S(`

-
-
-
-`) -//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(` `) -//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 }