From 6f79fac4f3921e48f98c671f25d2192a27beab9e Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Thu, 7 Jan 2021 17:48:58 +0100 Subject: [PATCH] Add badgesSection template When using custom templates, it's often useful to define a custom list of badges and use that everywhere. For example: I usually add a kubeVersion and an artifact hub badge as well. Signed-off-by: Mark Sagi-Kazar --- pkg/document/template.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/document/template.go b/pkg/document/template.go index 5bebe67..8b7e73b 100644 --- a/pkg/document/template.go +++ b/pkg/document/template.go @@ -1,13 +1,14 @@ package document import ( - "github.com/norwoodj/helm-docs/pkg/util" "io/ioutil" "os" "path" "strings" "text/template" + "github.com/norwoodj/helm-docs/pkg/util" + "github.com/Masterminds/sprig" log "github.com/sirupsen/logrus" @@ -91,6 +92,15 @@ func getAppVersionTemplate() string { return appVersionBuilder.String() } +func getBadgesTemplates() string { + badgeBuilder := strings.Builder{} + badgeBuilder.WriteString(`{{ define "chart.badgesSection" }}`) + badgeBuilder.WriteString(`{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}`) + badgeBuilder.WriteString("{{ end }}") + + return badgeBuilder.String() +} + func getDescriptionTemplate() string { descriptionBuilder := strings.Builder{} descriptionBuilder.WriteString(`{{ define "chart.description" }}`) @@ -271,6 +281,7 @@ func getDocumentationTemplates(chartDirectory string, chartSearchRoot string, te getHeaderTemplate(), getDeprecatedTemplate(), getAppVersionTemplate(), + getBadgesTemplates(), getDescriptionTemplate(), getVersionTemplates(), getTypeTemplate(),