~repos /gromer

#golang#htmx#ssr

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.


ceeeaa1a pyros2097

tag: v0.0.9

v0.0.9

5 years ago
fix Div
Files changed (3) hide show
  1. css_test.go +42 -2
  2. html.go +6 -2
  3. node.go +0 -9
css_test.go CHANGED
@@ -7,11 +7,51 @@ import (
7
7
  "github.com/stretchr/testify/assert"
8
8
  )
9
9
 
10
+ func Row(uis ...UI) UI {
11
+ uis = append(uis, Css("flex flex-row justify-center align-items-center"))
12
+ return Div(uis...)
13
+ }
14
+
15
+ func Col(uis ...UI) UI {
16
+ uis = append(uis, Css("flex flex-row justify-center align-items-center"))
17
+ return Div(uis...)
18
+ }
19
+
20
+ func Counter(c *RenderContext) UI {
21
+ count, _ := c.UseInt(0)
22
+ return Col(
23
+ Div(Css("yellow"),
24
+ Text("Counter"),
25
+ ),
26
+ Row(
27
+ Div(
28
+ Text("-"),
29
+ ),
30
+ Div(
31
+ Text(count()),
32
+ ),
33
+ Div(
34
+ Text("+"),
35
+ ),
36
+ ),
37
+ )
38
+ }
39
+
40
+ func Route(c *RenderContext) UI {
41
+ return Div(
42
+ Div(),
43
+ Counter(c),
44
+ )
45
+ }
46
+
10
47
  func TestCreatePage(t *testing.T) {
11
48
  page := bytes.NewBuffer(nil)
12
49
  page.WriteString("<!DOCTYPE html>\n")
13
50
  Html(
51
+ Head(
52
+ Title("Title"),
53
+ ),
14
- Body(Div(Css("abc"), Text("About Me"))),
54
+ Body(Route(NewRenderContext())),
15
55
  ).Html(page)
16
- assert.Equal(t, "<!DOCTYPE html>\n<html>\n <head>\n <div class=\"abc\"></div>\n </head>\n</html>", page.String())
56
+ assert.Equal(t, "<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"UTF-8\">\n <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n <meta http-equiv=\"encoding\" content=\"utf-8\">\n <title>\n Title\n </title>\n </head>\n <body>\n <div>\n <div></div>\n <div class=\"flex flex-row justify-center align-items-center\">\n <div class=\"yellow\">\n Counter\n </div>\n <div class=\"flex flex-row justify-center align-items-center\">\n <div>\n -\n </div>\n <div>\n 0\n </div>\n <div>\n +\n </div>\n </div>\n </div>\n </div>\n </body>\n</html>", page.String())
17
57
  }
html.go CHANGED
@@ -14,7 +14,7 @@ func Head(elems ...UI) *elem {
14
14
  }
15
15
 
16
16
  func Body(elems ...UI) *elem {
17
- return &elem{tag: "head", body: elems}
17
+ return &elem{tag: "body", body: elems}
18
18
  }
19
19
 
20
20
  func Title(v string) *elem {
@@ -55,6 +55,8 @@ func RemoveAttributes(uis ...UI) ([]UI, string) {
55
55
  if v.Kind() == Attribute {
56
56
  cc, _ := v.(CSSClass)
57
57
  classes = classes + cc.classes
58
+ } else {
59
+ elems = append(elems, v)
58
60
  }
59
61
 
60
62
  }
@@ -64,6 +66,8 @@ func RemoveAttributes(uis ...UI) ([]UI, string) {
64
66
  func Div(uis ...UI) *elem {
65
67
  elems, classes := RemoveAttributes(uis...)
66
68
  e := &elem{tag: "div", body: elems}
69
+ if classes != "" {
67
- e.setAttr("class", classes)
70
+ e.setAttr("class", classes)
71
+ }
68
72
  return e
69
73
  }
node.go CHANGED
@@ -113,15 +113,6 @@ func FilterUIElems(uis ...UI) []UI {
113
113
  case Selector:
114
114
  elems = append(elems, n.children()...)
115
115
 
116
- case Attribute:
117
- if n.parent() != nil {
118
- attr := n.parent().attributes()
119
- cc, err := n.(CSSClass)
120
- if err {
121
- panic("Could not convert attribute css")
122
- }
123
- attr["class"] = cc.classes
124
- }
125
116
  default:
126
117
  panic(errors.New("filtering ui elements failed").
127
118
  Tag("reason", "unexpected element type found").