~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.


e921ad2d pyros2097

5 years ago
make it work
Files changed (5) hide show
  1. attributes.go +1 -1
  2. element.go +1 -1
  3. node.go +7 -22
  4. node_test.go +0 -8
  5. selectors.go +3 -3
attributes.go CHANGED
@@ -37,7 +37,7 @@ func OnInput(cb js.EventHandlerFunc) OnInputAttribute {
37
37
  }
38
38
 
39
39
  func mergeAttributes(parent *elem, uis ...interface{}) {
40
- elems := make([]UI, 0, len(uis))
40
+ elems := []interface{}{}
41
41
  for _, v := range uis {
42
42
  switch c := v.(type) {
43
43
  case CssAttribute:
element.go CHANGED
@@ -351,7 +351,7 @@ func (e *elem) delJsEventHandler(k string, h js.EventHandler) {
351
351
  delete(e.events, k)
352
352
  }
353
353
 
354
- func (e *elem) setBody(body ...UI) {
354
+ func (e *elem) setBody(body ...interface{}) {
355
355
  if e.selfClosing {
356
356
  panic(errors.New("setting html element body failed").
357
357
  Tag("reason", "self closing element can't have children").
node.go CHANGED
@@ -44,9 +44,6 @@ func (k Kind) String() string {
44
44
  case HTML:
45
45
  return "html"
46
46
 
47
- case Selector:
48
- return "selector"
49
-
50
47
  case RawHTML:
51
48
  return "raw"
52
49
 
@@ -71,10 +68,6 @@ const (
71
68
  // Component represents a customized, independent and reusable UI element.
72
69
  Component
73
70
 
74
- // Selector represents an element that is used to select a subset of
75
- // elements within a given list.
76
- Selector
77
-
78
71
  // RawHTML represents an HTML element obtained from a raw HTML code snippet.
79
72
  RawHTML
80
73
 
@@ -87,7 +80,7 @@ const (
87
80
  //
88
81
  // It should be used only when implementing components that can accept content
89
82
  // with variadic arguments like HTML elements Body method.
90
- func FilterUIElems(uis ...UI) []UI {
83
+ func FilterUIElems(uis ...interface{}) []UI {
91
84
  if len(uis) == 0 {
92
85
  return nil
93
86
  }
@@ -95,25 +88,17 @@ func FilterUIElems(uis ...UI) []UI {
95
88
  elems := make([]UI, 0, len(uis))
96
89
 
97
90
  for _, n := range uis {
98
- // Ignore nil elements:
99
91
  if v := reflect.ValueOf(n); n == nil ||
100
92
  v.Kind() == reflect.Ptr && v.IsNil() {
101
93
  continue
102
94
  }
103
-
104
- switch n.Kind() {
95
+ switch c := n.(type) {
105
- case SimpleText, HTML, Component, RawHTML:
106
- elems = append(elems, n)
107
-
108
- case Selector:
96
+ case RangeLoop:
109
- elems = append(elems, n.children()...)
97
+ elems = append(elems, c.body...)
110
-
98
+ case Condition:
99
+ elems = append(elems, c.body...)
111
100
  default:
112
- panic(errors.New("filtering ui elements failed").
113
- Tag("reason", "unexpected element type found").
114
- Tag("kind", n.Kind()).
101
+ elems = append(elems, c.(UI))
115
- Tag("name", n.name()),
116
- )
117
102
  }
118
103
  }
119
104
 
node_test.go CHANGED
@@ -25,14 +25,6 @@ func TestKindString(t *testing.T) {
25
25
  kind: HTML,
26
26
  expectedString: "html",
27
27
  },
28
- // {
29
- // kind: Component,
30
- // expectedString: "component",
31
- // },
32
- {
33
- kind: Selector,
34
- expectedString: "selector",
35
- },
36
28
  }
37
29
 
38
30
  for _, u := range utests {
selectors.go CHANGED
@@ -69,7 +69,7 @@ func (r RangeLoop) Map(f func(string) UI) RangeLoop {
69
69
 
70
70
  // If returns a condition that filters the given elements according to the given
71
71
  // expression.
72
- func If(expr bool, elems ...UI) Condition {
72
+ func If(expr bool, elems ...interface{}) Condition {
73
73
  if !expr {
74
74
  elems = nil
75
75
  }
@@ -89,7 +89,7 @@ type Condition struct {
89
89
 
90
90
  // ElseIf sets the condition with the given nodes if previous expressions
91
91
  // were not met and given expression is true.
92
- func (c Condition) ElseIf(expr bool, elems ...UI) Condition {
92
+ func (c Condition) ElseIf(expr bool, elems ...interface{}) Condition {
93
93
  if c.satisfied {
94
94
  return c
95
95
  }
@@ -104,6 +104,6 @@ func (c Condition) ElseIf(expr bool, elems ...UI) Condition {
104
104
 
105
105
  // Else sets the condition with the given UI elements if previous
106
106
  // expressions were not met.
107
- func (c Condition) Else(elems ...UI) Condition {
107
+ func (c Condition) Else(elems ...interface{}) Condition {
108
108
  return c.ElseIf(true, elems...)
109
109
  }