2017-05-07 13:51:33 +02:00
package router
import (
"html/template"
"path/filepath"
)
var TemplateDir = "templates"
2017-05-10 17:37:49 +02:00
var homeTemplate , searchTemplate , faqTemplate , uploadTemplate , viewTemplate , viewRegisterTemplate , viewLoginTemplate , viewRegisterSuccessTemplate , viewVerifySuccessTemplate , viewProfileTemplate , viewProfileEditTemplate , viewUserDeleteTemplate , notFoundTemplate * template . Template
2017-05-07 13:51:33 +02:00
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" ,
} ,
2017-05-07 14:53:01 +02:00
templateLoader {
templ : & viewRegisterTemplate ,
name : "user_register" ,
file : "user/register.html" ,
} ,
templateLoader {
templ : & viewRegisterSuccessTemplate ,
name : "user_register_success" ,
file : "user/signup_success.html" ,
} ,
2017-05-07 22:00:45 +02:00
templateLoader {
templ : & viewVerifySuccessTemplate ,
name : "user_verify_success" ,
file : "user/verify_success.html" ,
} ,
2017-05-07 14:53:01 +02:00
templateLoader {
templ : & viewLoginTemplate ,
name : "user_login" ,
file : "user/login.html" ,
} ,
2017-05-09 03:36:48 +02:00
templateLoader {
templ : & viewProfileTemplate ,
name : "user_profile" ,
file : "user/profile.html" ,
} ,
2017-05-09 17:47:06 +02:00
templateLoader {
templ : & viewProfileEditTemplate ,
name : "user_profile" ,
file : "user/profile_edit.html" ,
} ,
templateLoader {
templ : & viewUserDeleteTemplate ,
name : "user_delete" ,
file : "user/delete_success.html" ,
} ,
2017-05-09 04:12:32 +02:00
templateLoader {
templ : & notFoundTemplate ,
name : "404" ,
file : "404.html" ,
} ,
2017-05-07 13:51:33 +02:00
}
for _ , templ := range templs {
t := template . Must ( template . New ( templ . name ) . Funcs ( FuncMap ) . ParseFiles ( filepath . Join ( TemplateDir , "index.html" ) , filepath . Join ( TemplateDir , templ . file ) ) )
2017-05-11 01:15:36 +02:00
t = template . Must ( t . ParseGlob ( filepath . Join ( TemplateDir , "_*.html" ) ) )
2017-05-07 13:51:33 +02:00
* templ . templ = t
}
}