Skip to content

Commit

Permalink
Merge pull request #10 from cert-manager/feat/add-vertical-table-temp…
Browse files Browse the repository at this point in the history
…late

feat: add vertical table layout
  • Loading branch information
jetstack-bot authored Jan 12, 2024
2 parents 263fd66 + e0c66d4 commit 4834ae2
Show file tree
Hide file tree
Showing 8 changed files with 15,214 additions and 895 deletions.
15,315 changes: 14,643 additions & 672 deletions examples/cert-manager/README.md

Large diffs are not rendered by default.

660 changes: 478 additions & 182 deletions examples/cert-manager/values.yaml

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ require (
github.com/go-openapi/swag v0.22.3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)
21 changes: 12 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand All @@ -43,10 +45,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand All @@ -70,8 +74,9 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand Down Expand Up @@ -108,8 +113,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ var Render = cobra.Command{
os.Exit(1)
}

fmt.Println(render.Render(templateName, document))
result, err := render.Render(templateName, document)
if err != nil {
fmt.Fprintf(os.Stderr, "Error rendering template: %s\n", err)
os.Exit(1)
}

fmt.Println(result)
},
}

Expand Down
31 changes: 7 additions & 24 deletions render/markdown-table
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
{{- /* Comment rendering depends on the comment type, define a helper function */}}
{{ define "comment" }}
{{ if eq .Type "yaml" }}
<pre lang="yaml">
{{- range .Contents }}
```yaml
{{ . }}
{{- end }}
</pre>
```
{{- else if eq .Type "text" }}
<p>

{{ $firstLineInParagraph := true }}
{{- range .Contents }}
{{- if eq . "" }}

</p>
<p>

{{ $firstLineInParagraph = true }}
{{- else }}
{{- if $firstLineInParagraph }}{{ . }}{{ else }}<br/>
{{ . }}{{ end }}
{{- $firstLineInParagraph = false }}
{{- end }}
{{- end }}

</p>
{{- /* Newlines are only preserved in markdown if the line ends with two or more spaces */}}
{{ .String | replace "\n" " \n"}}
{{- end }}
{{- end }}

Expand Down Expand Up @@ -66,10 +48,11 @@
<td>{{.Type}}</td>
<td>

<pre lang="yaml">{{.Default}}</pre>
```yaml
{{.Default}}
```

</td>

</tr>
{{- end }}
</table>
Expand Down
57 changes: 57 additions & 0 deletions render/markdown-table-vertical
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{- /* Comment rendering depends on the comment type, define a helper function */}}
{{ define "comment" }}
{{ if eq .Type "yaml" }}
```yaml
{{ . }}
```
{{- else if eq .Type "text" }}
{{- /* Newlines are only preserved in markdown if the line ends with two or more spaces */}}
{{ .String | replace "\n" " \n"}}
{{- end }}
{{- end }}

{{- /* Iterate over defined sections */}}
{{- range .Sections }}

{{- /* Render section header */}}
{{- if .Name }}
## {{ .Name }}
{{- end }}

{{- /* Render the description comment */}}
{{- range .Description.Segments }}
{{- template "comment" . }}
{{- end }}

{{- /* Iterate over properties within the section */}}
{{- range .Properties }}

### {{ .Name }}

<table>
<tr>
<th>Property</th>
<td>{{ .Name }}</td>
</tr>
<tr>
<th>Type</th>
<td>{{.Type}}</td>
</tr>
<tr>
<th>Default</th>
<td>

```yaml
{{.Default}}
```

</td>
</tr>
</table>

{{- range .Description.Segments }}
{{- template "comment" . }}
{{- end }}

{{ end }}
{{- end }}
5 changes: 4 additions & 1 deletion render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import (
"text/template"

"github.com/cert-manager/helm-tool/parser"

"github.com/Masterminds/sprig/v3"
)

//go:embed markdown-table
//go:embed markdown-table-vertical
var templates embed.FS

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

template, err := template.New(templateName).Parse(string(templateBytes))
template, err := template.New(templateName).Funcs(sprig.TxtFuncMap()).Parse(string(templateBytes))
if err != nil {
return "", err
}
Expand Down

0 comments on commit 4834ae2

Please sign in to comment.