Added comma-delimited string attrib type

This commit is contained in:
2019-05-29 22:26:36 -06:00
parent 6f42553a9b
commit 4aacd6e722
5 changed files with 33 additions and 16 deletions

View File

@ -39,6 +39,16 @@ func simpleTemplate(paramType, convertExpr string) string {
`, paramType, conversion)
}
func listTemplate(separator string) string {
return fmt.Sprintf(`func %%s(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "%%s",
Value: strings.Join(value, "%s"),
}
}
`, separator)
}
var attribTypes = map[string]AttribTypeInfo{
"string": {Template: simpleTemplate("string", "%s")},
"bool": {
@ -62,14 +72,12 @@ var attribTypes = map[string]AttribTypeInfo{
Imports: []string{"strconv"},
},
"space list": {
Template: `func %s(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "%s",
Value: strings.Join(value, " "),
}
}
`,
Imports: []string{"strings"},
Template: listTemplate(" "),
Imports: []string{"strings"},
},
"comma list": {
Template: listTemplate(","),
Imports: []string{"strings"},
},
}