From 4c0c0ec2a7bd9e55fb64948ace96ddafda173725 Mon Sep 17 00:00:00 2001 From: ysqi Date: Thu, 7 Jan 2016 16:16:39 +0800 Subject: [PATCH] TplNames renamed TplName ,fix #1229,Remember modify bee tool. --- controller.go | 28 ++++++++++++++-------------- namespace_test.go | 12 ++++++------ utils/captcha/README.md | 4 ++-- utils/captcha/captcha.go | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/controller.go b/controller.go index 1d0d9025..3bc871cc 100644 --- a/controller.go +++ b/controller.go @@ -68,7 +68,7 @@ type Controller struct { AppController interface{} // template data - TplNames string + TplName string Layout string LayoutSections map[string]string // the key is the section name and the value is the template name TplExt string @@ -105,7 +105,7 @@ type ControllerInterface interface { // Init generates default values of controller operations. func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) { c.Layout = "" - c.TplNames = "" + c.TplName = "" c.controllerName = controllerName c.actionName = actionName 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 var buf bytes.Buffer if c.Layout != "" { - if c.TplNames == "" { - c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt + if c.TplName == "" { + c.TplName = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt } if BConfig.RunMode == DEV { - buildFiles := []string{c.TplNames} + buildFiles := []string{c.TplName} if c.LayoutSections != nil { for _, sectionTpl := range c.LayoutSections { if sectionTpl == "" { @@ -216,10 +216,10 @@ func (c *Controller) RenderBytes() ([]byte, error) { } BuildTemplate(BConfig.WebConfig.ViewsPath, buildFiles...) } - if _, ok := BeeTemplates[c.TplNames]; !ok { - panic("can't find templatefile in the path:" + c.TplNames) + if _, ok := BeeTemplates[c.TplName]; !ok { + 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 { Trace("template Execute err:", err) return nil, err @@ -252,17 +252,17 @@ func (c *Controller) RenderBytes() ([]byte, error) { return buf.Bytes(), nil } - if c.TplNames == "" { - c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt + if c.TplName == "" { + c.TplName = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt } if BConfig.RunMode == DEV { - BuildTemplate(BConfig.WebConfig.ViewsPath, c.TplNames) + BuildTemplate(BConfig.WebConfig.ViewsPath, c.TplName) } - if _, ok := BeeTemplates[c.TplNames]; !ok { - panic("can't find templatefile in the path:" + c.TplNames) + if _, ok := BeeTemplates[c.TplName]; !ok { + panic("can't find templatefile in the path:" + c.TplName) } 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 { Trace("template Execute err:", err) return nil, err diff --git a/namespace_test.go b/namespace_test.go index fc02b5fb..a92ae3ef 100644 --- a/namespace_test.go +++ b/namespace_test.go @@ -61,8 +61,8 @@ func TestNamespaceNest(t *testing.T) { ns.Namespace( NewNamespace("/admin"). Get("/order", func(ctx *context.Context) { - ctx.Output.Body([]byte("order")) - }), + ctx.Output.Body([]byte("order")) + }), ) AddNamespace(ns) BeeApp.Handlers.ServeHTTP(w, r) @@ -79,8 +79,8 @@ func TestNamespaceNestParam(t *testing.T) { ns.Namespace( NewNamespace("/admin"). 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) BeeApp.Handlers.ServeHTTP(w, r) @@ -124,8 +124,8 @@ func TestNamespaceFilter(t *testing.T) { ctx.Output.Body([]byte("this is Filter")) }). 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) BeeApp.Handlers.ServeHTTP(w, r) if w.Body.String() != "this is Filter" { diff --git a/utils/captcha/README.md b/utils/captcha/README.md index cbdd5bde..dbc2026b 100644 --- a/utils/captcha/README.md +++ b/utils/captcha/README.md @@ -24,11 +24,11 @@ type MainController struct { } func (this *MainController) Get() { - this.TplNames = "index.tpl" + this.TplName = "index.tpl" } func (this *MainController) Post() { - this.TplNames = "index.tpl" + this.TplName = "index.tpl" this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request) } diff --git a/utils/captcha/captcha.go b/utils/captcha/captcha.go index 3616cc7e..76301a03 100644 --- a/utils/captcha/captcha.go +++ b/utils/captcha/captcha.go @@ -37,11 +37,11 @@ // } // // func (this *MainController) Get() { -// this.TplNames = "index.tpl" +// this.TplName = "index.tpl" // } // // func (this *MainController) Post() { -// this.TplNames = "index.tpl" +// this.TplName = "index.tpl" // // this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request) // }