From 79df6b030fd2a25bbc0c30ac0976ea33f8e423d2 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Mon, 28 Feb 2022 23:38:11 -0300 Subject: [PATCH] feat: add getsection template function issue: #40 --- sv/formatter.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sv/formatter.go b/sv/formatter.go index 917d0c5..96e8488 100644 --- a/sv/formatter.go +++ b/sv/formatter.go @@ -33,7 +33,8 @@ type OutputFormatterImpl struct { // NewOutputFormatter TemplateProcessor constructor. func NewOutputFormatter(templatesFS fs.FS) *OutputFormatterImpl { templateFNs := map[string]interface{}{ - "timefmt": timeFormat, + "timefmt": timeFormat, + "getSection": getSection, } tpls := template.Must(template.New("templates").Funcs(templateFNs).ParseFS(templatesFS, "*")) return &OutputFormatterImpl{templates: tpls} @@ -94,3 +95,12 @@ func timeFormat(t time.Time, format string) string { } return t.Format(format) } + +func getSection(sections []ReleaseNoteSection, name string) ReleaseNoteSection { + for _, section := range sections { + if section.SectionName() == name { + return section + } + } + return nil +}