diff --git a/fixtures/basic/hello.tmpl b/fixtures/basic/hello.tmpl
new file mode 100644
index 00000000..0767ef3f
--- /dev/null
+++ b/fixtures/basic/hello.tmpl
@@ -0,0 +1 @@
+
Hello {[{.name}]}
\ No newline at end of file
diff --git a/gin.go b/gin.go
index 62f4472a..17b3755b 100644
--- a/gin.go
+++ b/gin.go
@@ -152,7 +152,8 @@ func (engine *Engine) SetHTMLTemplate(templ *template.Template) {
if len(engine.trees) > 0 {
debugPrintWARNINGSetHTMLTemplate()
}
- engine.HTMLRender = render.HTMLProduction{Template: templ, Delims: engine.delims}
+
+ engine.HTMLRender = render.HTMLProduction{Template: templ}
}
// NoRoute adds handlers for NoRoute. It return a 404 code by default.
diff --git a/gin_test.go b/gin_test.go
index cc24bc92..6bb2f1a9 100644
--- a/gin_test.go
+++ b/gin_test.go
@@ -8,11 +8,60 @@ import (
"reflect"
"testing"
+ "net/http"
+
+ "fmt"
+ "io/ioutil"
+
+ "time"
+
"github.com/stretchr/testify/assert"
)
+func setupHTMLFiles(t *testing.T) func() {
+ go func() {
+ router := New()
+ router.Delims("{[{", "}]}")
+ router.LoadHTMLFiles("./fixtures/basic/hello.tmpl")
+ router.GET("/test", func(c *Context) {
+ c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"})
+ })
+ router.Run(":8888")
+ }()
+ t.Log("waiting 1 second for server startup")
+ time.Sleep(1 * time.Second)
+ return func() {}
+}
+
+func setupHTMLGlob(t *testing.T) func() {
+ go func() {
+ router := New()
+ router.Delims("{[{", "}]}")
+ router.LoadHTMLGlob("./fixtures/basic/*")
+ router.GET("/test", func(c *Context) {
+ c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"})
+ })
+ router.Run(":8888")
+ }()
+ t.Log("waiting 1 second for server startup")
+ time.Sleep(1 * time.Second)
+ return func() {}
+}
+
//TODO
-// func (engine *Engine) LoadHTMLGlob(pattern string) {
+func TestLoadHTMLGlob(t *testing.T) {
+ td := setupHTMLGlob(t)
+ res, err := http.Get("http://127.0.0.1:8888/test")
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ resp, _ := ioutil.ReadAll(res.Body)
+ assert.Equal(t, "Hello world
", string(resp[:]))
+
+ td()
+}
+
// func (engine *Engine) LoadHTMLFiles(files ...string) {
// func (engine *Engine) RunTLS(addr string, cert string, key string) error {
@@ -42,6 +91,18 @@ func TestCreateEngine(t *testing.T) {
// SetMode(TestMode)
// }
+func TestLoadHTMLFiles(t *testing.T) {
+ td := setupHTMLFiles(t)
+ res, err := http.Get("http://127.0.0.1:8888/test")
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ resp, _ := ioutil.ReadAll(res.Body)
+ assert.Equal(t, "Hello world
", string(resp[:]))
+ td()
+}
+
func TestLoadHTMLReleaseMode(t *testing.T) {
}