Example #1
0
File: pttweb.go Project: ptt/pttweb
func templateFuncMap() template.FuncMap {
	return template.FuncMap{
		"route_bbsindex": func(b pttbbs.Board) (*url.URL, error) {
			return router.Get("bbsindex").URLPath("brdname", b.BrdName)
		},
		"route_bbsindex_page": func(b pttbbs.Board, pg int) (*url.URL, error) {
			return router.Get("bbsindex_page").URLPath("brdname", b.BrdName, "page", strconv.Itoa(pg))
		},
		"route_classlist": func(b pttbbs.Board) (*url.URL, error) {
			return router.Get("classlist").URLPath("bid", strconv.Itoa(b.Bid))
		},
		"valid_article": func(a pttbbs.Article) bool {
			return pttbbs.IsValidArticleFileName(a.FileName)
		},
		"route_bbsarticle": func(brdname, filename string) (*url.URL, error) {
			return router.Get("bbsarticle").URLPath("brdname", brdname, "filename", filename)
		},
		"route_askover18": func() (*url.URL, error) {
			return router.Get("askover18").URLPath()
		},
		"route_manentry": func(e *bbspb.Entry) (*url.URL, error) {
			var index string
			if e.IsDir {
				index = "index"
			}
			return router.Get("manentry").URLPath("fullpath", path.Join(e.BoardName, e.Path, index))
		},
		"route_manarticle": func(brdname, p string) (*url.URL, error) {
			return router.Get("manentry").URLPath("fullpath", path.Join(brdname, p))
		},
		"route_manindex": func(brdname, p string) (*url.URL, error) {
			return router.Get("manentry").URLPath("fullpath", path.Join(brdname, p, "index"))
		},
		"route_manparent": func(brdname, p string) (*url.URL, error) {
			dir := path.Join(brdname, path.Dir(p))
			return router.Get("manentry").URLPath("fullpath", path.Join(dir, "index"))
		},
		"route": func(where string, attrs ...string) (*url.URL, error) {
			return router.Get(where).URLPath(attrs...)
		},
		"static_prefix": func() string {
			return config.StaticPrefix
		},
		"colored_counter": colored_counter,
		"post_mark":       post_mark,
		"ga_account": func() string {
			return config.GAAccount
		},
		"ga_domain": func() string {
			return config.GADomain
		},
		"slice": func(args ...interface{}) []interface{} {
			return args
		},
	}
}
Example #2
0
func templateFuncMap() template.FuncMap {
	return template.FuncMap{
		"route_bbsindex": func(b pttbbs.Board) (*url.URL, error) {
			return router.Get("bbsindex").URLPath("brdname", b.BrdName)
		},
		"route_bbsindex_page": func(b pttbbs.Board, pg int) (*url.URL, error) {
			return router.Get("bbsindex_page").URLPath("brdname", b.BrdName, "page", strconv.Itoa(pg))
		},
		"route_classlist": func(b pttbbs.Board) (*url.URL, error) {
			return router.Get("classlist").URLPath("bid", strconv.Itoa(b.Bid))
		},
		"valid_article": func(a pttbbs.Article) bool {
			return pttbbs.IsValidArticleFileName(a.FileName)
		},
		"route_bbsarticle": func(brdname, filename string) (*url.URL, error) {
			return router.Get("bbsarticle").URLPath("brdname", brdname, "filename", filename)
		},
		"route_askover18": func() (*url.URL, error) {
			return router.Get("askover18").URLPath()
		},
		"route": func(where string, attrs ...string) (*url.URL, error) {
			return router.Get(where).URLPath(attrs...)
		},
		"static_prefix": func() string {
			return config.StaticPrefix
		},
		"colored_counter": colored_counter,
		"post_mark":       post_mark,
		"ga_account": func() string {
			return config.GAAccount
		},
		"ga_domain": func() string {
			return config.GADomain
		},
		"slice": func(args ...interface{}) []interface{} {
			return args
		},
	}
}