dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 31e280d835a20febfcfae667fd99b20f9c00716e
parent 386cd69d42585636afe7d8bdcc084db96b70511d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 30 May 2023 07:42:30 -0700

cleanup + tests

Diffstat:
Mpkg/template/templates.go | 11++++++++---
Apkg/template/templates_test.go | 26++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/pkg/template/templates.go b/pkg/template/templates.go @@ -146,13 +146,18 @@ func buildTemplatesHelper(root string, tmpls map[string]*template.Template, pref if err != nil { logrus.Error(root+prefix+"/"+page+ext, err) } - tmplName := strings.TrimPrefix(prefix, "/") - tmplName = strings.Join(strings.Split(tmplName, "/"), ".") + "." + page - tmplName = strings.TrimPrefix(tmplName, ".") + tmplName := buildTemplateName(prefix, page) tmpls[tmplName] = tmpl.Tmpl } } +func buildTemplateName(prefix, page string) string { + tmplName := strings.TrimPrefix(prefix, "/") + tmplName = strings.Join(strings.Split(tmplName, "/"), ".") + "." + page + tmplName = strings.TrimPrefix(tmplName, ".") + return tmplName +} + func parseBases(tmpl *Template, bases []string) { var err error for _, b := range bases { diff --git a/pkg/template/templates_test.go b/pkg/template/templates_test.go @@ -0,0 +1,26 @@ +package template + +import "testing" + +func Test_buildTemplateName(t *testing.T) { + type args struct { + prefix string + page string + } + tests := []struct { + name string + args args + want string + }{ + {"", args{prefix: "/", page: "page"}, "page"}, + {"", args{prefix: "/admin", page: "page"}, "admin.page"}, + {"", args{prefix: "/admin/settings", page: "page"}, "admin.settings.page"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := buildTemplateName(tt.args.prefix, tt.args.page); got != tt.want { + t.Errorf("buildTemplateName() = %v, want %v", got, tt.want) + } + }) + } +}