From dc7652a13718408e4f2de34aef5459e003e0ded8 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 13 Jun 2022 20:02:12 +0400 Subject: [PATCH] Removed code for old template compiling. Added go:generate commands to generate template functions. --- web/web.go | 63 ++++-------------------------------------------------- 1 file changed, 4 insertions(+), 59 deletions(-) diff --git a/web/web.go b/web/web.go index 9ba9c01..db726fe 100644 --- a/web/web.go +++ b/web/web.go @@ -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) - } -}