Moved HTML5 helpers to subpackage

This commit is contained in:
Brandon Dyck 2019-03-24 19:56:24 -06:00
parent e5b056c1c1
commit 239ffa7ac2
4 changed files with 24 additions and 12 deletions

View File

@ -1,7 +1,8 @@
package main package main
import ( import (
h "gitlab.codemonkeysoftware.net/b/hatmill" "gitlab.codemonkeysoftware.net/b/hatmill"
h "gitlab.codemonkeysoftware.net/b/hatmill/html5"
"os" "os"
) )
@ -16,5 +17,5 @@ func main() {
), ),
), ),
) )
h.WriteDocument(os.Stdout, document) hatmill.WriteDocument(os.Stdout, document)
} }

View File

@ -2,7 +2,7 @@ package hatmill
import "io" 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. // Term represents a fragment of HTML markup, and is one of EmptyElement, ParentElement, or Text.
type Term interface { type Term interface {
@ -121,11 +121,3 @@ func WriteDocument(w io.Writer, root *ParentElement) (n int64, err error) {
n += nroot n += nroot
return return
} }
// Data creates an attribute of the form "data-suffix='value'".
func Data(suffix, value string) Attrib {
return Attrib{
Key: "data-" + suffix,
Value: value,
}
}

View File

@ -1,7 +1,9 @@
// GENERATED BY gitlab.codemonkeysoftware.net/b/hatmill/internal/codegen // GENERATED BY gitlab.codemonkeysoftware.net/b/hatmill/internal/codegen
// DO NOT EDIT! // DO NOT EDIT!
package hatmill package html5
import . "gitlab.codemonkeysoftware.net/b/hatmill"
// Body creates a <body> element. // Body creates a <body> element.
func Body(attribs ...Attrib) func(children ...Term) *ParentElement { func Body(attribs ...Attrib) func(children ...Term) *ParentElement {

17
html5/html5.go Normal file
View File

@ -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)
}