-
Notifications
You must be signed in to change notification settings - Fork 36
/
complex.go
61 lines (48 loc) · 1.04 KB
/
complex.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
package main
import (
"bytes"
_ "embed"
"text/template"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
//go:embed tmpl/complex.tmpl
var complexTmpl string
var complexTemplate = template.Must(template.New("complex").Funcs(
template.FuncMap{
"bt": func() string { return "`" },
}).Parse(complexTmpl))
type Variable struct {
Name string
Type string
Pointer bool
Multiple bool
Required bool
}
func (v Variable) Title() string {
return cases.Title(language.English).String(v.Name)
}
func (v Variable) Optional() bool {
return !v.Required
}
type Complex struct {
Package string
Name string
Derived *Variable
Builtin *Variable
Attributes []Variable
Variables []Variable
}
func (c Complex) Title() string {
return cases.Title(language.English).String(c.Name)
}
func (c Complex) Render() ([]byte, error) {
var buf bytes.Buffer
if err := complexTemplate.Execute(&buf, c); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func (c Complex) RenderFile(path string) error {
return RenderFile(path, c)
}