Skip to content

Commit 4834ae2

Browse files
authored
Merge pull request #10 from cert-manager/feat/add-vertical-table-template
feat: add vertical table layout
2 parents 263fd66 + e0c66d4 commit 4834ae2

File tree

8 files changed

+15214
-895
lines changed

8 files changed

+15214
-895
lines changed

examples/cert-manager/README.md

Lines changed: 14643 additions & 672 deletions
Large diffs are not rendered by default.

examples/cert-manager/values.yaml

Lines changed: 478 additions & 182 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ require (
1919
github.com/go-openapi/swag v0.22.3 // indirect
2020
github.com/golang/protobuf v1.5.2 // indirect
2121
github.com/google/gnostic-models v0.6.8 // indirect
22-
github.com/google/uuid v1.1.2 // indirect
23-
github.com/huandu/xstrings v1.3.3 // indirect
24-
github.com/imdario/mergo v0.3.11 // indirect
22+
github.com/google/uuid v1.5.0 // indirect
23+
github.com/huandu/xstrings v1.4.0 // indirect
24+
github.com/imdario/mergo v0.3.16 // indirect
2525
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2626
github.com/josharian/intern v1.0.0 // indirect
2727
github.com/mailru/easyjson v0.7.7 // indirect
28-
github.com/mitchellh/copystructure v1.0.0 // indirect
29-
github.com/mitchellh/reflectwalk v1.0.0 // indirect
28+
github.com/mitchellh/copystructure v1.2.0 // indirect
29+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
3030
github.com/pmezard/go-difflib v1.0.0 // indirect
3131
github.com/shopspring/decimal v1.2.0 // indirect
3232
github.com/spf13/cast v1.3.1 // indirect
3333
github.com/spf13/pflag v1.0.5 // indirect
34-
golang.org/x/crypto v0.3.0 // indirect
34+
golang.org/x/crypto v0.18.0 // indirect
3535
google.golang.org/protobuf v1.27.1 // indirect
3636
)

go.sum

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
2525
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
2626
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
2727
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
28-
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
29-
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
30-
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
28+
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
29+
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
3130
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
32-
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
31+
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
32+
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
3333
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
34+
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
35+
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
3436
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3537
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
3638
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@@ -43,10 +45,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
4345
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
4446
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
4547
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
46-
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
4748
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
48-
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
49+
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
50+
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
4951
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
52+
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
53+
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
5054
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5155
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5256
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -70,8 +74,9 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
7074
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
7175
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
7276
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
73-
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
7477
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
78+
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
79+
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
7580
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
7681
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
7782
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -108,8 +113,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
108113
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
109114
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
110115
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
111-
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
112-
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
113116
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
114117
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
115118
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ var Render = cobra.Command{
5252
os.Exit(1)
5353
}
5454

55-
fmt.Println(render.Render(templateName, document))
55+
result, err := render.Render(templateName, document)
56+
if err != nil {
57+
fmt.Fprintf(os.Stderr, "Error rendering template: %s\n", err)
58+
os.Exit(1)
59+
}
60+
61+
fmt.Println(result)
5662
},
5763
}
5864

render/markdown-table

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
{{- /* Comment rendering depends on the comment type, define a helper function */}}
22
{{ define "comment" }}
33
{{ if eq .Type "yaml" }}
4-
<pre lang="yaml">
5-
{{- range .Contents }}
4+
```yaml
65
{{ . }}
7-
{{- end }}
8-
</pre>
6+
```
97
{{- else if eq .Type "text" }}
10-
<p>
11-
12-
{{ $firstLineInParagraph := true }}
13-
{{- range .Contents }}
14-
{{- if eq . "" }}
15-
16-
</p>
17-
<p>
18-
19-
{{ $firstLineInParagraph = true }}
20-
{{- else }}
21-
{{- if $firstLineInParagraph }}{{ . }}{{ else }}<br/>
22-
{{ . }}{{ end }}
23-
{{- $firstLineInParagraph = false }}
24-
{{- end }}
25-
{{- end }}
26-
27-
</p>
8+
{{- /* Newlines are only preserved in markdown if the line ends with two or more spaces */}}
9+
{{ .String | replace "\n" " \n"}}
2810
{{- end }}
2911
{{- end }}
3012

@@ -66,10 +48,11 @@
6648
<td>{{.Type}}</td>
6749
<td>
6850

69-
<pre lang="yaml">{{.Default}}</pre>
51+
```yaml
52+
{{.Default}}
53+
```
7054

7155
</td>
72-
7356
</tr>
7457
{{- end }}
7558
</table>

render/markdown-table-vertical

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{{- /* Comment rendering depends on the comment type, define a helper function */}}
2+
{{ define "comment" }}
3+
{{ if eq .Type "yaml" }}
4+
```yaml
5+
{{ . }}
6+
```
7+
{{- else if eq .Type "text" }}
8+
{{- /* Newlines are only preserved in markdown if the line ends with two or more spaces */}}
9+
{{ .String | replace "\n" " \n"}}
10+
{{- end }}
11+
{{- end }}
12+
13+
{{- /* Iterate over defined sections */}}
14+
{{- range .Sections }}
15+
16+
{{- /* Render section header */}}
17+
{{- if .Name }}
18+
## {{ .Name }}
19+
{{- end }}
20+
21+
{{- /* Render the description comment */}}
22+
{{- range .Description.Segments }}
23+
{{- template "comment" . }}
24+
{{- end }}
25+
26+
{{- /* Iterate over properties within the section */}}
27+
{{- range .Properties }}
28+
29+
### {{ .Name }}
30+
31+
<table>
32+
<tr>
33+
<th>Property</th>
34+
<td>{{ .Name }}</td>
35+
</tr>
36+
<tr>
37+
<th>Type</th>
38+
<td>{{.Type}}</td>
39+
</tr>
40+
<tr>
41+
<th>Default</th>
42+
<td>
43+
44+
```yaml
45+
{{.Default}}
46+
```
47+
48+
</td>
49+
</tr>
50+
</table>
51+
52+
{{- range .Description.Segments }}
53+
{{- template "comment" . }}
54+
{{- end }}
55+
56+
{{ end }}
57+
{{- end }}

render/render.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ import (
2727
"text/template"
2828

2929
"github.com/cert-manager/helm-tool/parser"
30+
31+
"github.com/Masterminds/sprig/v3"
3032
)
3133

3234
//go:embed markdown-table
35+
//go:embed markdown-table-vertical
3336
var templates embed.FS
3437

3538
func openTemplate(path string) (fs.File, error) {
@@ -58,7 +61,7 @@ func Render(templateName string, document *parser.Document) (string, error) {
5861
return "", err
5962
}
6063

61-
template, err := template.New(templateName).Parse(string(templateBytes))
64+
template, err := template.New(templateName).Funcs(sprig.TxtFuncMap()).Parse(string(templateBytes))
6265
if err != nil {
6366
return "", err
6467
}

0 commit comments

Comments
 (0)