-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathdocumentation.tpl
More file actions
122 lines (118 loc) Β· 3.37 KB
/
documentation.tpl
File metadata and controls
122 lines (118 loc) Β· 3.37 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{{- define "param" }}
{{ .Name }}:{{ if .Value }} {{ .Value }}{{ end }}
{{- range .Values }}
- {{ . }}
{{- end }}
{{- $unit := .Unit -}}
{{- $description := localize .Description | replace "\n" " " | trim -}}
{{- $help := localize .Help | replace "\n" " " | trim -}}
{{- $choices := join ", " .Choice -}}
{{- $optional := not .IsRequired -}}
{{- if or $help $choices $optional $description }} # {{end}}
{{- if $description }}{{ $description }}
{{- if $unit }} ({{ $unit }}){{- end }}
{{- if or $help $choices $optional }}, {{end}}
{{- end}}
{{- if $help }}{{ $help }} {{end}}
{{- if $choices }}[{{ $choices }}] {{end}}
{{- if $optional }}
{{- if or $help $choices }}(optional){{ else }}optional{{end }}
{{- end }}
{{- end }}
{{- define "header" }}
type: template
template: {{ .Template }}
{{- if hasKey . "Usage" }}
usage: {{ .Usage }}
{{- end }}
{{- end }}
{{- define "default" }}
{{- include "header" . }}
{{- $usage := "" }}{{ if hasKey . "Usage" }}{{ $usage = .Usage }}{{ end }}
{{- range .Params }}
{{- if eq .Name "modbus" }}
{{- $.Modbus | indent 2 }}
{{- else if and (not .IsAdvanced) (or (not $usage) (not .Usages) (has $usage .Usages)) }}
{{- template "param" . }}
{{- end }}
{{- end }}
{{- end }}
{{- define "advanced" }}
{{- include "header" . }}
{{- $usage := "" }}{{ if hasKey . "Usage" }}{{ $usage = .Usage }}{{ end }}
{{- range .Params }}
{{- if eq .Name "modbus" }}
{{- $.Modbus | indent 2 }}
{{- else if or (not $usage) (not .Usages) (has $usage .Usages) }}
{{- template "param" . }}
{{- end }}
{{- end }}
{{- end -}}
template: {{ .Template }}
product:
identifier: {{ .ProductIdentifier }}
{{- if .ProductBrand }}
brand: {{ .ProductBrand }}
{{- end }}
{{- if .ProductDescription }}
description: {{ .ProductDescription }}
{{- end }}
{{- if .ProductGroup }}
group: {{ .ProductGroup }}
{{- end }}
{{- if .Capabilities }}
capabilities: ["{{ join "\", \"" .Capabilities }}"]
{{- end }}
{{- if .Countries }}
countries: ["{{ join "\", \"" .Countries }}"]
{{- end }}
{{- if .Requirements }}
requirements: ["{{ join "\", \"" .Requirements }}"]
{{- end }}
{{- if .RequirementDescription }}
description: |
{{ .RequirementDescription | indent 2 }}
{{- end }}
render:
{{- if .Usages -}}
{{- $content := . }}
{{- range $usage := .Usages }}
{{- $_ := set $content "Usage" $usage }}
- usage: {{ $usage }}
default: |
{{- include "default" $content | indent 4 }}
{{- if $.AdvancedParams }}
advanced: |
{{- include "advanced" $content | indent 4 }}
{{- end }}
{{- end }}
{{- else }}
- default: |
{{- include "default" . | indent 4 }}
{{- if $.AdvancedParams }}
advanced: |
{{- include "advanced" . | indent 4 }}
{{- end }}
{{- end }}
params:
{{- range .Params }}
{{- if and (not (eq .Name "usage")) (not .IsDeprecated) }}
- name: {{ .Name | quote }}
example: {{ .Example | quote }}
default: {{ .Default }}
choice: [{{ join ", " .Choice }}]
unit: {{ .Unit }}
{{- $description := localize .Description | replace "\n" " " | trim }}
description: {{ $description | quote }}
{{- $help := localize .Help | replace "\n" " " | trim }}
help: {{ $help | quote }}
advanced: {{ .IsAdvanced }}
optional: {{ not .IsRequired }}
{{- end }}
{{- end }}
{{- if .ModbusData }}
modbus:
{{- range $key, $value := .ModbusData }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}