refactor(templates): Dynamic image loading
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user