-
Notifications
You must be signed in to change notification settings - Fork 1
/
caption.go
39 lines (32 loc) · 948 Bytes
/
caption.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
package tables
import (
"fmt"
"html"
"html/template"
"github.com/coscms/forms/widgets"
)
type Caption struct {
Attributes Attributes `json:"attributes,omitempty" xml:"attributes,omitempty"`
Style string `json:"style" xml:"style"`
Template string `json:"template" xml:"template"`
Content interface{} `json:"content" xml:"content"`
widget widgets.WidgetInterface
}
func (c *Caption) String() string {
return fmt.Sprint(c.Content)
}
func (c *Caption) defaultHTMLString() string {
return `<` + TagCaption + GenAttr(c.Attributes) + `>` + html.EscapeString(fmt.Sprint(c.Content)) + `</` + TagCaption + `>`
}
func (c *Caption) render() string {
if len(c.Template) == 0 {
return c.defaultHTMLString()
}
if c.widget == nil {
c.widget = widgets.BaseWidget(c.Style, TagCaption, c.Template)
}
return c.widget.Render(c.Content)
}
func (c *Caption) Render() template.HTML {
return template.HTML(c.render())
}