| skipped 7 lines |
8 | 8 | | "crypto/sha1" |
9 | 9 | | "encoding/base64" |
10 | 10 | | "fmt" |
| 11 | + | "github.com/flosch/pongo2/v6" |
11 | 12 | | "io" |
12 | 13 | | "io/ioutil" |
13 | 14 | | "math/rand" |
| skipped 867 lines |
881 | 882 | | return |
882 | 883 | | } |
883 | 884 | | |
884 | | - | // RenderText resolve template from signature file |
885 | | - | func RenderText(format string, data map[string]string) string { |
| 885 | + | // OldRenderText resolve template from signature file |
| 886 | + | func OldRenderText(format string, data map[string]string) string { |
886 | 887 | | t := template.Must(template.New("").Parse(format)) |
887 | 888 | | buf := &bytes.Buffer{} |
888 | 889 | | err := t.Execute(buf, data) |
| skipped 3 lines |
892 | 893 | | return buf.String() |
893 | 894 | | } |
894 | 895 | | |
| 896 | + | // RenderText resolve template from signature file |
| 897 | + | func RenderText(format string, data map[string]string) string { |
| 898 | + | // for backward compatibility because new template using `{{variable}}` instead of `{{.variable}}` |
| 899 | + | if strings.Contains(format, "{{.") { |
| 900 | + | return OldRenderText(format, data) |
| 901 | + | } |
| 902 | + | |
| 903 | + | variable := make(map[string]interface{}) |
| 904 | + | for k, v := range data { |
| 905 | + | variable[k] = v |
| 906 | + | } |
| 907 | + | if tpl, err := pongo2.FromString(format); err == nil { |
| 908 | + | out, ok := tpl.Execute(variable) |
| 909 | + | if ok == nil { |
| 910 | + | return out |
| 911 | + | } |
| 912 | + | ErrorF("Error when resolve template: %v", ok) |
| 913 | + | } |
| 914 | + | return format |
| 915 | + | } |
| 916 | + | |