Skip to content

Commit

Permalink
Sort references (#2)
Browse files Browse the repository at this point in the history
* Sort references

* Move sorting to method call

* Add build status
  • Loading branch information
charith-elastic committed Feb 18, 2020
1 parent 4fa7899 commit bdc856d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
![](https://github.com/elastic/crd-ref-docs/workflows/Build/badge.svg)


CRD Reference Documentation Generator
======================================

Expand Down
2 changes: 1 addition & 1 deletion templates/asciidoctor/type.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{ if $type.References -}}
.Appears In:
****
{{- range $type.References }}
{{- range $type.SortedReferences }}
- {{ asciidocRenderTypeLink . }}
{{- end }}
****
Expand Down
20 changes: 20 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@ func (t *Type) IsAlias() bool {
return t.Kind == AliasKind
}

func (t *Type) SortedReferences() []*Type {
if t == nil || len(t.References) == 0 {
return nil
}

sort.Slice(t.References, func(i, j int) bool {
if t.References[i].Name < t.References[j].Name {
return true
}

if t.References[i].Name == t.References[j].Name {
return t.References[i].Package < t.References[j].Package
}

return false
})

return t.References
}

// Field describes a field in a struct.
type Field struct {
Name string
Expand Down

0 comments on commit bdc856d

Please sign in to comment.