refactor(templates): Dynamic image loading

This commit is contained in:
2024-12-09 17:28:53 +01:00
parent c5dc4f7e79
commit 11a9b51197
7 changed files with 14 additions and 11 deletions

View File

@@ -90,7 +90,11 @@ func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
return GetImage(sponsors[id%len(sponsors)]), nil
}
func FormatUnit(unit string, locale string, amount int) (string, error) {
func (t *DefaultTemplater) LoadImage(name string) (string, error) {
return GetImage(name), nil
}
func (t *DefaultTemplater) FormatUnit(unit string, locale string, amount int) (string, error) {
var formatted string
switch unit {
case "kilometer":
@@ -111,7 +115,8 @@ func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Te
return template.New("template").Funcs(template.FuncMap{
"barcode": t.GenerateBarcode,
"sponsorLogo": t.SelectSponsorImage,
"formatUnit": FormatUnit,
"formatUnit": t.FormatUnit,
"loadImage": t.LoadImage,
}).Parse(templateString)
}