Created CommaList type
This commit is contained in:
parent
287d0036f3
commit
276c0f9c0e
@ -4,14 +4,13 @@
|
|||||||
package attribute
|
package attribute
|
||||||
|
|
||||||
import "gitlab.codemonkeysoftware.net/b/hatmill"
|
import "gitlab.codemonkeysoftware.net/b/hatmill"
|
||||||
import "strings"
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
// Accept creates a "accept" attribute
|
// Accept creates a "accept" attribute
|
||||||
func Accept(value ...string) hatmill.Attrib {
|
func Accept(value ...string) hatmill.Attrib {
|
||||||
return hatmill.Attrib{
|
return hatmill.Attrib{
|
||||||
Key: "accept",
|
Key: "accept",
|
||||||
Value: String(strings.Join(value, ",")),
|
Value: String(CommaList(value).String()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -672,7 +671,7 @@ func Srclang(value string) hatmill.Attrib {
|
|||||||
func Srcset(value ...string) hatmill.Attrib {
|
func Srcset(value ...string) hatmill.Attrib {
|
||||||
return hatmill.Attrib{
|
return hatmill.Attrib{
|
||||||
Key: "srcset",
|
Key: "srcset",
|
||||||
Value: String(strings.Join(value, ",")),
|
Value: String(CommaList(value).String()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,15 +14,6 @@ func testAttribValue(t *testing.T, attrib hatmill.Attrib, expectedValue string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -7,3 +7,9 @@ type SpaceList []string
|
|||||||
func (l SpaceList) String() string {
|
func (l SpaceList) String() string {
|
||||||
return strings.Join(l, " ")
|
return strings.Join(l, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CommaList []string
|
||||||
|
|
||||||
|
func (l CommaList) String() string {
|
||||||
|
return strings.Join(l, ",")
|
||||||
|
}
|
||||||
|
@ -22,3 +22,15 @@ func TestSpaceList(t *testing.T) {
|
|||||||
expectEqualStrings(t, actual, expected)
|
expectEqualStrings(t, actual, expected)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCommaList(t *testing.T) {
|
||||||
|
t.Run("empty", func(t *testing.T) {
|
||||||
|
expectEqualStrings(t, attribute.CommaList{}.String(), "")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("nonempty", func(t *testing.T) {
|
||||||
|
expected := "alpha,bravo,charlie"
|
||||||
|
actual := attribute.CommaList{"alpha", "bravo", "charlie"}.String()
|
||||||
|
expectEqualStrings(t, actual, expected)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -71,8 +71,7 @@ var attribTypes = map[string]AttribTypeInfo{
|
|||||||
Template: simpleTemplate("...string", "SpaceList(%s).String()"),
|
Template: simpleTemplate("...string", "SpaceList(%s).String()"),
|
||||||
},
|
},
|
||||||
"comma list": {
|
"comma list": {
|
||||||
Template: listTemplate(","),
|
Template: simpleTemplate("...string", "CommaList(%s).String()"),
|
||||||
Imports: []string{"strings"},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user