~repos /gromer
git clone https://pyrossh.dev/repos/gromer.git
gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.
rename body to children
- .snapshots/TestHtmlPage +2 -2
- html.go +17 -17
.snapshots/TestHtmlPage
CHANGED
|
@@ -82,13 +82,13 @@
|
|
|
82
82
|
|
|
83
83
|
<h2> Hello this is a h2 </h2>
|
|
84
84
|
|
|
85
|
-
<h3 x-data="{ message: 'I ❤️ Alpine' }"
|
|
85
|
+
<h3 x-text="message" x-data="{ message: 'I ❤️ Alpine' }"> </h3>
|
|
86
86
|
|
|
87
87
|
<counter x-data="counter"> <div class="flex flex-col justify-center items-center text-3xl text-gray-700">
|
|
88
88
|
<div class="flex flex-row justify-center items-center"> <div class="flex flex-row justify-center items-center underline"> Counter </div>
|
|
89
89
|
</div>
|
|
90
90
|
|
|
91
|
-
<div class="flex flex-row justify-center items-center"
|
|
91
|
+
<div x-data="counter" class="flex flex-row justify-center items-center">
|
|
92
92
|
<button class="btn m-20" @click="decrement"> - </button>
|
|
93
93
|
|
|
94
94
|
<div class="flex flex-row justify-center items-center m-20 text-8xl" x-text="state.count"> 4 </div>
|
html.go
CHANGED
|
@@ -34,7 +34,7 @@ func mergeAttributes(parent *Element, uis ...interface{}) *Element {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
if !parent.selfClosing {
|
|
37
|
-
parent.
|
|
37
|
+
parent.children = elems
|
|
38
38
|
}
|
|
39
39
|
return parent
|
|
40
40
|
}
|
|
@@ -60,8 +60,8 @@ func (p *HtmlPage) computeCss(elems []*Element) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
if len(el.
|
|
63
|
+
if len(el.children) > 0 {
|
|
64
|
-
p.computeCss(el.
|
|
64
|
+
p.computeCss(el.children)
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -71,8 +71,8 @@ func (p *HtmlPage) computeJs(elems []*Element) {
|
|
|
71
71
|
if strings.HasPrefix(el.text, "wapp_js|") {
|
|
72
72
|
p.js.WriteString(strings.Replace(el.text, "wapp_js|", "", 1) + "\n")
|
|
73
73
|
}
|
|
74
|
-
if len(el.
|
|
74
|
+
if len(el.children) > 0 {
|
|
75
|
-
p.computeJs(el.
|
|
75
|
+
p.computeJs(el.children)
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -80,11 +80,11 @@ func (p *HtmlPage) computeJs(elems []*Element) {
|
|
|
80
80
|
func (p *HtmlPage) WriteHtml(w io.Writer) {
|
|
81
81
|
w.Write([]byte("<!DOCTYPE html>\n"))
|
|
82
82
|
w.Write([]byte("<html>\n"))
|
|
83
|
-
p.computeCss(p.Body.
|
|
83
|
+
p.computeCss(p.Body.children)
|
|
84
|
-
p.computeJs(p.Body.
|
|
84
|
+
p.computeJs(p.Body.children)
|
|
85
|
-
p.Head.
|
|
85
|
+
p.Head.children = append(p.Head.children, StyleTag(Text(normalizeStyles+p.css.String())))
|
|
86
86
|
p.Head.writeHtmlIndent(w, 1)
|
|
87
|
-
p.Body.
|
|
87
|
+
p.Body.children = append(p.Body.children, Script(Text(fmt.Sprintf(`
|
|
88
88
|
document.addEventListener('alpine:init', () => {
|
|
89
89
|
%s
|
|
90
90
|
});
|
|
@@ -109,11 +109,11 @@ func Head(elems ...*Element) *Element {
|
|
|
109
109
|
&Element{tag: "meta", selfClosing: true, attrs: map[string]string{"http-equiv": "Content-Type", "content": "text/html;charset=utf-8"}},
|
|
110
110
|
&Element{tag: "meta", selfClosing: true, attrs: map[string]string{"http-equiv": "encoding", "content": "utf-8"}},
|
|
111
111
|
}
|
|
112
|
-
return &Element{tag: "head",
|
|
112
|
+
return &Element{tag: "head", children: append(basic, elems...)}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
func Body(elems ...*Element) *Element {
|
|
116
|
-
return &Element{tag: "body",
|
|
116
|
+
return &Element{tag: "body", children: elems}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
func Component(r Reducer, uis ...interface{}) *Element {
|
|
@@ -149,7 +149,7 @@ func Component(r Reducer, uis ...interface{}) *Element {
|
|
|
149
149
|
type Element struct {
|
|
150
150
|
tag string
|
|
151
151
|
attrs map[string]string
|
|
152
|
-
|
|
152
|
+
children []*Element
|
|
153
153
|
selfClosing bool
|
|
154
154
|
text string
|
|
155
155
|
}
|
|
@@ -215,8 +215,8 @@ func (e *Element) writeHtmlIndent(w io.Writer, indent int) {
|
|
|
215
215
|
return
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
for _, c := range e.
|
|
218
|
+
for _, c := range e.children {
|
|
219
|
-
if len(e.
|
|
219
|
+
if len(e.children) > 1 {
|
|
220
220
|
w.Write([]byte("\n"))
|
|
221
221
|
}
|
|
222
222
|
if c != nil {
|
|
@@ -224,7 +224,7 @@ func (e *Element) writeHtmlIndent(w io.Writer, indent int) {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
if len(e.
|
|
227
|
+
if len(e.children) != 0 {
|
|
228
228
|
// w.Write([]byte("\n"))
|
|
229
229
|
writeIndent(w, indent)
|
|
230
230
|
}
|
|
@@ -236,8 +236,8 @@ func (e *Element) writeHtmlIndent(w io.Writer, indent int) {
|
|
|
236
236
|
|
|
237
237
|
func Title(v string) *Element {
|
|
238
238
|
return &Element{
|
|
239
|
-
tag:
|
|
239
|
+
tag: "title",
|
|
240
|
-
|
|
240
|
+
children: []*Element{Text(v)},
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
func Text(v string) *Element {
|