diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-03-31 21:18:58 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-03-31 21:18:58 +0200 |
commit | 66791d940bc60d004835307a86dd98a14cbc9553 (patch) | |
tree | 935f8fb7865bb9b4937b58134880f9dcae6eed0b /template.go | |
parent | a46cf4152ac32d97e0ebd071b9eb1d3e42c7a493 (diff) | |
download | apkdoc-master.tar.gz apkdoc-master.tar.bz2 apkdoc-master.zip |
Diffstat (limited to 'template.go')
-rw-r--r-- | template.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/template.go b/template.go index 8d84f2e..bb8d502 100644 --- a/template.go +++ b/template.go @@ -5,6 +5,7 @@ import ( html "html/template" "io" "os" + "strings" text "text/template" ) @@ -16,6 +17,11 @@ var ( templateFunc = map[string]any{ "DerefI": func(i *int) int { return *i }, "DerefS": func(i *string) string { return *i }, + "Format": func(e *Entry, format string) string { + p := e.Properties() + p["commit"] = strings.Replace(*e.Commit, "-dirty", "", -1) + return tsprintf(format, p) + }, } ) @@ -43,3 +49,10 @@ func GetTemplate(templateType, filePath string) (Templater, error) { return nil, errors.New("Invalid template type") } } + +func tsprintf(format string, params map[string]string) string { + for key, val := range params { + format = strings.Replace(format, "%{"+key+"}s", val, -1) + } + return format +} |