Пример #1
0
func init() {
	wcg.AddViewHelper("NavLink", func(p *Page) template.HTML {
		var buff bytes.Buffer
		navLinkTmpl.Execute(&buff, map[string]string{
			"href": p.GetExternalPath(),
			"text": p.Title,
		})
		return template.HTML(buff.String())
	})
	wcg.AddViewHelper("RGBHex", func(rgb int) template.HTML {
		r := (rgb & 0xFF0000) >> 16
		g := (rgb & 0x00FF00) >> 8
		b := (rgb & 0x0000FF)
		return template.HTML(fmt.Sprintf("#%02x%02x%02x", r, g, b))
	})

	wcg.AddViewHelper("IsAdmin", func(req *wcg.Request) bool {
		return GetUserKind(req) == Admin
	})

	// app specific view helpers
	wcg.AddViewHelper("EncodeURI", func(uri string) string {
		return url.QueryEscape(uri)
	})
}
Пример #2
0
func init() {
	wcg.AddViewHelper("tags", func(tags []string) string {
		if tags != nil && len(tags) > 0 {
			return strings.Join(tags, ",")
		}
		return ""
	})
}