Added comma-delimited string attrib type
This commit is contained in:
parent
6f42553a9b
commit
4aacd6e722
@ -10,8 +10,8 @@
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Formatted code identifiers in Changelog
|
- Formatted code identifiers in Changelog
|
||||||
- Attributes `accept-charset`, `class`, `for`, `headers`, `ping`, `rel`, and
|
- Attributes `accept`, `accept-charset`, `class`, `for`, `headers`, `ping`,
|
||||||
`sandbox` have variadic string parameters.
|
`rel`, `srcset`, and `sandbox` have variadic string parameters.
|
||||||
|
|
||||||
## [0.0.4] - 2019-05-27
|
## [0.0.4] - 2019-05-27
|
||||||
|
|
||||||
|
@ -8,10 +8,10 @@ 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.
|
||||||
func Accept(value string) hatmill.Attrib {
|
func Accept(value ...string) hatmill.Attrib {
|
||||||
return hatmill.Attrib{
|
return hatmill.Attrib{
|
||||||
Key: "accept",
|
Key: "accept",
|
||||||
Value: value,
|
Value: strings.Join(value, ","),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,10 +677,10 @@ func Srclang(value string) hatmill.Attrib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Srcset creates a "srcset" attribute
|
// Srcset creates a "srcset" attribute
|
||||||
func Srcset(value string) hatmill.Attrib {
|
func Srcset(value ...string) hatmill.Attrib {
|
||||||
return hatmill.Attrib{
|
return hatmill.Attrib{
|
||||||
Key: "srcset",
|
Key: "srcset",
|
||||||
Value: value,
|
Value: strings.Join(value, ","),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,15 @@ func TestSpaceList(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCommaList(t *testing.T) {
|
||||||
|
t.Run("empty", func(t *testing.T) {
|
||||||
|
testAttribValue(t, attribute.Class(), "")
|
||||||
|
})
|
||||||
|
t.Run("nonempty", func(t *testing.T) {
|
||||||
|
testAttribValue(t, attribute.Accept("alpha", "bravo", "charlie"), "alpha,bravo,charlie")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestString(t *testing.T) {
|
func TestString(t *testing.T) {
|
||||||
const s = "abcdefg"
|
const s = "abcdefg"
|
||||||
testAttribValue(t, attribute.Id(s), s)
|
testAttribValue(t, attribute.Id(s), s)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"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": "comma list", "comment": "Accept sets the content types or file types allowed in a form or file input."},
|
||||||
{"name": "accept-charset", "type": "space list"},
|
{"name": "accept-charset", "type": "space list"},
|
||||||
{"name": "action", "type": "string"},
|
{"name": "action", "type": "string"},
|
||||||
{"name": "alt", "type": "string"},
|
{"name": "alt", "type": "string"},
|
||||||
@ -86,7 +86,7 @@
|
|||||||
{"name": "src", "type": "string"},
|
{"name": "src", "type": "string"},
|
||||||
{"name": "srcdoc", "type": "string"},
|
{"name": "srcdoc", "type": "string"},
|
||||||
{"name": "srclang", "type": "string"},
|
{"name": "srclang", "type": "string"},
|
||||||
{"name": "srcset", "type": "string"},
|
{"name": "srcset", "type": "comma list"},
|
||||||
{"name": "start", "type": "string"},
|
{"name": "start", "type": "string"},
|
||||||
{"name": "style", "type": "string"},
|
{"name": "style", "type": "string"},
|
||||||
{"name": "tabindex", "type": "int"},
|
{"name": "tabindex", "type": "int"},
|
||||||
|
@ -39,6 +39,16 @@ func simpleTemplate(paramType, convertExpr string) string {
|
|||||||
`, paramType, conversion)
|
`, 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{
|
var attribTypes = map[string]AttribTypeInfo{
|
||||||
"string": {Template: simpleTemplate("string", "%s")},
|
"string": {Template: simpleTemplate("string", "%s")},
|
||||||
"bool": {
|
"bool": {
|
||||||
@ -62,14 +72,12 @@ var attribTypes = map[string]AttribTypeInfo{
|
|||||||
Imports: []string{"strconv"},
|
Imports: []string{"strconv"},
|
||||||
},
|
},
|
||||||
"space list": {
|
"space list": {
|
||||||
Template: `func %s(value ...string) hatmill.Attrib {
|
Template: listTemplate(" "),
|
||||||
return hatmill.Attrib{
|
Imports: []string{"strings"},
|
||||||
Key: "%s",
|
},
|
||||||
Value: strings.Join(value, " "),
|
"comma list": {
|
||||||
}
|
Template: listTemplate(","),
|
||||||
}
|
Imports: []string{"strings"},
|
||||||
`,
|
|
||||||
Imports: []string{"strings"},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user