-
Notifications
You must be signed in to change notification settings - Fork 10
/
editModelObject.go
48 lines (36 loc) · 1.2 KB
/
editModelObject.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
package step
import (
"text/template"
"github.com/benpate/derp"
"github.com/benpate/form"
"github.com/benpate/rosetta/mapof"
)
// EditModelObject is an action that can add new sub-streams to the domain.
type EditModelObject struct {
Form form.Element
Options []*template.Template
}
// NewEditModelObject returns a fully initialized EditModelObject record
func NewEditModelObject(stepInfo mapof.Any) (EditModelObject, error) {
// Parse the form definition
f, err := form.Parse(stepInfo.GetAny("form"))
if err != nil {
return EditModelObject{}, derp.Wrap(err, "model.step.NewEditModelObject", "Invalid 'form'", stepInfo)
}
// Parse options
options := stepInfo.GetSliceOfString("options")
optionTemplates := make([]*template.Template, len(options))
for index, option := range options {
template, err := template.New("option").Parse(option)
if err != nil {
return EditModelObject{}, derp.Wrap(err, "model.step.NewEditModelObject", "Invalid 'options'", stepInfo)
}
optionTemplates[index] = template
}
return EditModelObject{
Form: f,
Options: optionTemplates,
}, nil
}
// AmStep is here only to verify that this struct is a build pipeline step
func (step EditModelObject) AmStep() {}