From 69b1e1644db1e274cfba7de32e4d1676f580f85d Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Wed, 29 May 2019 21:32:16 -0600 Subject: [PATCH] Added space-delimited string list attrib type --- CHANGELOG.md | 2 ++ attribute/generated.go | 29 +++++++++++++++-------------- defs.json | 14 +++++++------- internal/codegen/codegen.go | 10 ++++++++++ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f010b5..8700131 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/attribute/generated.go b/attribute/generated.go index a7f92a8..17e9a9b 100644 --- a/attribute/generated.go +++ b/attribute/generated.go @@ -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, " "), } } diff --git a/defs.json b/defs.json index e5ea8dc..f5a18d6 100644 --- a/defs.json +++ b/defs.json @@ -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"}, diff --git a/internal/codegen/codegen.go b/internal/codegen/codegen.go index 280af0f..9e43cd2 100644 --- a/internal/codegen/codegen.go +++ b/internal/codegen/codegen.go @@ -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.