1
0

Removed code for old template compiling. Added go:generate commands to generate template functions.

This commit is contained in:
Alexander Andreev 2022-06-13 20:02:12 +04:00
parent 677aaa288a
commit dc7652a137
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -1,16 +1,15 @@
package web
import (
"dwelling-upload/pkg/logging"
"embed"
"html/template"
"io/fs"
"net/http"
"github.com/Joker/jade"
)
var compiledTemplates map[string]*template.Template
//go:generate $GOPATH/bin/jade -pkg=web -writer templates/index.jade
//go:generate $GOPATH/bin/jade -pkg=web -writer templates/nospace.jade
//go:generate $GOPATH/bin/jade -pkg=web -writer templates/uploaded.jade
//go:generate $GOPATH/bin/jade -pkg=web -writer templates/error404.jade
//go:embed assets
var assetsDir embed.FS
@ -23,57 +22,3 @@ func Assets() http.FileSystem {
func AssetsGetFile(path string) ([]byte, error) {
return assetsDir.ReadFile("assets/" + path)
}
//go:embed templates
var templatesDir embed.FS
func Template(name string) *template.Template {
return compiledTemplates[name]
}
func CompileTemplates(lErr *logging.Logger) {
compiledTemplates = make(map[string]*template.Template)
t, _ := fs.Sub(templatesDir, "templates")
templatesFS := http.FS(t)
indexStr, err := jade.ParseFileFromFileSystem("index.jade", templatesFS)
if err != nil {
lErr.Fatalln(err)
}
compiledTemplates["index"], err = template.New("index").Parse(indexStr)
if err != nil {
lErr.Fatalln(err)
}
uploadedStr, err := jade.ParseFileFromFileSystem("uploaded.jade", templatesFS)
if err != nil {
lErr.Fatalln(err)
}
compiledTemplates["uploaded"], err = template.New("uploaded").Parse(uploadedStr)
if err != nil {
lErr.Fatalln(err)
}
notfoundStr, err := jade.ParseFileFromFileSystem("404.jade", templatesFS)
if err != nil {
lErr.Fatalln(err)
}
compiledTemplates["404"], err = template.New("404").Parse(notfoundStr)
if err != nil {
lErr.Fatalln(err)
}
nospaceStr, err := jade.ParseFileFromFileSystem("nospace.jade", templatesFS)
if err != nil {
lErr.Fatalln(err)
}
compiledTemplates["nospace"], err = template.New("nospace").Parse(nospaceStr)
if err != nil {
lErr.Fatalln(err)
}
}