diff --git a/attribute/generated.go b/attribute/generated.go index 9b5b083..7177b30 100644 --- a/attribute/generated.go +++ b/attribute/generated.go @@ -4,14 +4,13 @@ package attribute import "gitlab.codemonkeysoftware.net/b/hatmill" -import "strings" import "strconv" // Accept creates a "accept" attribute func Accept(value ...string) hatmill.Attrib { return hatmill.Attrib{ 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 { return hatmill.Attrib{ Key: "srcset", - Value: String(strings.Join(value, ",")), + Value: String(CommaList(value).String()), } } diff --git a/attribute/generated_test.go b/attribute/generated_test.go index 34b06fc..a988952 100644 --- a/attribute/generated_test.go +++ b/attribute/generated_test.go @@ -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) { const s = "abcdefg" testAttribValue(t, attribute.Id(s), s) diff --git a/attribute/value_types.go b/attribute/value_types.go index 761f331..a66604f 100644 --- a/attribute/value_types.go +++ b/attribute/value_types.go @@ -7,3 +7,9 @@ type SpaceList []string func (l SpaceList) String() string { return strings.Join(l, " ") } + +type CommaList []string + +func (l CommaList) String() string { + return strings.Join(l, ",") +} diff --git a/attribute/value_types_test.go b/attribute/value_types_test.go index cef5d75..f5ed050 100644 --- a/attribute/value_types_test.go +++ b/attribute/value_types_test.go @@ -22,3 +22,15 @@ func TestSpaceList(t *testing.T) { 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) + }) +} diff --git a/internal/codegen/codegen.go b/internal/codegen/codegen.go index 3db45dd..6b79ce9 100644 --- a/internal/codegen/codegen.go +++ b/internal/codegen/codegen.go @@ -71,8 +71,7 @@ var attribTypes = map[string]AttribTypeInfo{ Template: simpleTemplate("...string", "SpaceList(%s).String()"), }, "comma list": { - Template: listTemplate(","), - Imports: []string{"strings"}, + Template: simpleTemplate("...string", "CommaList(%s).String()"), }, }