-
Notifications
You must be signed in to change notification settings - Fork 1
/
html5.go
91 lines (75 loc) · 2.37 KB
/
html5.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package htmx
import (
"io"
"sort"
"strings"
)
// HTML5Props represents the properties for an HTML5 document.
type HTML5Props struct {
Title string // The title of the HTML document.
Description string // The description of the HTML document.
Language string // The language of the HTML document.
Head []Node // The nodes to be included in the head section of the HTML document.
Attributes []Node // The attributes to be included in the HTML document.
}
// HTML5 generates an HTML5 document based on the provided properties.
func HTML5(props HTML5Props, body ...Node) Node {
return Doctype(
HTML(
If(props.Language != "", Lang(props.Language)),
Group(props.Attributes...),
Head(
Meta(Charset("utf-8")),
Meta(Name("viewport"), Content("width=device-width, initial-scale=1")),
TitleElement(Text(props.Title)),
If(props.Description != "", Meta(Name("description"), Content(props.Description))),
Group(props.Head...),
),
Body(body...),
),
)
}
// HxClassName represents a class name for htmx elements.
type HxClassName string
// String returns the string representation of the HxClassName.
func (c HxClassName) String() string {
return string(c)
}
const (
HxClassNameAdded HxClassName = "htmx-added"
HxClassNameIndicator HxClassName = "htmx-indicator"
HxClassNameRequest HxClassName = "htmx-request"
HxClassNameSettling HxClassName = "htmx-settling"
HxClassNameSwapping HxClassName = "htmx-swapping"
)
const (
HxClssNameAddedSelector = ".htmx-added"
HxClssNameIndicatorSelector = ".htmx-indicator"
HxClssNameRequestSelector = ".htmx-request"
HxClssNameSettlingSelector = ".htmx-settling"
HxClssNameSwappingSelector = ".htmx-swapping"
)
// ClassNames represents a set of class names.
type ClassNames map[string]bool
// Render writes the class names to the provided writer.
func (c ClassNames) Render(w io.Writer) error {
classes := make([]string, 0, len(c))
for class, ok := range c {
if !ok {
continue
}
classes = append(classes, strings.TrimSpace(class))
}
sort.Strings(classes)
return Class(strings.Join(classes, " ")).Render(w)
}
// Type returns the node type of the ClassNames.
func (c ClassNames) Type() NodeType {
return AttributeType
}
// String returns the string representation of the ClassNames.
func (c ClassNames) String() string {
var b strings.Builder
_ = c.Render(&b)
return b.String()
}