Attrib takes Stringer instead of string

This commit is contained in:
Brandon Dyck 2019-08-31 09:05:43 -06:00
parent daa401817d
commit 0e29901b4f
10 changed files with 116 additions and 94 deletions

View File

@ -5,6 +5,6 @@ import "gitlab.codemonkeysoftware.net/b/hatmill"
func Accesskey(value rune) hatmill.Attrib { func Accesskey(value rune) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "accesskey", Key: "accesskey",
Value: string([]rune{value}), Value: String([]rune{value}),
} }
} }

View File

@ -14,6 +14,6 @@ func Coords(values ...float32) hatmill.Attrib {
} }
return hatmill.Attrib{ return hatmill.Attrib{
Key: "coords", Key: "coords",
Value: strings.Join(s, ","), Value: String(strings.Join(s, ",")),
} }
} }

View File

@ -6,6 +6,6 @@ import "gitlab.codemonkeysoftware.net/b/hatmill"
func CustomData(suffix, value string) hatmill.Attrib { func CustomData(suffix, value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "data-" + suffix, Key: "data-" + suffix,
Value: value, Value: String(value),
} }
} }

View File

@ -11,7 +11,7 @@ import "strconv"
func Accept(value ...string) hatmill.Attrib { func Accept(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "accept", Key: "accept",
Value: strings.Join(value, ","), Value: String(strings.Join(value, ",")),
} }
} }
@ -19,7 +19,7 @@ func Accept(value ...string) hatmill.Attrib {
func AcceptCharset(value ...string) hatmill.Attrib { func AcceptCharset(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "accept-charset", Key: "accept-charset",
Value: strings.Join(value, " "), Value: String(strings.Join(value, " ")),
} }
} }
@ -27,7 +27,7 @@ func AcceptCharset(value ...string) hatmill.Attrib {
func Action(value string) hatmill.Attrib { func Action(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "action", Key: "action",
Value: value, Value: String(value),
} }
} }
@ -35,7 +35,7 @@ func Action(value string) hatmill.Attrib {
func Alt(value string) hatmill.Attrib { func Alt(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "alt", Key: "alt",
Value: value, Value: String(value),
} }
} }
@ -50,7 +50,7 @@ func Async() hatmill.Attrib {
func Autocapitalize(value string) hatmill.Attrib { func Autocapitalize(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "autocapitalize", Key: "autocapitalize",
Value: value, Value: String(value),
} }
} }
@ -58,7 +58,7 @@ func Autocapitalize(value string) hatmill.Attrib {
func Autocomplete(value string) hatmill.Attrib { func Autocomplete(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "autocomplete", Key: "autocomplete",
Value: value, Value: String(value),
} }
} }
@ -80,7 +80,7 @@ func Autoplay() hatmill.Attrib {
func Charset(value string) hatmill.Attrib { func Charset(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "charset", Key: "charset",
Value: value, Value: String(value),
} }
} }
@ -95,7 +95,7 @@ func Checked() hatmill.Attrib {
func Cite(value string) hatmill.Attrib { func Cite(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "cite", Key: "cite",
Value: value, Value: String(value),
} }
} }
@ -103,7 +103,7 @@ func Cite(value string) hatmill.Attrib {
func Class(value ...string) hatmill.Attrib { func Class(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "class", Key: "class",
Value: strings.Join(value, " "), Value: String(strings.Join(value, " ")),
} }
} }
@ -111,7 +111,7 @@ func Class(value ...string) hatmill.Attrib {
func Cols(value int) hatmill.Attrib { func Cols(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "cols", Key: "cols",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -119,7 +119,7 @@ func Cols(value int) hatmill.Attrib {
func Colspan(value int) hatmill.Attrib { func Colspan(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "colspan", Key: "colspan",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -127,7 +127,7 @@ func Colspan(value int) hatmill.Attrib {
func Content(value string) hatmill.Attrib { func Content(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "content", Key: "content",
Value: value, Value: String(value),
} }
} }
@ -135,7 +135,7 @@ func Content(value string) hatmill.Attrib {
func Contenteditable(value bool) hatmill.Attrib { func Contenteditable(value bool) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "contenteditable", Key: "contenteditable",
Value: strconv.FormatBool(value), Value: String(strconv.FormatBool(value)),
} }
} }
@ -143,7 +143,7 @@ func Contenteditable(value bool) hatmill.Attrib {
func Contextmenu(value string) hatmill.Attrib { func Contextmenu(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "contextmenu", Key: "contextmenu",
Value: value, Value: String(value),
} }
} }
@ -158,7 +158,7 @@ func Controls() hatmill.Attrib {
func Crossorigin(value string) hatmill.Attrib { func Crossorigin(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "crossorigin", Key: "crossorigin",
Value: value, Value: String(value),
} }
} }
@ -166,7 +166,7 @@ func Crossorigin(value string) hatmill.Attrib {
func Datetime(value string) hatmill.Attrib { func Datetime(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "datetime", Key: "datetime",
Value: value, Value: String(value),
} }
} }
@ -174,7 +174,7 @@ func Datetime(value string) hatmill.Attrib {
func Decoding(value string) hatmill.Attrib { func Decoding(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "decoding", Key: "decoding",
Value: value, Value: String(value),
} }
} }
@ -196,7 +196,7 @@ func Defer() hatmill.Attrib {
func Dir(value string) hatmill.Attrib { func Dir(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "dir", Key: "dir",
Value: value, Value: String(value),
} }
} }
@ -204,7 +204,7 @@ func Dir(value string) hatmill.Attrib {
func Dirname(value string) hatmill.Attrib { func Dirname(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "dirname", Key: "dirname",
Value: value, Value: String(value),
} }
} }
@ -219,7 +219,7 @@ func Disabled() hatmill.Attrib {
func Download(value string) hatmill.Attrib { func Download(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "download", Key: "download",
Value: value, Value: String(value),
} }
} }
@ -227,7 +227,7 @@ func Download(value string) hatmill.Attrib {
func Draggable(value bool) hatmill.Attrib { func Draggable(value bool) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "draggable", Key: "draggable",
Value: strconv.FormatBool(value), Value: String(strconv.FormatBool(value)),
} }
} }
@ -235,7 +235,7 @@ func Draggable(value bool) hatmill.Attrib {
func Enctype(value string) hatmill.Attrib { func Enctype(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "enctype", Key: "enctype",
Value: value, Value: String(value),
} }
} }
@ -243,7 +243,7 @@ func Enctype(value string) hatmill.Attrib {
func For(value ...string) hatmill.Attrib { func For(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "for", Key: "for",
Value: strings.Join(value, " "), Value: String(strings.Join(value, " ")),
} }
} }
@ -251,7 +251,7 @@ func For(value ...string) hatmill.Attrib {
func Form(value string) hatmill.Attrib { func Form(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "form", Key: "form",
Value: value, Value: String(value),
} }
} }
@ -259,7 +259,7 @@ func Form(value string) hatmill.Attrib {
func Formaction(value string) hatmill.Attrib { func Formaction(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "formaction", Key: "formaction",
Value: value, Value: String(value),
} }
} }
@ -267,7 +267,7 @@ func Formaction(value string) hatmill.Attrib {
func Formmethod(value string) hatmill.Attrib { func Formmethod(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "formmethod", Key: "formmethod",
Value: value, Value: String(value),
} }
} }
@ -275,7 +275,7 @@ func Formmethod(value string) hatmill.Attrib {
func Headers(value ...string) hatmill.Attrib { func Headers(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "headers", Key: "headers",
Value: strings.Join(value, " "), Value: String(strings.Join(value, " ")),
} }
} }
@ -283,7 +283,7 @@ func Headers(value ...string) hatmill.Attrib {
func Height(value int) hatmill.Attrib { func Height(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "height", Key: "height",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -298,7 +298,7 @@ func Hidden() hatmill.Attrib {
func High(value float32) hatmill.Attrib { func High(value float32) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "high", Key: "high",
Value: strconv.FormatFloat(float64(value), 'G', -1, 32), Value: String(strconv.FormatFloat(float64(value), 'G', -1, 32)),
} }
} }
@ -306,7 +306,7 @@ func High(value float32) hatmill.Attrib {
func Href(value string) hatmill.Attrib { func Href(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "href", Key: "href",
Value: value, Value: String(value),
} }
} }
@ -314,7 +314,7 @@ func Href(value string) hatmill.Attrib {
func Hreflang(value string) hatmill.Attrib { func Hreflang(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "hreflang", Key: "hreflang",
Value: value, Value: String(value),
} }
} }
@ -322,7 +322,7 @@ func Hreflang(value string) hatmill.Attrib {
func HttpEquiv(value string) hatmill.Attrib { func HttpEquiv(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "http-equiv", Key: "http-equiv",
Value: value, Value: String(value),
} }
} }
@ -330,7 +330,7 @@ func HttpEquiv(value string) hatmill.Attrib {
func Id(value string) hatmill.Attrib { func Id(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "id", Key: "id",
Value: value, Value: String(value),
} }
} }
@ -345,7 +345,7 @@ func Ismap() hatmill.Attrib {
func Itemprop(value string) hatmill.Attrib { func Itemprop(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "itemprop", Key: "itemprop",
Value: value, Value: String(value),
} }
} }
@ -353,7 +353,7 @@ func Itemprop(value string) hatmill.Attrib {
func Kind(value string) hatmill.Attrib { func Kind(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "kind", Key: "kind",
Value: value, Value: String(value),
} }
} }
@ -361,7 +361,7 @@ func Kind(value string) hatmill.Attrib {
func Label(value string) hatmill.Attrib { func Label(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "label", Key: "label",
Value: value, Value: String(value),
} }
} }
@ -369,7 +369,7 @@ func Label(value string) hatmill.Attrib {
func Lang(value string) hatmill.Attrib { func Lang(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "lang", Key: "lang",
Value: value, Value: String(value),
} }
} }
@ -377,7 +377,7 @@ func Lang(value string) hatmill.Attrib {
func List(value string) hatmill.Attrib { func List(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "list", Key: "list",
Value: value, Value: String(value),
} }
} }
@ -392,7 +392,7 @@ func Loop() hatmill.Attrib {
func Low(value float32) hatmill.Attrib { func Low(value float32) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "low", Key: "low",
Value: strconv.FormatFloat(float64(value), 'G', -1, 32), Value: String(strconv.FormatFloat(float64(value), 'G', -1, 32)),
} }
} }
@ -400,7 +400,7 @@ func Low(value float32) hatmill.Attrib {
func Max(value float32) hatmill.Attrib { func Max(value float32) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "max", Key: "max",
Value: strconv.FormatFloat(float64(value), 'G', -1, 32), Value: String(strconv.FormatFloat(float64(value), 'G', -1, 32)),
} }
} }
@ -408,7 +408,7 @@ func Max(value float32) hatmill.Attrib {
func Maxlength(value int) hatmill.Attrib { func Maxlength(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "maxlength", Key: "maxlength",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -416,7 +416,7 @@ func Maxlength(value int) hatmill.Attrib {
func Media(value string) hatmill.Attrib { func Media(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "media", Key: "media",
Value: value, Value: String(value),
} }
} }
@ -424,7 +424,7 @@ func Media(value string) hatmill.Attrib {
func Method(value string) hatmill.Attrib { func Method(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "method", Key: "method",
Value: value, Value: String(value),
} }
} }
@ -432,7 +432,7 @@ func Method(value string) hatmill.Attrib {
func Min(value float32) hatmill.Attrib { func Min(value float32) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "min", Key: "min",
Value: strconv.FormatFloat(float64(value), 'G', -1, 32), Value: String(strconv.FormatFloat(float64(value), 'G', -1, 32)),
} }
} }
@ -440,7 +440,7 @@ func Min(value float32) hatmill.Attrib {
func Minlength(value int) hatmill.Attrib { func Minlength(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "minlength", Key: "minlength",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -462,7 +462,7 @@ func Muted() hatmill.Attrib {
func Name(value string) hatmill.Attrib { func Name(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "name", Key: "name",
Value: value, Value: String(value),
} }
} }
@ -484,7 +484,7 @@ func Open() hatmill.Attrib {
func Optimum(value float32) hatmill.Attrib { func Optimum(value float32) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "optimum", Key: "optimum",
Value: strconv.FormatFloat(float64(value), 'G', -1, 32), Value: String(strconv.FormatFloat(float64(value), 'G', -1, 32)),
} }
} }
@ -492,7 +492,7 @@ func Optimum(value float32) hatmill.Attrib {
func Pattern(value string) hatmill.Attrib { func Pattern(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "pattern", Key: "pattern",
Value: value, Value: String(value),
} }
} }
@ -500,7 +500,7 @@ func Pattern(value string) hatmill.Attrib {
func Ping(value ...string) hatmill.Attrib { func Ping(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "ping", Key: "ping",
Value: strings.Join(value, " "), Value: String(strings.Join(value, " ")),
} }
} }
@ -508,7 +508,7 @@ func Ping(value ...string) hatmill.Attrib {
func Placeholder(value string) hatmill.Attrib { func Placeholder(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "placeholder", Key: "placeholder",
Value: value, Value: String(value),
} }
} }
@ -516,7 +516,7 @@ func Placeholder(value string) hatmill.Attrib {
func Poster(value string) hatmill.Attrib { func Poster(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "poster", Key: "poster",
Value: value, Value: String(value),
} }
} }
@ -524,7 +524,7 @@ func Poster(value string) hatmill.Attrib {
func Preload(value string) hatmill.Attrib { func Preload(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "preload", Key: "preload",
Value: value, Value: String(value),
} }
} }
@ -539,7 +539,7 @@ func Readonly() hatmill.Attrib {
func Referrerpolicy(value string) hatmill.Attrib { func Referrerpolicy(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "referrerpolicy", Key: "referrerpolicy",
Value: value, Value: String(value),
} }
} }
@ -547,7 +547,7 @@ func Referrerpolicy(value string) hatmill.Attrib {
func Rel(value ...string) hatmill.Attrib { func Rel(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "rel", Key: "rel",
Value: strings.Join(value, " "), Value: String(strings.Join(value, " ")),
} }
} }
@ -569,7 +569,7 @@ func Reversed() hatmill.Attrib {
func Rows(value int) hatmill.Attrib { func Rows(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "rows", Key: "rows",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -577,7 +577,7 @@ func Rows(value int) hatmill.Attrib {
func Rowspan(value int) hatmill.Attrib { func Rowspan(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "rowspan", Key: "rowspan",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -585,7 +585,7 @@ func Rowspan(value int) hatmill.Attrib {
func Sandbox(value ...string) hatmill.Attrib { func Sandbox(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "sandbox", Key: "sandbox",
Value: strings.Join(value, " "), Value: String(strings.Join(value, " ")),
} }
} }
@ -593,7 +593,7 @@ func Sandbox(value ...string) hatmill.Attrib {
func Scope(value string) hatmill.Attrib { func Scope(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "scope", Key: "scope",
Value: value, Value: String(value),
} }
} }
@ -608,7 +608,7 @@ func Selected() hatmill.Attrib {
func Shape(value string) hatmill.Attrib { func Shape(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "shape", Key: "shape",
Value: value, Value: String(value),
} }
} }
@ -616,7 +616,7 @@ func Shape(value string) hatmill.Attrib {
func Size(value int) hatmill.Attrib { func Size(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "size", Key: "size",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -624,7 +624,7 @@ func Size(value int) hatmill.Attrib {
func Sizes(value string) hatmill.Attrib { func Sizes(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "sizes", Key: "sizes",
Value: value, Value: String(value),
} }
} }
@ -632,7 +632,7 @@ func Sizes(value string) hatmill.Attrib {
func Span(value int) hatmill.Attrib { func Span(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "span", Key: "span",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -640,7 +640,7 @@ func Span(value int) hatmill.Attrib {
func Spellcheck(value bool) hatmill.Attrib { func Spellcheck(value bool) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "spellcheck", Key: "spellcheck",
Value: strconv.FormatBool(value), Value: String(strconv.FormatBool(value)),
} }
} }
@ -648,7 +648,7 @@ func Spellcheck(value bool) hatmill.Attrib {
func Src(value string) hatmill.Attrib { func Src(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "src", Key: "src",
Value: value, Value: String(value),
} }
} }
@ -656,7 +656,7 @@ func Src(value string) hatmill.Attrib {
func Srcdoc(value string) hatmill.Attrib { func Srcdoc(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "srcdoc", Key: "srcdoc",
Value: value, Value: String(value),
} }
} }
@ -664,7 +664,7 @@ func Srcdoc(value string) hatmill.Attrib {
func Srclang(value string) hatmill.Attrib { func Srclang(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "srclang", Key: "srclang",
Value: value, Value: String(value),
} }
} }
@ -672,7 +672,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: strings.Join(value, ","), Value: String(strings.Join(value, ",")),
} }
} }
@ -680,7 +680,7 @@ func Srcset(value ...string) hatmill.Attrib {
func Start(value string) hatmill.Attrib { func Start(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "start", Key: "start",
Value: value, Value: String(value),
} }
} }
@ -688,7 +688,7 @@ func Start(value string) hatmill.Attrib {
func Style(value string) hatmill.Attrib { func Style(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "style", Key: "style",
Value: value, Value: String(value),
} }
} }
@ -696,7 +696,7 @@ func Style(value string) hatmill.Attrib {
func Tabindex(value int) hatmill.Attrib { func Tabindex(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "tabindex", Key: "tabindex",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -704,7 +704,7 @@ func Tabindex(value int) hatmill.Attrib {
func Target(value string) hatmill.Attrib { func Target(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "target", Key: "target",
Value: value, Value: String(value),
} }
} }
@ -712,7 +712,7 @@ func Target(value string) hatmill.Attrib {
func Title(value string) hatmill.Attrib { func Title(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "title", Key: "title",
Value: value, Value: String(value),
} }
} }
@ -720,7 +720,7 @@ func Title(value string) hatmill.Attrib {
func Type(value string) hatmill.Attrib { func Type(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "type", Key: "type",
Value: value, Value: String(value),
} }
} }
@ -728,7 +728,7 @@ func Type(value string) hatmill.Attrib {
func Usemap(value string) hatmill.Attrib { func Usemap(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "usemap", Key: "usemap",
Value: value, Value: String(value),
} }
} }
@ -736,7 +736,7 @@ func Usemap(value string) hatmill.Attrib {
func Value(value string) hatmill.Attrib { func Value(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "value", Key: "value",
Value: value, Value: String(value),
} }
} }
@ -744,7 +744,7 @@ func Value(value string) hatmill.Attrib {
func Width(value int) hatmill.Attrib { func Width(value int) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "width", Key: "width",
Value: strconv.FormatInt(int64(value), 10), Value: String(strconv.FormatInt(int64(value), 10)),
} }
} }
@ -752,6 +752,6 @@ func Width(value int) hatmill.Attrib {
func Wrap(value string) hatmill.Attrib { func Wrap(value string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "wrap", Key: "wrap",
Value: value, Value: String(value),
} }
} }

View File

@ -9,8 +9,8 @@ import (
func testAttribValue(t *testing.T, attrib hatmill.Attrib, expectedValue string) { func testAttribValue(t *testing.T, attrib hatmill.Attrib, expectedValue string) {
t.Helper() t.Helper()
if attrib.Value != expectedValue { if attrib.ValueString() != expectedValue {
t.Fatalf("expected attribute value to be %#v, but got %#v", expectedValue, attrib.Value) t.Fatalf("expected attribute value to be %#v, but got %#v", expectedValue, attrib.ValueString())
} }
} }

View File

@ -17,9 +17,9 @@ func StepFloat(value float32) StepValue {
func Step(value StepValue) hatmill.Attrib { func Step(value StepValue) hatmill.Attrib {
var attr = hatmill.Attrib{Key: "step"} var attr = hatmill.Attrib{Key: "step"}
if value == nil { if value == nil {
attr.Value = "any" attr.Value = String("any")
} else { } else {
attr.Value = strconv.FormatFloat(float64(*value), 'G', -1, 32) attr.Value = String(strconv.FormatFloat(float64(*value), 'G', -1, 32))
} }
return attr return attr
} }

7
attribute/string.go Normal file
View File

@ -0,0 +1,7 @@
package attribute
type String string
func (s String) String() string {
return string(s)
}

View File

@ -3,6 +3,7 @@ package hatmill
//go:generate go run internal/codegen/codegen.go -input defs.json -elemfile element/generated.go -elempkg element -attribfile attribute/generated.go -attribpkg attribute //go:generate go run internal/codegen/codegen.go -input defs.json -elemfile element/generated.go -elempkg element -attribfile attribute/generated.go -attribpkg attribute
import ( import (
"bytes" "bytes"
"fmt"
"html" "html"
"io" "io"
) )
@ -32,7 +33,14 @@ func writeStringsTo(w io.Writer, n *int64, ss ...string) error {
// Attrib represents an HTML attribute. // Attrib represents an HTML attribute.
type Attrib struct { type Attrib struct {
Key string Key string
Value string Value fmt.Stringer
}
func (a Attrib) ValueString() string {
if a.Value == nil {
return ""
}
return html.EscapeString(a.Value.String())
} }
// WriteTo writes a to w as an HTML attribute in the form key="value", or // WriteTo writes a to w as an HTML attribute in the form key="value", or
@ -44,9 +52,8 @@ func (a Attrib) WriteTo(w io.Writer) (n int64, err error) {
if err != nil { if err != nil {
return return
} }
if a.Value != "" { if a.ValueString() != "" {
escaped := html.EscapeString(a.Value) err = writeStringsTo(w, &n, "='", a.ValueString(), "'")
err = writeStringsTo(w, &n, "='", escaped, "'")
} }
return return
} }

View File

@ -70,10 +70,18 @@ func stringNotEmpty(v interface{}) bool {
var nonEmptyAlphaString = gen.AlphaString().SuchThat(stringNotEmpty) var nonEmptyAlphaString = gen.AlphaString().SuchThat(stringNotEmpty)
type valueString string
func (s valueString) String() string {
return string(s)
}
func attribGen(value gopter.Gen) gopter.Gen { func attribGen(value gopter.Gen) gopter.Gen {
return gen.Struct(reflect.TypeOf(hatmill.Attrib{}), map[string]gopter.Gen{ return gen.Struct(reflect.TypeOf(hatmill.Attrib{}), map[string]gopter.Gen{
"Key": nonEmptyAlphaString, "Key": nonEmptyAlphaString,
"Value": value, "Value": value.Map(func(v string) fmt.Stringer {
return valueString(v)
}),
}) })
} }
@ -90,9 +98,9 @@ func TestAttrib(t *testing.T) {
nonEmptyAlphaString, nonEmptyAlphaString,
)) ))
properties.Property("writes key=value with escaped value when value is not empty", prop.ForAll( properties.Property("writes key=value with ValueString() when value is not empty", prop.ForAll(
func(attrib hatmill.Attrib) bool { func(attrib hatmill.Attrib) bool {
expected := fmt.Sprintf("%s='%s'", attrib.Key, html.EscapeString(attrib.Value)) expected := fmt.Sprintf("%s='%s'", attrib.Key, attrib.ValueString())
return checkWrite(attrib, expected) return checkWrite(attrib, expected)
}, },
attribGen(dangerousASCII.SuchThat(stringNotEmpty)), attribGen(dangerousASCII.SuchThat(stringNotEmpty)),

View File

@ -29,7 +29,7 @@ func simpleTemplate(paramType, convertExpr string) string {
return fmt.Sprintf(`func %%s(value %s) hatmill.Attrib { return fmt.Sprintf(`func %%s(value %s) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "%%s", Key: "%%s",
Value: %s, Value: String(%s),
} }
} }
`, paramType, conversion) `, paramType, conversion)
@ -39,7 +39,7 @@ func listTemplate(separator string) string {
return fmt.Sprintf(`func %%s(value ...string) hatmill.Attrib { return fmt.Sprintf(`func %%s(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "%%s", Key: "%%s",
Value: strings.Join(value, "%s"), Value: String(strings.Join(value, "%s")),
} }
} }
`, separator) `, separator)