~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.
add default props
http.go
CHANGED
|
@@ -81,6 +81,7 @@ func RegisterComponent(fn any, props ...string) {
|
|
|
81
81
|
for i := 0; i < structType.NumField(); i++ {
|
|
82
82
|
if f := rv.Field(i); f.CanSet() {
|
|
83
83
|
jsonName := structType.Field(i).Tag.Get("json")
|
|
84
|
+
defaultValue := structType.Field(i).Tag.Get("default")
|
|
84
85
|
if jsonName == "children" {
|
|
85
86
|
s, err := help.Block()
|
|
86
87
|
if err != nil {
|
|
@@ -88,7 +89,12 @@ func RegisterComponent(fn any, props ...string) {
|
|
|
88
89
|
}
|
|
89
90
|
f.Set(reflect.ValueOf(template.HTML(s)))
|
|
90
91
|
} else {
|
|
92
|
+
v := help.Context.Get(jsonName)
|
|
93
|
+
if v == nil {
|
|
91
|
-
|
|
94
|
+
f.Set(reflect.ValueOf(defaultValue))
|
|
95
|
+
} else {
|
|
96
|
+
f.Set(reflect.ValueOf(v))
|
|
97
|
+
}
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
}
|