mirror of
https://github.com/git-chglog/git-chglog.git
synced 2026-01-23 02:15:12 +00:00
feat: add sprig template functions support (#131)
* cherry-pick from delmendo * add tests, docs, and lift hermetic restriction * remove duplicate funcs that are now provided by sprig * switch func load order to allow built-ins precedence * Update chglog.go Co-authored-by: Dirk Elmendorf <dirk@r26d.com>
This commit is contained in:
parent
e523fd471a
commit
4f3fdc4dae
6 changed files with 176 additions and 27 deletions
15
chglog.go
15
chglog.go
|
|
@ -12,6 +12,7 @@ import (
|
|||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/tsuyoshiwada/go-gitcmd"
|
||||
)
|
||||
|
||||
|
|
@ -324,18 +325,6 @@ func (gen *Generator) render(w io.Writer, unreleased *Unreleased, versions []*Ve
|
|||
"datetime": func(layout string, input time.Time) string {
|
||||
return input.Format(layout)
|
||||
},
|
||||
// check whether substr is within s
|
||||
"contains": strings.Contains,
|
||||
// check whether s begins with prefix
|
||||
"hasPrefix": strings.HasPrefix,
|
||||
// check whether s ends with suffix
|
||||
"hasSuffix": strings.HasSuffix,
|
||||
// replace the first n instances of old with new
|
||||
"replace": strings.Replace,
|
||||
// lower case a string
|
||||
"lower": strings.ToLower,
|
||||
// upper case a string
|
||||
"upper": strings.ToUpper,
|
||||
// upper case the first character of a string
|
||||
"upperFirst": func(s string) string {
|
||||
if len(s) > 0 {
|
||||
|
|
@ -355,7 +344,7 @@ func (gen *Generator) render(w io.Writer, unreleased *Unreleased, versions []*Ve
|
|||
|
||||
fname := filepath.Base(gen.config.Template)
|
||||
|
||||
t := template.Must(template.New(fname).Funcs(fmap).ParseFiles(gen.config.Template))
|
||||
t := template.Must(template.New(fname).Funcs(sprig.TxtFuncMap()).Funcs(fmap).ParseFiles(gen.config.Template))
|
||||
|
||||
return t.Execute(w, &RenderData{
|
||||
Info: gen.config.Info,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue