From 7871515ac05412fce777247abc9c73b0d53d0c27 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Mon, 28 Feb 2022 23:40:29 -0300 Subject: [PATCH] refactor: move template funcions to a new go file issue: #40 --- sv/formatter.go | 18 +----------------- sv/formatter_functions.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 sv/formatter_functions.go diff --git a/sv/formatter.go b/sv/formatter.go index 96e8488..61b7ee8 100644 --- a/sv/formatter.go +++ b/sv/formatter.go @@ -34,7 +34,7 @@ type OutputFormatterImpl struct { func NewOutputFormatter(templatesFS fs.FS) *OutputFormatterImpl { templateFNs := map[string]interface{}{ "timefmt": timeFormat, - "getSection": getSection, + "getsection": getSection, } tpls := template.Must(template.New("templates").Funcs(templateFNs).ParseFS(templatesFS, "*")) return &OutputFormatterImpl{templates: tpls} @@ -88,19 +88,3 @@ func toSortedArray(input map[string]struct{}) []string { sort.Strings(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 -} diff --git a/sv/formatter_functions.go b/sv/formatter_functions.go new file mode 100644 index 0000000..607b988 --- /dev/null +++ b/sv/formatter_functions.go @@ -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 +}