Skip to content

Commit d1a32aa

Browse files
committed
Sectioned values are default if provied
1 parent 7d54b35 commit d1a32aa

File tree

1 file changed

+51
-64
lines changed

1 file changed

+51
-64
lines changed

pkg/document/template.go

+51-64
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,33 @@ func getValuesTableTemplates() string {
208208
valuesSectionBuilder.WriteString(`{{ define "chart.valuesHeader" }}## Values{{ end }}`)
209209

210210
valuesSectionBuilder.WriteString(`{{ define "chart.valuesTable" }}`)
211+
valuesSectionBuilder.WriteString("{{ if .Sections.Sections }}")
212+
valuesSectionBuilder.WriteString("{{ range .Sections.Sections }}")
213+
valuesSectionBuilder.WriteString("\n")
214+
valuesSectionBuilder.WriteString("\n### {{ .SectionName }}\n")
215+
valuesSectionBuilder.WriteString("| Key | Type | Default | Description |\n")
216+
valuesSectionBuilder.WriteString("|-----|------|---------|-------------|\n")
217+
valuesSectionBuilder.WriteString(" {{- range .SectionItems }}")
218+
valuesSectionBuilder.WriteString("\n| {{ .Key }} | {{ .Type }} | {{ if .Default }}{{ .Default }}{{ else }}{{ .AutoDefault }}{{ end }} | {{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }} |")
219+
valuesSectionBuilder.WriteString(" {{- end }}")
220+
valuesSectionBuilder.WriteString("{{- end }}")
221+
valuesSectionBuilder.WriteString("{{ if .Sections.DefaultSection.SectionItems}}")
222+
valuesSectionBuilder.WriteString("\n")
223+
valuesSectionBuilder.WriteString("\n### {{ .Sections.DefaultSection.SectionName }}\n")
224+
valuesSectionBuilder.WriteString("| Key | Type | Default | Description |\n")
225+
valuesSectionBuilder.WriteString("|-----|------|---------|-------------|\n")
226+
valuesSectionBuilder.WriteString(" {{- range .Sections.DefaultSection.SectionItems }}")
227+
valuesSectionBuilder.WriteString("\n| {{ .Key }} | {{ .Type }} | {{ if .Default }}{{ .Default }}{{ else }}{{ .AutoDefault }}{{ end }} | {{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }} |")
228+
valuesSectionBuilder.WriteString(" {{- end }}")
229+
valuesSectionBuilder.WriteString("{{ end }}")
230+
valuesSectionBuilder.WriteString("{{ else }}")
211231
valuesSectionBuilder.WriteString("| Key | Type | Default | Description |\n")
212232
valuesSectionBuilder.WriteString("|-----|------|---------|-------------|\n")
213233
valuesSectionBuilder.WriteString(" {{- range .Values }}")
214234
valuesSectionBuilder.WriteString("\n| {{ .Key }} | {{ .Type }} | {{ if .Default }}{{ .Default }}{{ else }}{{ .AutoDefault }}{{ end }} | {{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }} |")
215235
valuesSectionBuilder.WriteString(" {{- end }}")
216236
valuesSectionBuilder.WriteString("{{ end }}")
237+
valuesSectionBuilder.WriteString("{{ end }}")
217238

218239
valuesSectionBuilder.WriteString(`{{ define "chart.valuesSection" }}`)
219240
valuesSectionBuilder.WriteString("{{ if .Values }}")
@@ -243,6 +264,9 @@ func getValuesTableTemplates() string {
243264
{{ end }}
244265
245266
{{ define "chart.valuesTableHtml" }}
267+
{{ if .Sections.Sections }}
268+
{{- range .Sections.Sections }}
269+
<h3>{{- .SectionName }}</h3>
246270
<table>
247271
<thead>
248272
<th>Key</th>
@@ -251,7 +275,7 @@ func getValuesTableTemplates() string {
251275
<th>Description</th>
252276
</thead>
253277
<tbody>
254-
{{- range .Values }}
278+
{{- range .SectionItems }}
255279
<tr>
256280
<td>{{ .Key }}</td>
257281
<td>{{ .Type }}</td>
@@ -261,65 +285,29 @@ func getValuesTableTemplates() string {
261285
{{- end }}
262286
</tbody>
263287
</table>
264-
{{ end }}
265-
266-
{{ define "chart.valuesSectionHtml" }}
267-
{{ if .Values }}
268-
{{ template "chart.valuesHeader" . }}
269-
{{ template "chart.valuesTableHtml" . }}
270-
{{ end }}
271-
{{ end }}
272-
`)
273-
274-
return valuesSectionBuilder.String()
275-
}
276-
277-
func getValuesTableSectionedTemplates() string {
278-
valuesSectionBuilder := strings.Builder{}
279-
valuesSectionBuilder.WriteString(`{{ define "chart.valuesSectionedHeader" }}## Values{{ end }}`)
280-
281-
valuesSectionBuilder.WriteString(`{{ define "chart.valuesSectionedTable" }}`)
282-
valuesSectionBuilder.WriteString("{{ range .Sections }}")
283-
valuesSectionBuilder.WriteString("\n")
284-
valuesSectionBuilder.WriteString("\n### {{ .SectionName }}\n")
285-
valuesSectionBuilder.WriteString("| Key | Type | Default | Description |\n")
286-
valuesSectionBuilder.WriteString("|-----|------|---------|-------------|\n")
287-
valuesSectionBuilder.WriteString(" {{- range .SectionItems }}")
288-
valuesSectionBuilder.WriteString("\n| {{ .Key }} | {{ .Type }} | {{ if .Default }}{{ .Default }}{{ else }}{{ .AutoDefault }}{{ end }} | {{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }} |")
289-
valuesSectionBuilder.WriteString(" {{- end }}")
290-
valuesSectionBuilder.WriteString("{{ end }}")
291-
valuesSectionBuilder.WriteString("{{ end }}")
292-
293-
valuesSectionBuilder.WriteString(`{{ define "chart.valuesSectionedSection" }}`)
294-
valuesSectionBuilder.WriteString("{{ if .Values }}")
295-
valuesSectionBuilder.WriteString(`{{ template "chart.valuesSectionedHeader" . }}`)
296-
valuesSectionBuilder.WriteString("\n\n")
297-
valuesSectionBuilder.WriteString(`{{ template "chart.valuesSectionedTable" . }}`)
298-
valuesSectionBuilder.WriteString("{{ end }}")
299-
valuesSectionBuilder.WriteString("{{ end }}")
300-
301-
// For HTML tables
302-
valuesSectionBuilder.WriteString(`
303-
{{ define "chart.valueDefaultColumnRender" }}
304-
{{- $defaultValue := (default .Default .AutoDefault) -}}
305-
{{- $notationType := .NotationType }}
306-
{{- if (and (hasPrefix "` + "`" + `" $defaultValue) (hasSuffix "` + "`" + `" $defaultValue) ) -}}
307-
{{- $defaultValue = (toPrettyJson (fromJson (trimAll "` + "`" + `" (default .Default .AutoDefault) ) ) ) -}}
308-
{{- $notationType = "json" }}
309-
{{- end -}}
310-
<pre lang="{{ $notationType }}">
311-
{{- if (eq $notationType "tpl" ) }}
312-
{{ .Key }}: |
313-
{{- $defaultValue | nindent 2 }}
314-
{{- else }}
315-
{{ $defaultValue }}
316288
{{- end }}
317-
</pre>
289+
{{ if .Sections.DefaultSection.SectionItems }}
290+
<h3>{{- .Sections.DefaultSection.SectionName }}</h3>
291+
<table>
292+
<thead>
293+
<th>Key</th>
294+
<th>Type</th>
295+
<th>Default</th>
296+
<th>Description</th>
297+
</thead>
298+
<tbody>
299+
{{- range .Sections.DefaultSection.SectionItems }}
300+
<tr>
301+
<td>{{ .Key }}</td>
302+
<td>{{ .Type }}</td>
303+
<td>{{ template "chart.valueDefaultColumnRender" . }}</td>
304+
<td>{{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }}</td>
305+
</tr>
306+
{{- end }}
307+
</tbody>
308+
</table>
318309
{{ end }}
319-
320-
{{ define "chart.valuesSectionedTableHtml" }}
321-
{{- range .Sections }}
322-
<h3>{{- .SectionName }}</h3>
310+
{{ else }}
323311
<table>
324312
<thead>
325313
<th>Key</th>
@@ -328,7 +316,7 @@ func getValuesTableSectionedTemplates() string {
328316
<th>Description</th>
329317
</thead>
330318
<tbody>
331-
{{- range .SectionItems }}
319+
{{- range .Values }}
332320
<tr>
333321
<td>{{ .Key }}</td>
334322
<td>{{ .Type }}</td>
@@ -338,13 +326,13 @@ func getValuesTableSectionedTemplates() string {
338326
{{- end }}
339327
</tbody>
340328
</table>
341-
{{- end }}
329+
{{ end }}
342330
{{ end }}
343331
344-
{{ define "chart.valuesSectionedSectionHtml" }}
332+
{{ define "chart.valuesSectionHtml" }}
345333
{{ if .Sections }}
346-
{{ template "chart.valuesSectionedHeader" . }}
347-
{{ template "chart.valuesSectionedTableHtml" . }}
334+
{{ template "chart.valuesHeader" . }}
335+
{{ template "chart.valuesTableHtml" . }}
348336
{{ end }}
349337
{{ end }}
350338
`)
@@ -428,7 +416,6 @@ func getDocumentationTemplates(chartDirectory string, chartSearchRoot string, te
428416
getSourceLinkTemplates(),
429417
getRequirementsTableTemplates(),
430418
getValuesTableTemplates(),
431-
getValuesTableSectionedTemplates(),
432419
getHomepageTemplate(),
433420
getMaintainersTemplate(),
434421
getHelmDocsVersionTemplates(),

0 commit comments

Comments
 (0)