forked from ungerik/go-start
/
image.go
35 lines (31 loc) · 968 Bytes
/
image.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
package view
///////////////////////////////////////////////////////////////////////////////
// Image
type Image struct {
ViewBaseWithId
Class string
URL URL // If URL is set, then Src will be ignored
Src string // String URL of the image, used when URL is nil
Width int
Height int
Description string
}
func (self *Image) Render(ctx *Context) (err error) {
ctx.Response.XML.OpenTag("img")
ctx.Response.XML.AttribIfNotDefault("id", self.id)
ctx.Response.XML.AttribIfNotDefault("class", self.Class)
src := self.Src
if self.URL != nil {
src = self.URL.URL(ctx)
}
ctx.Response.XML.Attrib("src", src)
ctx.Response.XML.AttribIfNotDefault("width", self.Width)
ctx.Response.XML.AttribIfNotDefault("height", self.Height)
ctx.Response.XML.AttribIfNotDefault("alt", self.Description)
ctx.Response.XML.CloseTag()
return nil
}
//func (self *Image) SetClass(class string) {
// self.Class = class
// ViewChanged(self)
//}