From b2447bc967df37b31282a97e32c581954bb8bcc9 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Thu, 17 Oct 2024 16:37:23 +0200 Subject: Move from html/template to templ --- templ/404.tpl | 10 ------- templ/base.tpl | 20 -------------- templ/categories.tpl | 9 ------- templ/content.tpl | 36 -------------------------- templ/form.tpl | 22 ---------------- templ/index.tpl | 3 --- templ/login.tpl | 10 ------- templ/navlinks.tpl | 8 ------ templ/recur.tpl | 9 ------- templ/template.go | 73 ---------------------------------------------------- 10 files changed, 200 deletions(-) delete mode 100644 templ/404.tpl delete mode 100644 templ/base.tpl delete mode 100644 templ/categories.tpl delete mode 100644 templ/content.tpl delete mode 100644 templ/form.tpl delete mode 100644 templ/index.tpl delete mode 100644 templ/login.tpl delete mode 100644 templ/navlinks.tpl delete mode 100644 templ/recur.tpl delete mode 100644 templ/template.go (limited to 'templ') diff --git a/templ/404.tpl b/templ/404.tpl deleted file mode 100644 index b0a3658..0000000 --- a/templ/404.tpl +++ /dev/null @@ -1,10 +0,0 @@ -{{define "main"}} - -{{end}} \ No newline at end of file diff --git a/templ/base.tpl b/templ/base.tpl deleted file mode 100644 index 7e42630..0000000 --- a/templ/base.tpl +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - {{block "title" .}}Kosten{{end}} - - - - {{block "head" .}}{{end}} - - -{{block "body" .}} - Dummy Text -{{end}} -{{block "js" .}} -{{end}} - - \ No newline at end of file diff --git a/templ/categories.tpl b/templ/categories.tpl deleted file mode 100644 index 662e1e1..0000000 --- a/templ/categories.tpl +++ /dev/null @@ -1,9 +0,0 @@ -{{define "main"}} - -{{end}} \ No newline at end of file diff --git a/templ/content.tpl b/templ/content.tpl deleted file mode 100644 index 47a7909..0000000 --- a/templ/content.tpl +++ /dev/null @@ -1,36 +0,0 @@ -{{define "body"}} - {{/* different inline svgs */}} - - - - - - - {{/* The Navbar */}} - - - {{/* The Main Content */}} -
- {{block "main" .}} - Dummy Content - {{end}} -
-{{end}} \ No newline at end of file diff --git a/templ/form.tpl b/templ/form.tpl deleted file mode 100644 index 4d20557..0000000 --- a/templ/form.tpl +++ /dev/null @@ -1,22 +0,0 @@ -{{define "formItem"}} - {{- $cb := eq .Type "checkbox" -}} -
- - - - {{range errors}} -

{{.}}

- {{end}} - {{with .Footer}}

{{.}}

{{end}} -
-{{end}} \ No newline at end of file diff --git a/templ/index.tpl b/templ/index.tpl deleted file mode 100644 index 76016bb..0000000 --- a/templ/index.tpl +++ /dev/null @@ -1,3 +0,0 @@ -{{define "main"}} - Logged in with user: {{.}} -{{end}} \ No newline at end of file diff --git a/templ/login.tpl b/templ/login.tpl deleted file mode 100644 index 7a9a049..0000000 --- a/templ/login.tpl +++ /dev/null @@ -1,10 +0,0 @@ -{{define "body"}} -
-
- - {{inputs_and_errors_for . .Errors}} - {{.CsrfField}} - -
-
-{{end}} \ No newline at end of file diff --git a/templ/navlinks.tpl b/templ/navlinks.tpl deleted file mode 100644 index cdd54d7..0000000 --- a/templ/navlinks.tpl +++ /dev/null @@ -1,8 +0,0 @@ -{{define "navlinks"}} - - -{{end}} \ No newline at end of file diff --git a/templ/recur.tpl b/templ/recur.tpl deleted file mode 100644 index 316b768..0000000 --- a/templ/recur.tpl +++ /dev/null @@ -1,9 +0,0 @@ -{{define "main"}} - -{{end}} \ No newline at end of file diff --git a/templ/template.go b/templ/template.go deleted file mode 100644 index 9cefadc..0000000 --- a/templ/template.go +++ /dev/null @@ -1,73 +0,0 @@ -package templ - -import ( - "embed" - "html/template" - "io/fs" - "os" - "sync" - - "gosten/form" -) - -//go:embed *.tpl -var fsEmbed embed.FS - -var templates = make(map[string]*template.Template) -var muTpl sync.RWMutex - -var baseTpl *template.Template - -var isLive = sync.OnceValue(checkLive) - -func init() { - loadBase(fsEmbed) -} - -func checkLive() bool { - return os.Getenv("GOSTEN_LIVE") != "" -} - -func loadBase(fs fs.FS) { - baseTpl = template.Must(template.New("base.tpl"). - Funcs(form.ParsingFuncMap()). - ParseFS(fs, "base.tpl", "form.tpl", "navlinks.tpl", "content.tpl")) - baseTpl.Funcs(form.FuncMap(baseTpl.Lookup("formItem"))) -} - -func Lookup(name string) *template.Template { - if isLive() { - fs := os.DirFS("templ/") - loadBase(fs) - return getTemplate(name, fs) - } - - muTpl.RLock() - tpl := templates[name] - muTpl.RUnlock() - - if tpl == nil { - return parse(name) - } - return tpl -} - -func parse(name string) *template.Template { - muTpl.Lock() - defer muTpl.Unlock() - - if tpl := templates[name]; tpl != nil { - // might've been created by another goroutine - return tpl - } - - t := getTemplate(name, fsEmbed) - templates[name] = t - return t -} - -func getTemplate(name string, fs fs.FS) *template.Template { - b := template.Must(baseTpl.Clone()) - t := template.Must(b.ParseFS(fs, name+".tpl")) - return t -} -- cgit v1.2.3-70-g09d2