Skip to content

Commit

Permalink
Merge pull request #186 from feloy/feloy-anchors
Browse files Browse the repository at this point in the history
resourcedocs: Add Anchors to inlined definitions
  • Loading branch information
k8s-ci-robot committed Jan 5, 2021
2 parents c96658d + 2c047b6 commit 6d86d27
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gen-resourcesdocs/pkg/config/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (o *TOC) OutputProperties(defname string, definition spec.Schema, outputSec
return err
}

err = outputSection.AddTypeDefinition(target.Description)
err = outputSection.AddTypeDefinition(property.TypeKey.ResourceName(), target.Description)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions gen-resourcesdocs/pkg/config/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func (o FakeChapter) Write() error { return nil }

type FakeSection struct{}

func (o FakeSection) AddContent(s string) error { return nil }
func (o FakeSection) AddTypeDefinition(s string) error { return nil }
func (o FakeSection) AddFieldCategory(name string) error { return nil }
func (o FakeSection) AddContent(s string) error { return nil }
func (o FakeSection) AddTypeDefinition(typ string, description string) error { return nil }
func (o FakeSection) AddFieldCategory(name string) error { return nil }

func (o FakeSection) AddProperty(name string, property *kubernetes.Property, linkend []string, indent bool, defname string, shortName string) error {
return nil
Expand Down
2 changes: 1 addition & 1 deletion gen-resourcesdocs/pkg/outputs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Chapter interface {
// Section is an interface to a section of an output
type Section interface {
AddContent(s string) error
AddTypeDefinition(s string) error
AddTypeDefinition(typ string, description string) error
StartPropertyList() error
AddFieldCategory(name string) error
AddProperty(name string, property *kubernetes.Property, linkend []string, indent bool, defname string, shortName string) error
Expand Down
1 change: 1 addition & 0 deletions gen-resourcesdocs/pkg/outputs/kwebsite/chapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type FieldData struct {
Name string
Value string
Description string
Type string
TypeDefinition string
Indent int
}
Expand Down
3 changes: 1 addition & 2 deletions gen-resourcesdocs/pkg/outputs/kwebsite/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func escapeName(parts ...string) string {

// headingID returns the ID built by hugo for a given header
func headingID(s string) string {
result := strings.ToLower(s)
result = strings.ReplaceAll(result, " ", "-")
result := strings.ReplaceAll(s, " ", "-")
return result
}
5 changes: 3 additions & 2 deletions gen-resourcesdocs/pkg/outputs/kwebsite/section.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (o Section) AddContent(s string) error {
}

// AddTypeDefinition adds the definition of a type to a section
func (o Section) AddTypeDefinition(s string) error {
func (o Section) AddTypeDefinition(typ string, description string) error {
i := len(o.chapter.data.Sections)
cats := o.chapter.data.Sections[i-1].FieldCategories
var fields *[]FieldData
Expand All @@ -34,7 +34,8 @@ func (o Section) AddTypeDefinition(s string) error {
fields = &cats[len(cats)-1].Fields
}
j := len(*fields)
(*fields)[j-1].TypeDefinition = "*" + s + "*"
(*fields)[j-1].Type = typ
(*fields)[j-1].TypeDefinition = "*" + description + "*"
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion gen-resourcesdocs/templates/chapter-single-definition.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ weight: {{.Metadata.Weight}}
{{.Description | replace "<" "\\<" | indent 2 | indent .Indent | indent .Indent}}
{{- end}}
{{if .TypeDefinition}}
{{ "" | indent .Indent | indent .Indent}} <a name="{{.Type}}"></a>
{{.TypeDefinition | indent 2 | indent .Indent | indent .Indent}}
{{end}}
{{- end}}{{/* range .Fields */}}

{{range .FieldCategories}}
### {{.Name}}
### {{.Name}} {#{{.Name}}}{{/* explicitly set fragment to keep capitalization */}}

{{range .Fields}}
{{ "" | indent .Indent | indent .Indent}}- {{.Name}}{{if .Value}}: {{.Value}}{{end}}
{{if .Description}}
{{.Description | replace "<" "\\<" | indent 2 | indent .Indent | indent .Indent}}
{{- end}}
{{if .TypeDefinition}}
{{ "" | indent .Indent | indent .Indent}} <a name="{{.Type}}"></a>
{{.TypeDefinition | indent 2 | indent .Indent | indent .Indent}}
{{end}}
{{- end}}{{/* range .Fields */}}
Expand Down
4 changes: 3 additions & 1 deletion gen-resourcesdocs/templates/chapter.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ weight: {{.Metadata.Weight}}
{{if .Import}}`import "{{.Import}}"`{{end}}

{{range .Sections}}
## {{.Name}}
## {{.Name}} {#{{.Name}}}{{/* explicitly set fragment to keep capitalization */}}

{{.Description | replace "<" "\\<" }}

Expand All @@ -24,6 +24,7 @@ weight: {{.Metadata.Weight}}
{{.Description | replace "<" "\\<" | indent 2 | indent .Indent | indent .Indent}}
{{- end}}
{{if .TypeDefinition}}
{{ "" | indent .Indent | indent .Indent}} <a name="{{.Type}}"></a>
{{.TypeDefinition | indent 2 | indent .Indent | indent .Indent}}
{{end}}
{{- end}}{{/* range .Fields */}}
Expand All @@ -37,6 +38,7 @@ weight: {{.Metadata.Weight}}
{{.Description | replace "<" "\\<" | indent 2 | indent .Indent | indent .Indent}}
{{- end}}
{{if .TypeDefinition}}
{{ "" | indent .Indent | indent .Indent}} <a name="{{.Type}}"></a>
{{.TypeDefinition | indent 2 | indent .Indent | indent .Indent}}
{{end}}
{{- end}}{{/* range .Fields */}}
Expand Down

0 comments on commit 6d86d27

Please sign in to comment.