-
Notifications
You must be signed in to change notification settings - Fork 11
/
func_category.go
44 lines (37 loc) · 1.06 KB
/
func_category.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package template
import (
"sort"
)
// FuncCategory represents a group of functions of the same group.
type FuncCategory struct {
name string
functions []string
}
// Name returns the name related to the entry.
func (fc FuncCategory) Name() string { return fc.name }
// Functions returns the list of functions associated with the category.
func (fc FuncCategory) Functions() []string { return fc.functions }
func (t Template) getCategories() []FuncCategory {
categories := make(map[string][]string)
for name := range t.functions {
fi := t.functions[name]
if fi.alias != nil {
fi = *fi.alias
}
categories[fi.group] = append(categories[fi.group], name)
}
categoryList := make([]string, 0, len(categories))
for key := range categories {
categoryList = append(categoryList, key)
}
sort.Strings(categoryList)
result := make([]FuncCategory, len(categoryList))
for i := range categoryList {
sort.Strings(categories[categoryList[i]])
result[i] = FuncCategory{
name: categoryList[i],
functions: categories[categoryList[i]],
}
}
return result
}