當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.ViewContext方法代碼示例

本文整理匯總了Golang中github.com/opesun/nocrud/frame/interfaces.Context.ViewContext方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.ViewContext方法的具體用法?Golang Context.ViewContext怎麽用?Golang Context.ViewContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/opesun/nocrud/frame/interfaces.Context的用法示例。


在下文中一共展示了Context.ViewContext方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: builtins

// We must recreate this map each time because map write is not threadsafe.
// Write will happen when a hook modifies the map (hook call is not implemented yet).
func builtins(ctx iface.Context) map[string]interface{} {
	viewCtx := ctx.ViewContext().Get()
	user := ctx.User()
	ret := map[string]interface{}{
		"get": func(s ...string) interface{} {
			return get(viewCtx, s...)
		},
		"date": date,
		"is_stranger": func() bool {
			return user.Level() == 0
		},
		"logged_in": func() bool {
			return user.Level() > 0
		},
		"is_moderator": func() bool {
			return user.Level() >= 200
		},
		"is_admin": func() bool {
			return user.Level() >= 300
		},
		"is_map":       isMap,
		"eq":           eq,
		"html":         html,
		"format_float": formatFloat,
		"fallback":     fallback,
		"type_of":      typeOf,
		"same_kind":    sameKind,
		"title":        strings.Title,
		"url": func(action_name string, i ...interface{}) string {
			return _url(ctx, action_name, i...)
		},
		"form": func(action_name string) *Form {
			return form(ctx, action_name)
		},
		"counter": newcounter,
		"get_sub": func(str string, params ...interface{}) []interface{} {
			return getSub(ctx, str, params...)
		},
		"get_list": func(str string, params ...interface{}) []interface{} {
			return getList(ctx, str, params...)
		},
		"elem": elem,
		"pager": func(pagesl []string, count, limited int) []paging.Pelem {
			var pagestr string
			if len(pagesl) == 0 {
				pagestr = "1"
			} else {
				pagestr = pagesl[0]
			}
			return pager(ctx, pagestr, count, limited)
		},
	}
	ctx.Conducting().Hooks().Select("AddTemplateBuiltin").Fire(ret)
	return ret
}
開發者ID:Laller,項目名稱:nocrud,代碼行數:57,代碼來源:builtins.go

示例2: builtins

// We must recreate this map each time because map write is not threadsafe.
// Write will happen when a hook modifies the map (hook call is not implemented yet).
func builtins(ctx iface.Context) map[string]interface{} {
	viewCtx := ctx.ViewContext().Get()
	user := ctx.User()
	ret := map[string]interface{}{
		"get": func(s ...string) interface{} {
			return getMap(viewCtx, s...)
		},
		"getMap": getMap,
		"date":   date,
		"isStranger": func() bool {
			return user.Level() == 0
		},
		"loggedIn": func() bool {
			return user.Level() > 0
		},
		"isModerator": func() bool {
			return user.Level() >= 200
		},
		"isAdmin": func() bool {
			return user.Level() >= 300
		},
		"isMap":       isMap,
		"eq":          eq,
		"html":        html,
		"formatFloat": formatFloat,
		"newMap":      newMap,
		"newSlice":    newSlice,
		"fallback":    fallback,
		"typeOf":      typeOf,
		"sameKind":    sameKind,
		"title":       strings.Title,
		"url": func(action_name string, i ...interface{}) string {
			return _url(ctx, action_name, i...)
		},
		"form": func(action_name string) *Form {
			return form(ctx, action_name)
		},
		"counter": newcounter,
		"getSub": func(str string, params ...interface{}) []interface{} {
			return getSub(ctx, str, params...)
		},
		"getList": func(str string, params ...interface{}) []interface{} {
			return getList(ctx, str, params...)
		},
		"concat": concat,
		"index":  index,
		"pager": func(page interface{}, count, limited int) []paging.Pelem {
			var pagestr string
			if page == nil {
				pagestr = "1"
			} else {
				pagestr = page.(string)
			}
			return pager(ctx, pagestr, count, limited)
		},
		"len":     _len,
		"setMap":  setMap,
		"inSlice": inSlice,
		"hook": func(hookName string) *hook {
			return selectHook(ctx, hookName)
		},
		"indentedJSON": indentedJSON,
	}
	ctx.Conducting().Hooks().Select("AddTemplateBuiltin").Fire(ret)
	return ret
}
開發者ID:crufter,項目名稱:nocrud,代碼行數:68,代碼來源:builtins.go


注:本文中的github.com/opesun/nocrud/frame/interfaces.Context.ViewContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。