From 239ffa7ac2f6e86160f2266bbadfe4f8fdffcb3f Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Sun, 24 Mar 2019 19:56:24 -0600 Subject: [PATCH] Moved HTML5 helpers to subpackage --- example/example.go | 5 +++-- hatmill.go | 10 +--------- htmldefs.go => html5/generated.go | 4 +++- html5/html5.go | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 12 deletions(-) rename htmldefs.go => html5/generated.go (97%) create mode 100644 html5/html5.go diff --git a/example/example.go b/example/example.go index 1971f1d..e22ca84 100644 --- a/example/example.go +++ b/example/example.go @@ -1,7 +1,8 @@ package main import ( - h "gitlab.codemonkeysoftware.net/b/hatmill" + "gitlab.codemonkeysoftware.net/b/hatmill" + h "gitlab.codemonkeysoftware.net/b/hatmill/html5" "os" ) @@ -16,5 +17,5 @@ func main() { ), ), ) - h.WriteDocument(os.Stdout, document) + hatmill.WriteDocument(os.Stdout, document) } diff --git a/hatmill.go b/hatmill.go index 522f2b9..66520ab 100644 --- a/hatmill.go +++ b/hatmill.go @@ -2,7 +2,7 @@ package hatmill import "io" -//go:generate go run ./internal/codegen/codegen.go -input htmldefs.json -output htmldefs.go -package hatmill +//go:generate go run ./internal/codegen/codegen.go -input htmldefs.json -output html5/generated.go -package html5 -import // Term represents a fragment of HTML markup, and is one of EmptyElement, ParentElement, or Text. type Term interface { @@ -121,11 +121,3 @@ 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, - } -} diff --git a/htmldefs.go b/html5/generated.go similarity index 97% rename from htmldefs.go rename to html5/generated.go index 02a5e41..a40339d 100644 --- a/htmldefs.go +++ b/html5/generated.go @@ -1,7 +1,9 @@ // GENERATED BY gitlab.codemonkeysoftware.net/b/hatmill/internal/codegen // DO NOT EDIT! -package hatmill +package html5 + +import . "gitlab.codemonkeysoftware.net/b/hatmill" // Body creates a element. func Body(attribs ...Attrib) func(children ...Term) *ParentElement { diff --git a/html5/html5.go b/html5/html5.go new file mode 100644 index 0000000..3ed436d --- /dev/null +++ b/html5/html5.go @@ -0,0 +1,17 @@ +package html5 + +import "gitlab.codemonkeysoftware.net/b/hatmill" + +// Data creates an attribute of the form "data-suffix='value'". +func Data(suffix, value string) hatmill.Attrib { + return hatmill.Attrib{ + Key: "data-" + suffix, + Value: value, + } +} + +// Text converts a string to a hatmill.Text. Text(s) is functionally identical +// to hatmill.Text(s) and is reproduced here for convenience. +func Text(s string) hatmill.Text { + return hatmill.Text(s) +}