1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00
mycorrhiza/views/admin.go
2022-03-29 23:59:36 +03:00

76 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package views
import (
"github.com/bouncepaw/mycorrhiza/util"
"github.com/bouncepaw/mycorrhiza/viewutil"
"html/template"
"io"
"log"
"strings"
)
const adminTranslationRu = `
{{define "panel title"}}Панель админстратора{{end}}
{{define "panel safe section title"}}Безопасная секция{{end}}
{{define "panel link about"}}Об этой вики{{end}}
{{define "panel update header"}}Обновить ссылки в верхней панели{{end}}
{{define "panel link user list"}}Список пользователей{{end}}
{{define "panel users"}}Управление пользователями{{end}}
{{define "panel unsafe section title"}}Опасная секция{{end}}
{{define "panel shutdown"}}Выключить вики{{end}}
{{define "panel reindex hyphae"}}Переиндексировать гифы{{end}}
`
var (
adminTemplatesEn *template.Template
adminTemplatesRu *template.Template
)
func localizedAdminTemplates(meta viewutil.Meta) *template.Template {
if meta.Lc.Locale == "ru" {
return adminTemplatesRu
}
return adminTemplatesEn
}
func templateAsString(temp *template.Template, name string, datum ...interface{}) string {
var buf strings.Builder
var err error
if len(datum) == 1 {
err = temp.ExecuteTemplate(&buf, name, datum[0])
} else {
err = temp.ExecuteTemplate(&buf, name, nil)
}
if err != nil {
log.Println(err)
return ""
}
return buf.String()
}
func init() {
adminTemplatesEn = template.Must(
template.
New("admin").
Funcs(template.FuncMap{
"beautifulName": util.BeautifulName,
}).
ParseFS(fs, "admin.html"))
adminTemplatesRu = template.Must(
template.Must(adminTemplatesEn.Clone()).Parse(adminTranslationRu))
}
func AdminPanel(meta viewutil.Meta) {
var buf strings.Builder
err := localizedAdminTemplates(meta).ExecuteTemplate(&buf, "panel", nil)
if err != nil {
log.Println(err)
}
_, err = io.WriteString(meta.W, Base(
templateAsString(localizedAdminTemplates(meta), "panel title"),
buf.String(),
meta.Lc,
meta.U,
))
}