Added space-delimited string list attrib type

This commit is contained in:
Brandon Dyck 2019-05-29 21:32:16 -06:00
parent d24afba75c
commit 69b1e1644d
4 changed files with 34 additions and 21 deletions

View File

@ -7,6 +7,8 @@
### Changed ### Changed
- Formatted code identifiers in Changelog - Formatted code identifiers in Changelog
- Attributes `accept-charset`, `class`, `for`, `headers`, `ping`, `rel`, and
`sandbox` have variadic string parameters.
## [0.0.4] - 2019-05-27 ## [0.0.4] - 2019-05-27

View File

@ -4,6 +4,7 @@
package attribute package attribute
import "gitlab.codemonkeysoftware.net/b/hatmill" import "gitlab.codemonkeysoftware.net/b/hatmill"
import "strings"
import "strconv" import "strconv"
// Accept sets the content types or file types allowed in a form or file input. // Accept sets the content types or file types allowed in a form or file input.
@ -15,10 +16,10 @@ func Accept(value string) hatmill.Attrib {
} }
// AcceptCharset creates a "accept-charset" attribute // AcceptCharset creates a "accept-charset" attribute
func AcceptCharset(value string) hatmill.Attrib { func AcceptCharset(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "accept-charset", Key: "accept-charset",
Value: value, Value: strings.Join(value, " "),
} }
} }
@ -99,10 +100,10 @@ func Cite(value string) hatmill.Attrib {
} }
// Class creates a "class" attribute // Class creates a "class" attribute
func Class(value string) hatmill.Attrib { func Class(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "class", Key: "class",
Value: value, Value: strings.Join(value, " "),
} }
} }
@ -247,10 +248,10 @@ func Enctype(value string) hatmill.Attrib {
} }
// For creates a "for" attribute // For creates a "for" attribute
func For(value string) hatmill.Attrib { func For(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "for", Key: "for",
Value: value, Value: strings.Join(value, " "),
} }
} }
@ -279,10 +280,10 @@ func Formmethod(value string) hatmill.Attrib {
} }
// Headers creates a "headers" attribute // Headers creates a "headers" attribute
func Headers(value string) hatmill.Attrib { func Headers(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "headers", Key: "headers",
Value: value, Value: strings.Join(value, " "),
} }
} }
@ -504,10 +505,10 @@ func Pattern(value string) hatmill.Attrib {
} }
// Ping creates a "ping" attribute // Ping creates a "ping" attribute
func Ping(value string) hatmill.Attrib { func Ping(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "ping", Key: "ping",
Value: value, Value: strings.Join(value, " "),
} }
} }
@ -551,10 +552,10 @@ func Referrerpolicy(value string) hatmill.Attrib {
} }
// Rel creates a "rel" attribute // Rel creates a "rel" attribute
func Rel(value string) hatmill.Attrib { func Rel(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "rel", Key: "rel",
Value: value, Value: strings.Join(value, " "),
} }
} }
@ -589,10 +590,10 @@ func Rowspan(value int) hatmill.Attrib {
} }
// Sandbox creates a "sandbox" attribute // Sandbox creates a "sandbox" attribute
func Sandbox(value string) hatmill.Attrib { func Sandbox(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "sandbox", Key: "sandbox",
Value: value, Value: strings.Join(value, " "),
} }
} }

View File

@ -1,7 +1,7 @@
{ {
"attributes": [ "attributes": [
{"name": "accept", "type": "string", "comment": "Accept sets the content types or file types allowed in a form or file input."}, {"name": "accept", "type": "string", "comment": "Accept sets the content types or file types allowed in a form or file input."},
{"name": "accept-charset", "type": "string"}, {"name": "accept-charset", "type": "space list"},
{"name": "action", "type": "string"}, {"name": "action", "type": "string"},
{"name": "alt", "type": "string"}, {"name": "alt", "type": "string"},
{"name": "async", "type": "bool"}, {"name": "async", "type": "bool"},
@ -12,7 +12,7 @@
{"name": "charset", "type": "string"}, {"name": "charset", "type": "string"},
{"name": "checked", "type": "bool"}, {"name": "checked", "type": "bool"},
{"name": "cite", "type": "string"}, {"name": "cite", "type": "string"},
{"name": "class", "type": "string"}, {"name": "class", "type": "space list"},
{"name": "cols", "type": "int"}, {"name": "cols", "type": "int"},
{"name": "colspan", "type": "int"}, {"name": "colspan", "type": "int"},
{"name": "content", "type": "string"}, {"name": "content", "type": "string"},
@ -31,11 +31,11 @@
{"name": "download", "type": "string"}, {"name": "download", "type": "string"},
{"name": "draggable", "type": "explicit bool"}, {"name": "draggable", "type": "explicit bool"},
{"name": "enctype", "type": "string"}, {"name": "enctype", "type": "string"},
{"name": "for", "type": "string"}, {"name": "for", "type": "space list"},
{"name": "form", "type": "string"}, {"name": "form", "type": "string"},
{"name": "formaction", "type": "string"}, {"name": "formaction", "type": "string"},
{"name": "formmethod", "type": "string"}, {"name": "formmethod", "type": "string"},
{"name": "headers", "type": "string"}, {"name": "headers", "type": "space list"},
{"name": "height", "type": "int"}, {"name": "height", "type": "int"},
{"name": "hidden", "type": "bool"}, {"name": "hidden", "type": "bool"},
{"name": "high", "type": "float"}, {"name": "high", "type": "float"},
@ -64,18 +64,18 @@
{"name": "open", "type": "bool"}, {"name": "open", "type": "bool"},
{"name": "optimum", "type": "float"}, {"name": "optimum", "type": "float"},
{"name": "pattern", "type": "string"}, {"name": "pattern", "type": "string"},
{"name": "ping", "type": "string"}, {"name": "ping", "type": "space list"},
{"name": "placeholder", "type": "string"}, {"name": "placeholder", "type": "string"},
{"name": "poster", "type": "string"}, {"name": "poster", "type": "string"},
{"name": "preload", "type": "string"}, {"name": "preload", "type": "string"},
{"name": "readonly", "type": "bool"}, {"name": "readonly", "type": "bool"},
{"name": "referrerpolicy", "type": "string"}, {"name": "referrerpolicy", "type": "string"},
{"name": "rel", "type": "string"}, {"name": "rel", "type": "space list"},
{"name": "required", "type": "bool"}, {"name": "required", "type": "bool"},
{"name": "reversed", "type": "bool"}, {"name": "reversed", "type": "bool"},
{"name": "rows", "type": "int"}, {"name": "rows", "type": "int"},
{"name": "rowspan", "type": "int"}, {"name": "rowspan", "type": "int"},
{"name": "sandbox", "type": "string"}, {"name": "sandbox", "type": "space list"},
{"name": "scope", "type": "string"}, {"name": "scope", "type": "string"},
{"name": "selected", "type": "bool"}, {"name": "selected", "type": "bool"},
{"name": "shape", "type": "string"}, {"name": "shape", "type": "string"},

View File

@ -61,6 +61,16 @@ var attribTypes = map[string]AttribTypeInfo{
Template: simpleTemplate("float32", "strconv.FormatFloat(float64(%s), 'G', -1, 32)"), Template: simpleTemplate("float32", "strconv.FormatFloat(float64(%s), 'G', -1, 32)"),
Imports: []string{"strconv"}, Imports: []string{"strconv"},
}, },
"space list": {
Template: `func %s(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "%s",
Value: strings.Join(value, " "),
}
}
`,
Imports: []string{"strings"},
},
} }
// Def represents a top-level definition and its required imports. // Def represents a top-level definition and its required imports.