0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-21 12:00:40 +00:00

feat: add getsection template function

issue: #40
This commit is contained in:
Beatriz Vieira 2022-02-28 23:38:11 -03:00
parent 19bf65fbb3
commit 79df6b030f

View File

@ -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
}