Skip to content

Commit

Permalink
add files From Glob
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Dec 21, 2016
1 parent ba668c0 commit 4b92988
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
25 changes: 23 additions & 2 deletions multitemplate_test.go
Expand Up @@ -16,16 +16,23 @@ func performRequest(r http.Handler, method, path string) *httptest.ResponseRecor
return w
}

func createMyRender() Render {
func createFromFile() Render {
r := New()
r.AddFromFiles("index", "tests/base.html", "tests/article.html")

return r
}

func createFromGlob() Render {
r := New()
r.AddFromGlob("index", "tests/global/*")

return r
}

func TestAddFromFiles(t *testing.T) {
router := gin.New()
router.HTMLRender = createMyRender()
router.HTMLRender = createFromFile()
router.GET("/", func(c *gin.Context) {
c.HTML(200, "index", gin.H{
"title": "Test Multiple Template",
Expand All @@ -36,3 +43,17 @@ func TestAddFromFiles(t *testing.T) {
assert.Equal(t, 200, w.Code)
assert.Equal(t, "<p>Test Multiple Template</p>\nHi, this is article template\n", w.Body.String())
}

func TestAddFromGlob(t *testing.T) {
router := gin.New()
router.HTMLRender = createFromGlob()
router.GET("/", func(c *gin.Context) {
c.HTML(200, "index", gin.H{
"title": "Test Multiple Template",
})
})

w := performRequest(router, "GET", "/")
assert.Equal(t, 200, w.Code)
assert.Equal(t, "<p>Test Multiple Template</p>\nHi, this is login template\n", w.Body.String())
}
2 changes: 2 additions & 0 deletions tests/global/base.html
@@ -0,0 +1,2 @@
<p>{{ .title }}</p>
{{template "login.html"}}
1 change: 1 addition & 0 deletions tests/global/login.html
@@ -0,0 +1 @@
{{define "login.html"}}Hi, this is login template{{end}}

0 comments on commit 4b92988

Please sign in to comment.