1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 22:00:27 +00:00
mycorrhiza/misc/views.go
Timur Ismagilov 5bc704b404 Viewutil: Introduce CopyEnRuWith
Reducing boilerplate as usual
2022-05-18 19:58:24 +03:00

56 lines
1.4 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 misc
import (
"embed"
"github.com/bouncepaw/mycorrhiza/viewutil"
)
var (
//go:embed *html
fs embed.FS
chainList, chainTitleSearch viewutil.Chain
ruTranslation = `
{{define "list of hyphae"}}Список гиф{{end}}
{{define "search:"}}Поиск:{{end}}
{{define "search results for"}}Результаты поиска для «{{.}}»{{end}}
{{define "search desc"}}Название каждой из существующих гиф сопоставлено с запросом. Подходящие гифы приведены ниже.{{end}}
{{define "search no results"}}Ничего не найдено{{end}}
`
)
func initViews() {
chainList = viewutil.CopyEnRuWith(fs, "view_list.html", ruTranslation)
chainTitleSearch = viewutil.CopyEnRuWith(fs, "view_title_search.html", ruTranslation)
}
type listDatum struct {
Name string
Ext string
}
type listData struct {
*viewutil.BaseData
Entries []listDatum
}
func viewList(meta viewutil.Meta, entries []listDatum) {
viewutil.ExecutePage(meta, chainList, listData{
BaseData: &viewutil.BaseData{},
Entries: entries,
})
}
type titleSearchData struct {
*viewutil.BaseData
Query string
Results []string
}
func viewTitleSearch(meta viewutil.Meta, query string, results []string) {
viewutil.ExecutePage(meta, chainTitleSearch, titleSearchData{
BaseData: &viewutil.BaseData{},
Query: query,
Results: results,
})
}