1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

api changes in context

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-04-06 08:09:38 -07:00
parent eed30582ae
commit cff9ce5ae6
2 changed files with 8 additions and 8 deletions

View File

@ -56,7 +56,7 @@ func (c *Context) Render(code int, i interface{}) error {
return c.String(code, i.(string))
} else if strings.HasPrefix(a, MIMEHTML) {
}
return c.HTML(code, i.(string))
return c.HTMLString(code, i.(string))
}
// JSON sends an application/json response with status code.
@ -74,17 +74,17 @@ func (c *Context) String(code int, s string) (err error) {
return
}
// HTML sends a text/html response with status code.
func (c *Context) HTML(code int, html string) (err error) {
// HTMLString sends a text/html response with status code.
func (c *Context) HTMLString(code int, html string) (err error) {
c.Response.Header().Set(HeaderContentType, MIMEHTML+"; charset=utf-8")
c.Response.WriteHeader(code)
_, err = c.Response.Write([]byte(html))
return
}
// HTMLTemplate applies the template associated with t that has the given name to
// HTML applies the template associated with t that has the given name to
// the specified data object and sends a text/html response with status code.
func (c *Context) HTMLTemplate(code int, t *template.Template, name string, data interface{}) (err error) {
func (c *Context) HTML(code int, t *template.Template, name string, data interface{}) (err error) {
return t.ExecuteTemplate(c.Response, name, data)
}

View File

@ -83,17 +83,17 @@ func TestContext(t *testing.T) {
t.Errorf("render string %v", err)
}
// HTML
// HTML string
r.Header.Set(HeaderAccept, MIMEHTML)
c.Response.committed = false
if err := c.Render(http.StatusOK, "Hello, <strong>World!</strong>"); err != nil {
t.Errorf("render html %v", err)
}
// HTML template
// HTML
c.Response.committed = false
tmpl, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
if err := c.HTMLTemplate(http.StatusOK, tmpl, "T", "Joe"); err != nil {
if err := c.HTML(http.StatusOK, tmpl, "T", "Joe"); err != nil {
t.Errorf("render html template %v", err)
}