mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 19:00:55 +00:00
TplNames renamed TplName ,fix #1229,Remember modify bee tool.
This commit is contained in:
parent
80912b6210
commit
4c0c0ec2a7
@ -68,7 +68,7 @@ type Controller struct {
|
|||||||
AppController interface{}
|
AppController interface{}
|
||||||
|
|
||||||
// template data
|
// template data
|
||||||
TplNames string
|
TplName string
|
||||||
Layout string
|
Layout string
|
||||||
LayoutSections map[string]string // the key is the section name and the value is the template name
|
LayoutSections map[string]string // the key is the section name and the value is the template name
|
||||||
TplExt string
|
TplExt string
|
||||||
@ -105,7 +105,7 @@ type ControllerInterface interface {
|
|||||||
// Init generates default values of controller operations.
|
// Init generates default values of controller operations.
|
||||||
func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
|
func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
|
||||||
c.Layout = ""
|
c.Layout = ""
|
||||||
c.TplNames = ""
|
c.TplName = ""
|
||||||
c.controllerName = controllerName
|
c.controllerName = controllerName
|
||||||
c.actionName = actionName
|
c.actionName = actionName
|
||||||
c.Ctx = ctx
|
c.Ctx = ctx
|
||||||
@ -200,12 +200,12 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
|||||||
//if the controller has set layout, then first get the tplname's content set the content to the layout
|
//if the controller has set layout, then first get the tplname's content set the content to the layout
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if c.Layout != "" {
|
if c.Layout != "" {
|
||||||
if c.TplNames == "" {
|
if c.TplName == "" {
|
||||||
c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
c.TplName = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
||||||
}
|
}
|
||||||
|
|
||||||
if BConfig.RunMode == DEV {
|
if BConfig.RunMode == DEV {
|
||||||
buildFiles := []string{c.TplNames}
|
buildFiles := []string{c.TplName}
|
||||||
if c.LayoutSections != nil {
|
if c.LayoutSections != nil {
|
||||||
for _, sectionTpl := range c.LayoutSections {
|
for _, sectionTpl := range c.LayoutSections {
|
||||||
if sectionTpl == "" {
|
if sectionTpl == "" {
|
||||||
@ -216,10 +216,10 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
BuildTemplate(BConfig.WebConfig.ViewsPath, buildFiles...)
|
BuildTemplate(BConfig.WebConfig.ViewsPath, buildFiles...)
|
||||||
}
|
}
|
||||||
if _, ok := BeeTemplates[c.TplNames]; !ok {
|
if _, ok := BeeTemplates[c.TplName]; !ok {
|
||||||
panic("can't find templatefile in the path:" + c.TplNames)
|
panic("can't find templatefile in the path:" + c.TplName)
|
||||||
}
|
}
|
||||||
err := BeeTemplates[c.TplNames].ExecuteTemplate(&buf, c.TplNames, c.Data)
|
err := BeeTemplates[c.TplName].ExecuteTemplate(&buf, c.TplName, c.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Trace("template Execute err:", err)
|
Trace("template Execute err:", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -252,17 +252,17 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
|||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.TplNames == "" {
|
if c.TplName == "" {
|
||||||
c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
c.TplName = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
||||||
}
|
}
|
||||||
if BConfig.RunMode == DEV {
|
if BConfig.RunMode == DEV {
|
||||||
BuildTemplate(BConfig.WebConfig.ViewsPath, c.TplNames)
|
BuildTemplate(BConfig.WebConfig.ViewsPath, c.TplName)
|
||||||
}
|
}
|
||||||
if _, ok := BeeTemplates[c.TplNames]; !ok {
|
if _, ok := BeeTemplates[c.TplName]; !ok {
|
||||||
panic("can't find templatefile in the path:" + c.TplNames)
|
panic("can't find templatefile in the path:" + c.TplName)
|
||||||
}
|
}
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
err := BeeTemplates[c.TplNames].ExecuteTemplate(&buf, c.TplNames, c.Data)
|
err := BeeTemplates[c.TplName].ExecuteTemplate(&buf, c.TplName, c.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Trace("template Execute err:", err)
|
Trace("template Execute err:", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -61,8 +61,8 @@ func TestNamespaceNest(t *testing.T) {
|
|||||||
ns.Namespace(
|
ns.Namespace(
|
||||||
NewNamespace("/admin").
|
NewNamespace("/admin").
|
||||||
Get("/order", func(ctx *context.Context) {
|
Get("/order", func(ctx *context.Context) {
|
||||||
ctx.Output.Body([]byte("order"))
|
ctx.Output.Body([]byte("order"))
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
AddNamespace(ns)
|
AddNamespace(ns)
|
||||||
BeeApp.Handlers.ServeHTTP(w, r)
|
BeeApp.Handlers.ServeHTTP(w, r)
|
||||||
@ -79,8 +79,8 @@ func TestNamespaceNestParam(t *testing.T) {
|
|||||||
ns.Namespace(
|
ns.Namespace(
|
||||||
NewNamespace("/admin").
|
NewNamespace("/admin").
|
||||||
Get("/order/:id", func(ctx *context.Context) {
|
Get("/order/:id", func(ctx *context.Context) {
|
||||||
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
AddNamespace(ns)
|
AddNamespace(ns)
|
||||||
BeeApp.Handlers.ServeHTTP(w, r)
|
BeeApp.Handlers.ServeHTTP(w, r)
|
||||||
@ -124,8 +124,8 @@ func TestNamespaceFilter(t *testing.T) {
|
|||||||
ctx.Output.Body([]byte("this is Filter"))
|
ctx.Output.Body([]byte("this is Filter"))
|
||||||
}).
|
}).
|
||||||
Get("/user/:id", func(ctx *context.Context) {
|
Get("/user/:id", func(ctx *context.Context) {
|
||||||
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
||||||
})
|
})
|
||||||
AddNamespace(ns)
|
AddNamespace(ns)
|
||||||
BeeApp.Handlers.ServeHTTP(w, r)
|
BeeApp.Handlers.ServeHTTP(w, r)
|
||||||
if w.Body.String() != "this is Filter" {
|
if w.Body.String() != "this is Filter" {
|
||||||
|
@ -24,11 +24,11 @@ type MainController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *MainController) Get() {
|
func (this *MainController) Get() {
|
||||||
this.TplNames = "index.tpl"
|
this.TplName = "index.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MainController) Post() {
|
func (this *MainController) Post() {
|
||||||
this.TplNames = "index.tpl"
|
this.TplName = "index.tpl"
|
||||||
|
|
||||||
this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
|
this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,11 @@
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// func (this *MainController) Get() {
|
// func (this *MainController) Get() {
|
||||||
// this.TplNames = "index.tpl"
|
// this.TplName = "index.tpl"
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// func (this *MainController) Post() {
|
// func (this *MainController) Post() {
|
||||||
// this.TplNames = "index.tpl"
|
// this.TplName = "index.tpl"
|
||||||
//
|
//
|
||||||
// this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
|
// this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
|
||||||
// }
|
// }
|
||||||
|
Loading…
Reference in New Issue
Block a user