From c9d9cc59bc7396d1285605c456b432f788d18c42 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Thu, 21 Mar 2019 21:58:23 -0600 Subject: [PATCH] Added Data attribute function --- example/example.go | 2 +- hatmill.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/example/example.go b/example/example.go index 16a3d2c..8d87d03 100644 --- a/example/example.go +++ b/example/example.go @@ -12,7 +12,7 @@ func main() { h.Div()( h.Img(h.Src("./me.jpg"), h.Id("profile-photo")), h.Text("hello hatmill!"), - h.Div(h.Disabled())(), + h.Div(h.Disabled(), h.Data("coolness", "awesome"))(), ), ), ) diff --git a/hatmill.go b/hatmill.go index 346de3c..36bd6d8 100644 --- a/hatmill.go +++ b/hatmill.go @@ -122,3 +122,11 @@ func WriteDocument(w io.Writer, root *ParentElement) (n int64, err error) { n += nroot return } + +// Data creates an attribute of the form "data-suffix='value'". +func Data(suffix, value string) Attrib { + return Attrib{ + Key: "data-" + suffix, + Value: value, + } +}