mirror of
https://github.com/git-chglog/git-chglog.git
synced 2026-01-23 02:15:12 +00:00
feat: add the contains, hasPrefix, hasSuffix, replace, lower and upper functions to the template functions map
This PR adds the strings.Contains, strings.HasPrefix, strings.HasSuffix, strings.Replace, strings.Lower and strings.Upper to the set of functions available for usage in the changelog template. The added functions can be used to manipulate commit messages before rendering the changelog.
This commit is contained in:
parent
44fcaed553
commit
dc128028e6
1 changed files with 26 additions and 0 deletions
26
chglog.go
26
chglog.go
|
|
@ -7,6 +7,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
|
|
@ -302,9 +303,34 @@ func (gen *Generator) render(w io.Writer, unreleased *Unreleased, versions []*Ve
|
|||
}
|
||||
|
||||
fmap := template.FuncMap{
|
||||
// format the input time according to layout
|
||||
"datetime": func(layout string, input time.Time) string {
|
||||
return input.Format(layout)
|
||||
},
|
||||
// check whether substs is withing s
|
||||
"contains": func(s, substr string) bool {
|
||||
return strings.Contains(s, substr)
|
||||
},
|
||||
// check whether s begins with prefix
|
||||
"hasPrefix": func(s, prefix string) bool {
|
||||
return strings.HasPrefix(s, prefix)
|
||||
},
|
||||
// check whether s ends with suffix
|
||||
"hasSuffix": func(s, suffix string) bool {
|
||||
return strings.HasSuffix(s, suffix)
|
||||
},
|
||||
// replace the first n instances of old with new
|
||||
"replace": func(s, old, new string, n int) string {
|
||||
return strings.Replace(s, old, new, n)
|
||||
},
|
||||
// lower case a string
|
||||
"lower": func(s string) string {
|
||||
return strings.ToLower(s)
|
||||
},
|
||||
// upper case a string
|
||||
"upper": func(s string) string {
|
||||
return strings.ToUpper(s)
|
||||
},
|
||||
}
|
||||
|
||||
fname := filepath.Base(gen.config.Template)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue