~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.
aeae085e
—
pyros2097 4 years ago
atts
- attributes.go +62 -2
- element.go +1 -0
- html.go +13 -1
- js/js.go +1 -0
attributes.go
CHANGED
|
@@ -1,9 +1,60 @@
|
|
|
1
1
|
package app
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"strconv"
|
|
5
|
+
|
|
4
6
|
"github.com/pyros2097/wapp/js"
|
|
5
7
|
)
|
|
6
8
|
|
|
9
|
+
type Attribute struct {
|
|
10
|
+
Key string
|
|
11
|
+
Value string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func ID(v string) Attribute {
|
|
15
|
+
return Attribute{"id", v}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
func Style(v string) Attribute {
|
|
19
|
+
return Attribute{"style", v}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
func Accept(v string) Attribute {
|
|
23
|
+
return Attribute{"accept", v}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
func AutoComplete(v bool) Attribute {
|
|
27
|
+
return Attribute{"autocomplete", strconv.FormatBool(v)}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func Checked(v bool) Attribute {
|
|
31
|
+
return Attribute{"checked", strconv.FormatBool(v)}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func Disabled(v bool) Attribute {
|
|
35
|
+
return Attribute{"disabled", strconv.FormatBool(v)}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func Name(v string) Attribute {
|
|
39
|
+
return Attribute{"name", v}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func Type(v string) Attribute {
|
|
43
|
+
return Attribute{"type", v}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
func Value(v string) Attribute {
|
|
47
|
+
return Attribute{"value", v}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func Placeholder(v string) Attribute {
|
|
51
|
+
return Attribute{"placeholder", v}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
func Src(v string) Attribute {
|
|
55
|
+
return Attribute{"src", v}
|
|
56
|
+
}
|
|
57
|
+
|
|
7
58
|
type CssAttribute struct {
|
|
8
59
|
classes string
|
|
9
60
|
}
|
|
@@ -12,6 +63,13 @@ func Css(d string) CssAttribute {
|
|
|
12
63
|
return CssAttribute{classes: d}
|
|
13
64
|
}
|
|
14
65
|
|
|
66
|
+
func CssIf(v bool, d string) CssAttribute {
|
|
67
|
+
if v {
|
|
68
|
+
return CssAttribute{classes: d}
|
|
69
|
+
}
|
|
70
|
+
return CssAttribute{}
|
|
71
|
+
}
|
|
72
|
+
|
|
15
73
|
type OnClickAttribute struct {
|
|
16
74
|
cb func()
|
|
17
75
|
}
|
|
@@ -45,6 +103,8 @@ func mergeAttributes(parent *elem, uis ...interface{}) {
|
|
|
45
103
|
elems := []UI{}
|
|
46
104
|
for _, v := range uis {
|
|
47
105
|
switch c := v.(type) {
|
|
106
|
+
case Attribute:
|
|
107
|
+
parent.setAttr(c.Key, c.Value)
|
|
48
108
|
case CssAttribute:
|
|
49
109
|
if vv, ok := parent.attrs["classes"]; ok {
|
|
50
110
|
parent.setAttr("class", vv+" "+c.classes)
|
|
@@ -67,10 +127,10 @@ func mergeAttributes(parent *elem, uis ...interface{}) {
|
|
|
67
127
|
helmet.Author = string(c)
|
|
68
128
|
case HelmetKeywords:
|
|
69
129
|
helmet.Keywords = string(c)
|
|
70
|
-
case nil:
|
|
71
|
-
// don't add nil to elems
|
|
72
130
|
case UI:
|
|
73
131
|
elems = append(elems, c)
|
|
132
|
+
case nil:
|
|
133
|
+
// dont need to add nil items
|
|
74
134
|
default:
|
|
75
135
|
panic("unknown type in render")
|
|
76
136
|
}
|
element.go
CHANGED
|
@@ -300,6 +300,7 @@ func (e *elem) setJsEventHandler(k string, h js.EventHandler) {
|
|
|
300
300
|
return
|
|
301
301
|
}
|
|
302
302
|
e := js.Event{
|
|
303
|
+
Src: this,
|
|
303
304
|
Value: args[0],
|
|
304
305
|
}
|
|
305
306
|
trackMousePosition(e)
|
html.go
CHANGED
|
@@ -56,6 +56,18 @@ func Div(uis ...interface{}) *elem {
|
|
|
56
56
|
return e
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
func Input(uis ...interface{}) *elem {
|
|
60
|
+
e := &elem{tag: "input"}
|
|
61
|
+
mergeAttributes(e, uis...)
|
|
62
|
+
return e
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func Image(uis ...interface{}) *elem {
|
|
66
|
+
e := &elem{tag: "image"}
|
|
67
|
+
mergeAttributes(e, uis...)
|
|
68
|
+
return e
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
func Row(uis ...interface{}) UI {
|
|
60
72
|
return Div(append([]interface{}{Css("flex flex-row justify-center items-center")}, uis...)...)
|
|
61
73
|
}
|
|
@@ -64,7 +76,7 @@ func Col(uis ...interface{}) UI {
|
|
|
64
76
|
return Div(append([]interface{}{Css("flex flex-col justify-center items-center")}, uis...)...)
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
func If(expr bool, a UI
|
|
79
|
+
func If(expr bool, a UI) UI {
|
|
68
80
|
if expr {
|
|
69
81
|
return a
|
|
70
82
|
}
|
js/js.go
CHANGED
|
@@ -201,6 +201,7 @@ type BrowserWindow interface {
|
|
|
201
201
|
|
|
202
202
|
// Event is the interface that describes a javascript event.
|
|
203
203
|
type Event struct {
|
|
204
|
+
Src Value
|
|
204
205
|
Value
|
|
205
206
|
}
|
|
206
207
|
|