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
- 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

View File

@ -4,6 +4,7 @@
package attribute
import "gitlab.codemonkeysoftware.net/b/hatmill"
import "strings"
import "strconv"
// 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
func AcceptCharset(value string) hatmill.Attrib {
func AcceptCharset(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "accept-charset",
Value: value,
Value: strings.Join(value, " "),
}
}
@ -99,10 +100,10 @@ func Cite(value string) hatmill.Attrib {
}
// Class creates a "class" attribute
func Class(value string) hatmill.Attrib {
func Class(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "class",
Value: value,
Value: strings.Join(value, " "),
}
}
@ -247,10 +248,10 @@ func Enctype(value string) hatmill.Attrib {
}
// For creates a "for" attribute
func For(value string) hatmill.Attrib {
func For(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "for",
Value: value,
Value: strings.Join(value, " "),
}
}
@ -279,10 +280,10 @@ func Formmethod(value string) hatmill.Attrib {
}
// Headers creates a "headers" attribute
func Headers(value string) hatmill.Attrib {
func Headers(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "headers",
Value: value,
Value: strings.Join(value, " "),
}
}
@ -504,10 +505,10 @@ func Pattern(value string) hatmill.Attrib {
}
// Ping creates a "ping" attribute
func Ping(value string) hatmill.Attrib {
func Ping(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "ping",
Value: value,
Value: strings.Join(value, " "),
}
}
@ -551,10 +552,10 @@ func Referrerpolicy(value string) hatmill.Attrib {
}
// Rel creates a "rel" attribute
func Rel(value string) hatmill.Attrib {
func Rel(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "rel",
Value: value,
Value: strings.Join(value, " "),
}
}
@ -589,10 +590,10 @@ func Rowspan(value int) hatmill.Attrib {
}
// Sandbox creates a "sandbox" attribute
func Sandbox(value string) hatmill.Attrib {
func Sandbox(value ...string) hatmill.Attrib {
return hatmill.Attrib{
Key: "sandbox",
Value: value,
Value: strings.Join(value, " "),
}
}

View File

@ -1,7 +1,7 @@
{
"attributes": [
{"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": "alt", "type": "string"},
{"name": "async", "type": "bool"},
@ -12,7 +12,7 @@
{"name": "charset", "type": "string"},
{"name": "checked", "type": "bool"},
{"name": "cite", "type": "string"},
{"name": "class", "type": "string"},
{"name": "class", "type": "space list"},
{"name": "cols", "type": "int"},
{"name": "colspan", "type": "int"},
{"name": "content", "type": "string"},
@ -31,11 +31,11 @@
{"name": "download", "type": "string"},
{"name": "draggable", "type": "explicit bool"},
{"name": "enctype", "type": "string"},
{"name": "for", "type": "string"},
{"name": "for", "type": "space list"},
{"name": "form", "type": "string"},
{"name": "formaction", "type": "string"},
{"name": "formmethod", "type": "string"},
{"name": "headers", "type": "string"},
{"name": "headers", "type": "space list"},
{"name": "height", "type": "int"},
{"name": "hidden", "type": "bool"},
{"name": "high", "type": "float"},
@ -64,18 +64,18 @@
{"name": "open", "type": "bool"},
{"name": "optimum", "type": "float"},
{"name": "pattern", "type": "string"},
{"name": "ping", "type": "string"},
{"name": "ping", "type": "space list"},
{"name": "placeholder", "type": "string"},
{"name": "poster", "type": "string"},
{"name": "preload", "type": "string"},
{"name": "readonly", "type": "bool"},
{"name": "referrerpolicy", "type": "string"},
{"name": "rel", "type": "string"},
{"name": "rel", "type": "space list"},
{"name": "required", "type": "bool"},
{"name": "reversed", "type": "bool"},
{"name": "rows", "type": "int"},
{"name": "rowspan", "type": "int"},
{"name": "sandbox", "type": "string"},
{"name": "sandbox", "type": "space list"},
{"name": "scope", "type": "string"},
{"name": "selected", "type": "bool"},
{"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)"),
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.