-
Notifications
You must be signed in to change notification settings - Fork 1
/
uihtml.go
80 lines (71 loc) · 1.73 KB
/
uihtml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package jaws
import (
"html/template"
"io"
"github.com/linkdata/jaws/what"
)
type UiHtml struct {
Tag any
}
func (ui *UiHtml) parseGetter(e *Element, getter interface{}) {
if getter != nil {
if tagger, ok := getter.(TagGetter); ok {
ui.Tag = tagger.JawsGetTag(e.Request)
if ch, ok := getter.(ClickHandler); ok {
e.handlers = append(e.handlers, clickHandlerWapper{ch})
}
if eh, ok := getter.(EventHandler); ok {
e.handlers = append(e.handlers, eh)
}
} else {
ui.Tag = getter
}
e.Tag(ui.Tag)
}
}
func parseParams(elem *Element, params []interface{}) (attrs []string) {
for i := range params {
switch data := params[i].(type) {
case template.HTML:
attrs = append(attrs, string(data))
case []template.HTML:
for _, s := range data {
attrs = append(attrs, string(s))
}
case string:
attrs = append(attrs, data)
case []string:
attrs = append(attrs, data...)
case EventFn:
if data != nil {
elem.handlers = append(elem.handlers, eventFnWrapper{data})
}
default:
if h, ok := data.(ClickHandler); ok {
elem.handlers = append(elem.handlers, clickHandlerWapper{h})
}
if h, ok := data.(EventHandler); ok {
elem.handlers = append(elem.handlers, h)
}
elem.Tag(data)
}
}
return
}
func (ui *UiHtml) parseParams(elem *Element, params []interface{}) (attrs []string) {
attrs = parseParams(elem, params)
return
}
func (ui *UiHtml) JawsRender(e *Element, w io.Writer, params []interface{}) {
if h, ok := ui.Tag.(UI); ok {
h.JawsRender(e, w, params)
}
}
func (ui *UiHtml) JawsUpdate(e *Element) {
if h, ok := ui.Tag.(UI); ok {
h.JawsUpdate(e)
}
}
func (ui *UiHtml) JawsEvent(e *Element, wht what.What, val string) error {
return callEventHandler(ui.Tag, e, wht, val)
}