Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/router/template.go
sfan5 1961db72a1 Revert "Added Profile page"
This reverts commit 5860cf1d79.
2017-05-08 22:50:25 +02:00

73 lignes
1,7 Kio
Go

package router
import (
"html/template"
"path/filepath"
)
var TemplateDir = "templates"
var homeTemplate, searchTemplate, faqTemplate, uploadTemplate, viewTemplate, viewRegisterTemplate, viewLoginTemplate, viewRegisterSuccessTemplate, viewVerifySuccessTemplate *template.Template
type templateLoader struct {
templ **template.Template
file string
name string
}
// ReloadTemplates reloads templates on runtime
func ReloadTemplates() {
templs := []templateLoader{
templateLoader{
templ: &homeTemplate,
name: "home",
file: "home.html",
},
templateLoader{
templ: &searchTemplate,
name: "search",
file: "home.html",
},
templateLoader{
templ: &uploadTemplate,
name: "upload",
file: "upload.html",
},
templateLoader{
templ: &faqTemplate,
name: "FAQ",
file: "FAQ.html",
},
templateLoader{
templ: &viewTemplate,
name: "view",
file: "view.html",
},
templateLoader{
templ: &viewRegisterTemplate,
name: "user_register",
file: "user/register.html",
},
templateLoader{
templ: &viewRegisterSuccessTemplate,
name: "user_register_success",
file: "user/signup_success.html",
},
templateLoader{
templ: &viewVerifySuccessTemplate,
name: "user_verify_success",
file: "user/verify_success.html",
},
templateLoader{
templ: &viewLoginTemplate,
name: "user_login",
file: "user/login.html",
},
}
for _, templ := range templs {
t := template.Must(template.New(templ.name).Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "index.html"), filepath.Join(TemplateDir, templ.file)))
t = template.Must(t.ParseGlob(filepath.Join("templates", "_*.html")))
*templ.templ = t
}
}