1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 19:50:56 +00:00

add Config.Int64 and Template add Runmode==dev everytime parsefile

This commit is contained in:
astaxie 2013-04-02 23:57:15 +08:00
parent f78ceb82d9
commit 0f982c4a18
2 changed files with 28 additions and 5 deletions

View File

@ -97,6 +97,10 @@ func (c *Config) Int(key string) (int, error) {
return strconv.Atoi(c.data[key]) return strconv.Atoi(c.data[key])
} }
func (c *Config) Int64(key string) (int64, error) {
return strconv.ParseInt(c.data[key], 10, 64)
}
// Float returns the float value for a given key. // Float returns the float value for a given key.
func (c *Config) Float(key string) (float64, error) { func (c *Config) Float(key string) (float64, error) {
return strconv.ParseFloat(c.data[key], 64) return strconv.ParseFloat(c.data[key], 64)

View File

@ -98,19 +98,30 @@ func (c *Controller) Render() error {
func (c *Controller) RenderBytes() ([]byte, error) { 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 t *template.Template
var err error
if c.Layout != "" { if c.Layout != "" {
if c.TplNames == "" { if c.TplNames == "" {
c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt
} }
_, file := path.Split(c.TplNames) if RunMode == "dev" {
t, err = template.New("beegoTemplate").Funcs(beegoTplFuncMap).ParseFiles(path.Join(ViewsPath, c.TplNames), path.Join(ViewsPath, c.Layout))
if err != nil {
Trace("template ParseFiles err:", err)
}
} else {
subdir := path.Dir(c.TplNames) subdir := path.Dir(c.TplNames)
t = BeeTemplates[subdir]
}
_, file := path.Split(c.TplNames)
newbytes := bytes.NewBufferString("") newbytes := bytes.NewBufferString("")
BeeTemplates[subdir].ExecuteTemplate(newbytes, file, c.Data) t.ExecuteTemplate(newbytes, file, c.Data)
tplcontent, _ := ioutil.ReadAll(newbytes) tplcontent, _ := ioutil.ReadAll(newbytes)
c.Data["LayoutContent"] = template.HTML(string(tplcontent)) c.Data["LayoutContent"] = template.HTML(string(tplcontent))
_, file = path.Split(c.Layout) _, file = path.Split(c.Layout)
ibytes := bytes.NewBufferString("") ibytes := bytes.NewBufferString("")
err := BeeTemplates[subdir].ExecuteTemplate(ibytes, file, c.Data) err := t.ExecuteTemplate(ibytes, file, c.Data)
if err != nil { if err != nil {
Trace("template Execute err:", err) Trace("template Execute err:", err)
} }
@ -120,10 +131,18 @@ func (c *Controller) RenderBytes() ([]byte, error) {
if c.TplNames == "" { if c.TplNames == "" {
c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt
} }
_, file := path.Split(c.TplNames) if RunMode == "dev" {
t, err = template.New("beegoTemplate").Funcs(beegoTplFuncMap).ParseFiles(path.Join(ViewsPath, c.TplNames))
if err != nil {
Trace("template ParseFiles err:", err)
}
} else {
subdir := path.Dir(c.TplNames) subdir := path.Dir(c.TplNames)
t = BeeTemplates[subdir]
}
_, file := path.Split(c.TplNames)
ibytes := bytes.NewBufferString("") ibytes := bytes.NewBufferString("")
err := BeeTemplates[subdir].ExecuteTemplate(ibytes, file, c.Data) err := t.ExecuteTemplate(ibytes, file, c.Data)
if err != nil { if err != nil {
Trace("template Execute err:", err) Trace("template Execute err:", err)
} }