diff --git a/util/templates/class.go b/util/templates/class.go index 8e970ec687..42ea0c109c 100644 --- a/util/templates/class.go +++ b/util/templates/class.go @@ -2,7 +2,7 @@ package templates type Class int -//go:generate enumer -type Class +//go:generate enumer -type Class -transform=lower const ( _ Class = iota Charger diff --git a/util/templates/class_enumer.go b/util/templates/class_enumer.go index 0891e5c019..48acc8c8e1 100644 --- a/util/templates/class_enumer.go +++ b/util/templates/class_enumer.go @@ -1,4 +1,4 @@ -// Code generated by "enumer -type Class"; DO NOT EDIT. +// Code generated by "enumer -type Class -transform=lower"; DO NOT EDIT. package templates @@ -7,7 +7,7 @@ import ( "strings" ) -const _ClassName = "ChargerMeterVehicleTariffCircuit" +const _ClassName = "chargermetervehicletariffcircuit" var _ClassIndex = [...]uint8{0, 7, 12, 19, 25, 32} diff --git a/util/templates/init.go b/util/templates/init.go index 65a9461c6a..143c6c614e 100644 --- a/util/templates/init.go +++ b/util/templates/init.go @@ -5,7 +5,6 @@ import ( "embed" "fmt" "io/fs" - "path" "slices" "sync" "text/template" @@ -33,8 +32,8 @@ func init() { baseTmpl = template.Must(template.ParseFS(includeFS, "includes/*.tpl")) - for _, class := range ClassValues() { - loadTemplates(class) + for _, class := range []Class{Charger, Meter, Vehicle, Tariff} { + templates[class] = load(class) } } @@ -66,12 +65,8 @@ func FromBytes(b []byte) (Template, error) { return tmpl, err } -func loadTemplates(class Class) { - if templates[class] != nil { - return - } - - err := fs.WalkDir(definition.YamlTemplates, ".", func(filepath string, d fs.DirEntry, err error) error { +func load(class Class) (res []Template) { + err := fs.WalkDir(definition.YamlTemplates, class.String(), func(filepath string, d fs.DirEntry, err error) error { if err != nil { return err } @@ -89,18 +84,15 @@ func loadTemplates(class Class) { return fmt.Errorf("processing template '%s' failed: %w", filepath, err) } - class, err := ClassString(path.Dir(filepath)) - if err != nil { - return fmt.Errorf("invalid template class: '%s'", err) - } - - templates[class] = append(templates[class], tmpl) + res = append(res, tmpl) return nil }) if err != nil { panic(err) } + + return res } // EncoderLanguage sets the template language for encoding json