Moved example, Data, and Text into html5 package
This commit is contained in:
@ -3,13 +3,13 @@
|
||||
|
||||
package html5
|
||||
|
||||
import . "gitlab.codemonkeysoftware.net/b/hatmill"
|
||||
import "gitlab.codemonkeysoftware.net/b/hatmill"
|
||||
|
||||
// Body creates a <body> element.
|
||||
func Body(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
return func(children ...Term) *ParentElement {
|
||||
return &ParentElement{
|
||||
EmptyElement: EmptyElement{
|
||||
func Body(attribs ...hatmill.Attrib) func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return &hatmill.ParentElement{
|
||||
EmptyElement: hatmill.EmptyElement{
|
||||
TagName: "body",
|
||||
Attribs: attribs,
|
||||
},
|
||||
@ -19,10 +19,10 @@ func Body(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
}
|
||||
|
||||
// Div creates a <div> element.
|
||||
func Div(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
return func(children ...Term) *ParentElement {
|
||||
return &ParentElement{
|
||||
EmptyElement: EmptyElement{
|
||||
func Div(attribs ...hatmill.Attrib) func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return &hatmill.ParentElement{
|
||||
EmptyElement: hatmill.EmptyElement{
|
||||
TagName: "div",
|
||||
Attribs: attribs,
|
||||
},
|
||||
@ -32,10 +32,10 @@ func Div(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
}
|
||||
|
||||
// Head creates a <head> element.
|
||||
func Head(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
return func(children ...Term) *ParentElement {
|
||||
return &ParentElement{
|
||||
EmptyElement: EmptyElement{
|
||||
func Head(attribs ...hatmill.Attrib) func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return &hatmill.ParentElement{
|
||||
EmptyElement: hatmill.EmptyElement{
|
||||
TagName: "head",
|
||||
Attribs: attribs,
|
||||
},
|
||||
@ -45,10 +45,10 @@ func Head(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
}
|
||||
|
||||
// Html creates a <html> element.
|
||||
func Html(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
return func(children ...Term) *ParentElement {
|
||||
return &ParentElement{
|
||||
EmptyElement: EmptyElement{
|
||||
func Html(attribs ...hatmill.Attrib) func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return &hatmill.ParentElement{
|
||||
EmptyElement: hatmill.EmptyElement{
|
||||
TagName: "html",
|
||||
Attribs: attribs,
|
||||
},
|
||||
@ -58,18 +58,18 @@ func Html(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
}
|
||||
|
||||
// Img creates a <img> element.
|
||||
func Img(attribs ...Attrib) EmptyElement {
|
||||
return EmptyElement{
|
||||
func Img(attribs ...hatmill.Attrib) hatmill.EmptyElement {
|
||||
return hatmill.EmptyElement{
|
||||
TagName: "img",
|
||||
Attribs: attribs,
|
||||
}
|
||||
}
|
||||
|
||||
// Li creates a <li> element.
|
||||
func Li(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
return func(children ...Term) *ParentElement {
|
||||
return &ParentElement{
|
||||
EmptyElement: EmptyElement{
|
||||
func Li(attribs ...hatmill.Attrib) func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return &hatmill.ParentElement{
|
||||
EmptyElement: hatmill.EmptyElement{
|
||||
TagName: "li",
|
||||
Attribs: attribs,
|
||||
},
|
||||
@ -79,10 +79,10 @@ func Li(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
}
|
||||
|
||||
// Span creates a <span> element.
|
||||
func Span(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
return func(children ...Term) *ParentElement {
|
||||
return &ParentElement{
|
||||
EmptyElement: EmptyElement{
|
||||
func Span(attribs ...hatmill.Attrib) func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return &hatmill.ParentElement{
|
||||
EmptyElement: hatmill.EmptyElement{
|
||||
TagName: "span",
|
||||
Attribs: attribs,
|
||||
},
|
||||
@ -92,10 +92,10 @@ func Span(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
}
|
||||
|
||||
// Title creates a <title> element.
|
||||
func Title(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
return func(children ...Term) *ParentElement {
|
||||
return &ParentElement{
|
||||
EmptyElement: EmptyElement{
|
||||
func Title(attribs ...hatmill.Attrib) func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return &hatmill.ParentElement{
|
||||
EmptyElement: hatmill.EmptyElement{
|
||||
TagName: "title",
|
||||
Attribs: attribs,
|
||||
},
|
||||
@ -105,10 +105,10 @@ func Title(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
}
|
||||
|
||||
// Ul creates a <ul> element.
|
||||
func Ul(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
return func(children ...Term) *ParentElement {
|
||||
return &ParentElement{
|
||||
EmptyElement: EmptyElement{
|
||||
func Ul(attribs ...hatmill.Attrib) func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return func(children ...hatmill.Term) *hatmill.ParentElement {
|
||||
return &hatmill.ParentElement{
|
||||
EmptyElement: hatmill.EmptyElement{
|
||||
TagName: "ul",
|
||||
Attribs: attribs,
|
||||
},
|
||||
@ -116,19 +116,25 @@ func Ul(attribs ...Attrib) func(children ...Term) *ParentElement {
|
||||
}
|
||||
}
|
||||
}
|
||||
func Disabled() Attrib {
|
||||
return Attrib{
|
||||
|
||||
// Disabled creates a disabled attribute
|
||||
func Disabled() hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "disabled",
|
||||
}
|
||||
}
|
||||
func Id(value string) Attrib {
|
||||
return Attrib{
|
||||
|
||||
// Id creates a id attribute
|
||||
func Id(value string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "id",
|
||||
Value: value,
|
||||
}
|
||||
}
|
||||
func Src(value string) Attrib {
|
||||
return Attrib{
|
||||
|
||||
// Src creates a src attribute
|
||||
func Src(value string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "src",
|
||||
Value: value,
|
||||
}
|
||||
|
26
html5/html5_test.go
Normal file
26
html5/html5_test.go
Normal file
@ -0,0 +1,26 @@
|
||||
package html5_test
|
||||
|
||||
import (
|
||||
"gitlab.codemonkeysoftware.net/b/hatmill"
|
||||
html5 "gitlab.codemonkeysoftware.net/b/hatmill/html5"
|
||||
|
||||
"html"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
userInput := "<script>launchMissiles();</script>"
|
||||
|
||||
document := html5.Html()(
|
||||
html5.Head()(),
|
||||
html5.Body()(
|
||||
html5.Div()(
|
||||
html5.Img(html5.Src("./me.jpg"), html5.Id("profile-photo")),
|
||||
html5.Text(html.EscapeString(userInput)),
|
||||
html5.Div(html5.Disabled(), html5.Data("coolness", "awesome"))(),
|
||||
),
|
||||
),
|
||||
)
|
||||
hatmill.WriteDocument(os.Stdout, document)
|
||||
// Output: <!DOCTYPE html><html><head></head><body><div><img src='./me.jpg' id='profile-photo'><script>launchMissiles();</script><div disabled data-coolness='awesome'></div></div></body></html>
|
||||
}
|
Reference in New Issue
Block a user