From 6f79fac4f3921e48f98c671f25d2192a27beab9e Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Thu, 7 Jan 2021 17:48:58 +0100 Subject: [PATCH 1/3] 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(), From 3be86db6b28796c27343a179296c96b824071ad3 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Thu, 7 Jan 2021 17:51:04 +0100 Subject: [PATCH 2/3] Update the default template to use badgesSection Signed-off-by: Mark Sagi-Kazar --- README.md | 2 +- pkg/document/template.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 233b081..1e43538 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ The default internal template mentioned above uses many of these and looks like {{ template "chart.header" . }} {{ template "chart.deprecationWarning" . }} -{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }} +{{ template "chart.badgesSection" . }} {{ template "chart.description" . }} diff --git a/pkg/document/template.go b/pkg/document/template.go index 8b7e73b..392e6b7 100644 --- a/pkg/document/template.go +++ b/pkg/document/template.go @@ -18,7 +18,7 @@ import ( const defaultDocumentationTemplate = `{{ template "chart.header" . }} {{ template "chart.deprecationWarning" . }} -{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }} +{{ template "chart.badgesSection" . }} {{ template "chart.description" . }} From e8bea3438b5441782e1c5845e1d8fa14edc457c6 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Thu, 7 Jan 2021 17:51:36 +0100 Subject: [PATCH 3/3] Update full-template example Signed-off-by: Mark Sagi-Kazar --- example-charts/full-template/README.md | 4 ++++ example-charts/full-template/README.md.gotmpl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/example-charts/full-template/README.md b/example-charts/full-template/README.md index 4f33df8..8d2699a 100644 --- a/example-charts/full-template/README.md +++ b/example-charts/full-template/README.md @@ -50,6 +50,10 @@ application ![AppVersion: 13.0.0](https://img.shields.io/badge/AppVersion-13.0.0-informational?style=flat-square) +## `chart.badgesSection` + +![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 13.0.0](https://img.shields.io/badge/AppVersion-13.0.0-informational?style=flat-square) + ## `chart.homepage` https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template diff --git a/example-charts/full-template/README.md.gotmpl b/example-charts/full-template/README.md.gotmpl index a01c2f9..b5b7d92 100644 --- a/example-charts/full-template/README.md.gotmpl +++ b/example-charts/full-template/README.md.gotmpl @@ -40,6 +40,10 @@ {{ template "chart.appVersionBadge" . }} +## `chart.badgesSection` + +{{ template "chart.badgesSection" . }} + ## `chart.homepage` {{ template "chart.homepage" . }}