-
Notifications
You must be signed in to change notification settings - Fork 3
/
template.go
83 lines (70 loc) · 2.74 KB
/
template.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package doccompiler
import (
"sort"
"strings"
"text/template"
)
var FuncMap = template.FuncMap{
"params": SortedParamsKeys,
"join": strings.Join,
}
// SortedParamsKeys returns map keys as a sorted slice
func SortedParamsKeys(paramsMap map[string][]string) []string {
params := make([]string, 0, len(paramsMap))
for param := range paramsMap {
params = append(params, param)
}
sort.Strings(params)
return params
}
// TemplateStr used to generate in memory documentation golang package
const TemplateStr = `package generated
/*
This file has been generated, do not edit the file directly.
Generate with go run ./generatedocs/compile/main.go or by running go generate in gopherciser root project.
*/
import "github.com/qlik-oss/gopherciser/generatedocs/pkg/common"
{{with $data := .}}
var (
{{/* Loop over action slice instead of map in order to keep order consistent */}}
Actions = map[string]common.DocEntry{ {{range $action := $data.Actions}}{{with $actionEntry := index $data.ActionMap $action}}
"{{$action}}": {
Description: "{{$actionEntry.Description}}",
Examples: "{{$actionEntry.Examples}}",
},{{end}}{{end}}
}
Schedulers = map[string]common.DocEntry{ {{range $scheduler := $data.Schedulers}}{{with $schedulerEntry := index $data.SchedulerMap $scheduler}}
"{{$scheduler}}": {
Description: "{{$schedulerEntry.Description}}",
Examples: "{{$schedulerEntry.Examples}}",
},{{end}}{{end}}
}
Params = map[string][]string{ {{range $param := params $data.ParamMap}}
"{{.}}": { "{{join (index $data.ParamMap $param) "\",\""}}" }, {{end}}
}
{{/* Loop over config fields slice instead of map in order to keep order consistent */}}
Config = map[string]common.DocEntry{ {{range $field := $data.ConfigFields}}{{with $configEntry := index $data.ConfigMap $field}}
"{{$field}}" : {
Description: "{{$configEntry.Description}}",
Examples: "{{$configEntry.Examples}}",
},{{end}}{{end}}
}
Groups = []common.GroupsEntry{ {{range $group := $data.Groups}}
{
Name: "{{$group.Name}}",
Title: "{{$group.Title}}",
Actions: []string{ "{{join $group.Actions "\",\""}}" },
DocEntry: common.DocEntry{
Description: "{{$group.Description}}",
Examples: "{{$group.Examples}}",
},
},{{end}}
}
Extra = map[string]common.DocEntry{ {{range $extra := $data.Extra}}{{with $extraEntry := index $data.ExtraMap $extra}}
"{{$extra}}": {
Description: "{{$extraEntry.Description}}",
Examples: "{{$extraEntry.Examples}}",
},{{end}}{{end}}
}
){{end}}
`