0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-21 22:10:39 +00:00

refactor: move template funcions to a new go file

issue: #40
This commit is contained in:
Beatriz Vieira 2022-02-28 23:40:29 -03:00
parent 79df6b030f
commit 7871515ac0
2 changed files with 20 additions and 17 deletions

View File

@ -34,7 +34,7 @@ type OutputFormatterImpl struct {
func NewOutputFormatter(templatesFS fs.FS) *OutputFormatterImpl { func NewOutputFormatter(templatesFS fs.FS) *OutputFormatterImpl {
templateFNs := map[string]interface{}{ templateFNs := map[string]interface{}{
"timefmt": timeFormat, "timefmt": timeFormat,
"getSection": getSection, "getsection": getSection,
} }
tpls := template.Must(template.New("templates").Funcs(templateFNs).ParseFS(templatesFS, "*")) tpls := template.Must(template.New("templates").Funcs(templateFNs).ParseFS(templatesFS, "*"))
return &OutputFormatterImpl{templates: tpls} return &OutputFormatterImpl{templates: tpls}
@ -88,19 +88,3 @@ func toSortedArray(input map[string]struct{}) []string {
sort.Strings(result) sort.Strings(result)
return result return result
} }
func timeFormat(t time.Time, format string) string {
if t.IsZero() {
return ""
}
return t.Format(format)
}
func getSection(sections []ReleaseNoteSection, name string) ReleaseNoteSection {
for _, section := range sections {
if section.SectionName() == name {
return section
}
}
return nil
}

19
sv/formatter_functions.go Normal file
View File

@ -0,0 +1,19 @@
package sv
import "time"
func timeFormat(t time.Time, format string) string {
if t.IsZero() {
return ""
}
return t.Format(format)
}
func getSection(sections []ReleaseNoteSection, name string) ReleaseNoteSection {
for _, section := range sections {
if section.SectionName() == name {
return section
}
}
return nil
}