-
Notifications
You must be signed in to change notification settings - Fork 1
/
uiimg.go
40 lines (33 loc) · 815 Bytes
/
uiimg.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
package jaws
import (
"html/template"
"io"
"strconv"
)
type UiImg struct {
UiHtml
StringSetter
}
func (ui *UiImg) SrcAttr(e *Element) string {
src := ui.JawsGetString(e)
if len(src) < 1 || src[0] != '"' {
return strconv.Quote(src)
}
return src
}
func (ui *UiImg) JawsRender(e *Element, w io.Writer, params []interface{}) {
ui.parseGetter(e, ui.StringSetter)
attrs := append(ui.parseParams(e, params), "src="+ui.SrcAttr(e))
maybePanic(WriteHtmlInner(w, e.Jid(), "img", "", "", attrs...))
}
func (ui *UiImg) JawsUpdate(u *Element) {
u.SetAttr("src", ui.SrcAttr(u))
}
func NewUiImg(g StringSetter) *UiImg {
return &UiImg{
StringSetter: g,
}
}
func (rq *Request) Img(imageSrc interface{}, params ...interface{}) template.HTML {
return rq.UI(NewUiImg(makeStringSetter(imageSrc)), params...)
}