0f982c4a by astaxie

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

1 parent f78ceb82
...@@ -97,6 +97,10 @@ func (c *Config) Int(key string) (int, error) { ...@@ -97,6 +97,10 @@ func (c *Config) Int(key string) (int, error) {
97 return strconv.Atoi(c.data[key]) 97 return strconv.Atoi(c.data[key])
98 } 98 }
99 99
100 func (c *Config) Int64(key string) (int64, error) {
101 return strconv.ParseInt(c.data[key], 10, 64)
102 }
103
100 // Float returns the float value for a given key. 104 // Float returns the float value for a given key.
101 func (c *Config) Float(key string) (float64, error) { 105 func (c *Config) Float(key string) (float64, error) {
102 return strconv.ParseFloat(c.data[key], 64) 106 return strconv.ParseFloat(c.data[key], 64)
......
...@@ -98,19 +98,30 @@ func (c *Controller) Render() error { ...@@ -98,19 +98,30 @@ func (c *Controller) Render() error {
98 98
99 func (c *Controller) RenderBytes() ([]byte, error) { 99 func (c *Controller) RenderBytes() ([]byte, error) {
100 //if the controller has set layout, then first get the tplname's content set the content to the layout 100 //if the controller has set layout, then first get the tplname's content set the content to the layout
101 var t *template.Template
102 var err error
101 if c.Layout != "" { 103 if c.Layout != "" {
102 if c.TplNames == "" { 104 if c.TplNames == "" {
103 c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt 105 c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt
104 } 106 }
105 _, file := path.Split(c.TplNames) 107 if RunMode == "dev" {
108 t, err = template.New("beegoTemplate").Funcs(beegoTplFuncMap).ParseFiles(path.Join(ViewsPath, c.TplNames), path.Join(ViewsPath, c.Layout))
109 if err != nil {
110 Trace("template ParseFiles err:", err)
111 }
112 } else {
106 subdir := path.Dir(c.TplNames) 113 subdir := path.Dir(c.TplNames)
114 t = BeeTemplates[subdir]
115 }
116 _, file := path.Split(c.TplNames)
117
107 newbytes := bytes.NewBufferString("") 118 newbytes := bytes.NewBufferString("")
108 BeeTemplates[subdir].ExecuteTemplate(newbytes, file, c.Data) 119 t.ExecuteTemplate(newbytes, file, c.Data)
109 tplcontent, _ := ioutil.ReadAll(newbytes) 120 tplcontent, _ := ioutil.ReadAll(newbytes)
110 c.Data["LayoutContent"] = template.HTML(string(tplcontent)) 121 c.Data["LayoutContent"] = template.HTML(string(tplcontent))
111 _, file = path.Split(c.Layout) 122 _, file = path.Split(c.Layout)
112 ibytes := bytes.NewBufferString("") 123 ibytes := bytes.NewBufferString("")
113 err := BeeTemplates[subdir].ExecuteTemplate(ibytes, file, c.Data) 124 err := t.ExecuteTemplate(ibytes, file, c.Data)
114 if err != nil { 125 if err != nil {
115 Trace("template Execute err:", err) 126 Trace("template Execute err:", err)
116 } 127 }
...@@ -120,10 +131,18 @@ func (c *Controller) RenderBytes() ([]byte, error) { ...@@ -120,10 +131,18 @@ func (c *Controller) RenderBytes() ([]byte, error) {
120 if c.TplNames == "" { 131 if c.TplNames == "" {
121 c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt 132 c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt
122 } 133 }
123 _, file := path.Split(c.TplNames) 134 if RunMode == "dev" {
135 t, err = template.New("beegoTemplate").Funcs(beegoTplFuncMap).ParseFiles(path.Join(ViewsPath, c.TplNames))
136 if err != nil {
137 Trace("template ParseFiles err:", err)
138 }
139 } else {
124 subdir := path.Dir(c.TplNames) 140 subdir := path.Dir(c.TplNames)
141 t = BeeTemplates[subdir]
142 }
143 _, file := path.Split(c.TplNames)
125 ibytes := bytes.NewBufferString("") 144 ibytes := bytes.NewBufferString("")
126 err := BeeTemplates[subdir].ExecuteTemplate(ibytes, file, c.Data) 145 err := t.ExecuteTemplate(ibytes, file, c.Data)
127 if err != nil { 146 if err != nil {
128 Trace("template Execute err:", err) 147 Trace("template Execute err:", err)
129 } 148 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!