本文整理匯總了Golang中github.com/hjin-me/banana.Context.Tpl方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Tpl方法的具體用法?Golang Context.Tpl怎麽用?Golang Context.Tpl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hjin-me/banana.Context
的用法示例。
在下文中一共展示了Context.Tpl方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Post
func Post(ctx banana.Context) error {
err := Auth(ctx, PrivilegePostRead)
switch err {
case ErrNoPermit:
return err
case ErrNotLogin:
http.Redirect(ctx.Res(), ctx.Req(), "/login?error", http.StatusFound)
return nil
case nil:
default:
return err
}
var (
idStr string
ok bool
)
if idStr, ok = ctx.Params()["id"]; !ok {
panic("no id")
}
id, err := strconv.ParseInt(idStr, 10, 32)
if err != nil {
panic(err)
}
p := post.ReadRaw(int(id))
categories, err := category.Query()
if err != nil {
return err
}
layout := ThemeLayout{}
layout.Content = ThemeBlock{theme.CP("post"), struct{ Post, Categories interface{} }{p, categories}}
return ctx.Tpl(theme.CP("layout"), layout)
}
示例2: UsersCreatePage
func UsersCreatePage(ctx banana.Context) error {
err := Auth(ctx, PrivilegeUserRead)
switch err {
case ErrNoPermit:
return err
case ErrNotLogin:
http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/users", http.StatusFound)
return nil
case nil:
default:
return err
}
/*
idStr, ok := ctx.Params()["id"]
if !ok {
http.Redirect(ctx.Res(), ctx.Req(), "/cp/users", http.StatusFound)
return nil
}
id, err := strconv.ParseInt(idStr, 10, 32)
if err != nil {
http.Redirect(ctx.Res(), ctx.Req(), "/cp/users", http.StatusFound)
return nil
}
u, err := user.FindOne(int(id))
if err != nil {
return err
}
*/
u := 1
layout := ThemeLayout{}
layout.Content = ThemeBlock{theme.CP("user"), struct{ Info interface{} }{u}}
return ctx.Tpl(theme.CP("layout"), layout)
}
示例3: Latest
func Latest(ctx banana.Context) error {
ps := post.Query(0, 10)
layout := ThemeLayout{}
layout.Content = ThemeBlock{theme.UI("home"), ps}
return ctx.Tpl(theme.UI("layout"), layout)
/*
posts, err := models.ZRange("pubtime", 0, 4)
if err != nil {
log.Fatal(err)
}
ctx.Tpl("home", posts)
*/
}
示例4: Read
func Read(ctx banana.Context) error {
var (
idStr string
ok bool
)
if idStr, ok = ctx.Params()["id"]; !ok {
return errors.New("no id")
}
id, err := strconv.ParseInt(idStr, 10, 32)
if err != nil {
return err
}
x := post.Read(int(id))
if yearStr, ok := ctx.Params()["year"]; ok {
t, err := strconv.ParseInt(yearStr, 10, 32)
if err != nil {
return err
}
if int(t) != x.PubTime.Year() {
return errors.New("404")
}
}
if monthStr, ok := ctx.Params()["month"]; ok {
t, err := strconv.ParseInt(monthStr, 10, 32)
if err != nil {
return err
}
if int(t) != int(x.PubTime.Month()) {
return errors.New("404")
}
}
if dayStr, ok := ctx.Params()["day"]; ok {
t, err := strconv.ParseInt(dayStr, 10, 32)
if err != nil {
return err
}
if int(t) != x.PubTime.Day() {
return errors.New("404")
}
}
layout := ThemeLayout{}
layout.Content = ThemeBlock{theme.UI("post"), x}
return ctx.Tpl(theme.UI("layout"), layout)
}
示例5: DashBoard
func DashBoard(ctx banana.Context) error {
err := Auth(ctx, PrivilegePostRead)
switch err {
case ErrNoPermit:
http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/dashboard", http.StatusFound)
return err
case ErrNotLogin:
http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/dashboard", http.StatusFound)
return err
case nil:
default:
return err
}
layout := ThemeLayout{}
layout.Content = ThemeBlock{theme.CP("starter"), 1}
return ctx.Tpl(theme.CP("layout"), layout)
}
示例6: Posts
func Posts(ctx banana.Context) error {
err := Auth(ctx, PrivilegePostRead)
switch err {
case ErrNoPermit:
return err
case ErrNotLogin:
http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/posts", http.StatusFound)
return nil
case nil:
default:
return err
}
ps := post.Query(0, 10)
layout := ThemeLayout{}
layout.Content = ThemeBlock{theme.CP("posts"), ps}
return ctx.Tpl(theme.CP("layout"), layout)
}
示例7: Users
func Users(ctx banana.Context) error {
err := Auth(ctx, PrivilegeUserRead)
switch err {
case ErrNoPermit:
return err
case ErrNotLogin:
http.Redirect(ctx.Res(), ctx.Req(), "/login?error&u=/cp/users", http.StatusFound)
return nil
case nil:
default:
return err
}
users, err := user.Query(0, 10)
if err != nil {
return err
}
layout := ThemeLayout{}
layout.Content = ThemeBlock{theme.CP("users"), struct{ List interface{} }{users}}
return ctx.Tpl(theme.CP("layout"), layout)
}
示例8: Category
func Category(ctx banana.Context) error {
c, ok := ctx.Params()["category"]
if !ok {
return errors.New("no category")
}
ps, err := post.QueryByCategory(c, 0, 10)
if err != nil {
return err
}
var ca = category.Category{}
if len(ps) > 0 {
ca = ps[0].Category
}
layout := ThemeLayout{}
layout.Content = ThemeBlock{theme.UI("category"), struct {
List []post.Post
Bread category.Category
}{ps, ca}}
return ctx.Tpl(theme.UI("layout"), layout)
}
示例9: NewPost
func NewPost(ctx banana.Context) error {
err := Auth(ctx, PrivilegePostRead)
switch err {
case ErrNoPermit:
return err
case ErrNotLogin:
http.Redirect(ctx.Res(), ctx.Req(), "/login?error", http.StatusFound)
return nil
case nil:
default:
return err
}
categories, err := category.Query()
if err != nil {
return err
}
p := post.New()
layout := ThemeLayout{}
layout.Content = ThemeBlock{theme.CP("post"), struct{ Post, Categories interface{} }{p, categories}}
return ctx.Tpl(theme.CP("layout"), layout)
}
示例10: LoginPage
func LoginPage(ctx banana.Context) error {
return ctx.Tpl(theme.CP("login"), 0)
}
示例11: Query
func Query(ctx banana.Context) error {
posts := post.Query(0, 10)
layout := HomeLayout{}
layout.Content = posts
return ctx.Tpl(theme.UI("home"), layout)
}