Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

add layout based renderer

goenning07e12d629feb
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 81a43f63d..628e77577 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -10,6 +10,8 @@
"gin-bin.exe": true,
"wchy": true,
"wchy.exe": true,
- "tmp": true
- }
+ "tmp": true,
+ "vendor": true
+ },
+ "vsicons.presets.angular": false
}
\ No newline at end of file
diff --git a/handler/index.go b/handler/index.go
index 38e6aa11c..824d22445 100644
--- a/handler/index.go
+++ b/handler/index.go
@@ -19,7 +19,7 @@ func (h indexHandlder) get() gin.HandlerFunc {
return func(c *gin.Context) {
tenant := c.MustGet("Tenant").(*model.Tenant)
ideas, _ := h.ctx.Idea.GetAll(tenant.ID)
- c.HTML(200, "index.html", gin.H{
+ c.HTML(200, "index", gin.H{
"Tenant": tenant,
"Ideas": ideas,
})
diff --git a/mock/server.go b/mock/server.go
index 824e91476..2ad5fa439 100644
--- a/mock/server.go
+++ b/mock/server.go
@@ -4,11 +4,10 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
- "os"
- "path/filepath"
"strings"
+ "github.com/WeCanHearYou/wchy/router"
"github.com/gin-gonic/gin"
"github.com/jmoiron/jsonq"
)
@@ -21,7 +20,7 @@ type Server struct {
// NewServer creates a new test server
func NewServer() *Server {
engine := gin.New()
- engine.LoadHTMLGlob(filepath.Join(os.Getenv("GOPATH"), "src/github.com/WeCanHearYou/wchy/views/*"))
+ engine.HTMLRender = router.CreateTemplateRender()
return &Server{
engine: engine,
diff --git a/router/renderer.go b/router/renderer.go
new file mode 100644
index 000000000..711a8a60d
--- /dev/null
+++ b/router/renderer.go
@@ -0,0 +1,21 @@
+package router
+
+import (
+ "os"
+ "path/filepath"
+
+ "github.com/WeCanHearYou/wchy/env"
+ "github.com/gin-contrib/multitemplate"
+)
+
+func CreateTemplateRender() multitemplate.Render {
+ r := multitemplate.New()
+
+ path := filepath.Join(os.Getenv("GOPATH"), "src/github.com/WeCanHearYou/wchy/views")
+ if !env.IsTest() {
+ path = "views"
+ }
+
+ r.AddFromFiles("index", path+"/base.html", path+"/index.html")
+ return r
+}
diff --git a/router/router.go b/router/router.go
index cb8c17568..d12e3be3b 100644
--- a/router/router.go
+++ b/router/router.go
@@ -2,8 +2,6 @@ package router
import (
"net/http"
- "os"
- "path/filepath"
"github.com/WeCanHearYou/wchy/context"
"github.com/WeCanHearYou/wchy/handler"
@@ -15,6 +13,7 @@ import (
// GetMainEngine returns main HTTP engine
func GetMainEngine(ctx *context.WchyContext) *gin.Engine {
router := gin.New()
+ router.HTMLRender = CreateTemplateRender()
if env.IsDevelopment() {
gin.SetMode(gin.DebugMode)
@@ -23,12 +22,6 @@ func GetMainEngine(ctx *context.WchyContext) *gin.Engine {
}
router.Use(MultiTenant(ctx))
- if env.IsTest() {
- router.LoadHTMLGlob(filepath.Join(os.Getenv("GOPATH"), "src/github.com/WeCanHearYou/wchy/views/*"))
- } else {
- router.LoadHTMLGlob("views/*")
- }
-
router.GET("/", handler.Index(ctx))
api := router.Group("/api")
diff --git a/vendor/vendor.json b/vendor/vendor.json
index 862124ae9..d1dc2e1a9 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -1,11 +1,12 @@
{
"comment": "",
- "ignore": "test",
- "rootPath": "github.com/WeCanHearYou/wchy",
"heroku": {
- "install" : [ "./..." ],
- "goVersion": "go1.7"
+ "goVersion": "go1.7",
+ "install": [
+ "./..."
+ ]
},
+ "ignore": "test",
"package": [
{
"path": "appengine",
@@ -137,6 +138,12 @@
"revision": "42c364ba490082e4815b5222728711b3440603eb",
"revisionTime": "2017-01-13T15:16:12Z"
},
+ {
+ "checksumSHA1": "DU+rQjGYHOqFTEnI/ouieb1155g=",
+ "path": "github.com/gin-contrib/multitemplate",
+ "revision": "7a0692bde41e2af6e7811ba69bd05a5232351492",
+ "revisionTime": "2016-12-22T02:49:54Z"
+ },
{
"checksumSHA1": "RsNwOto8G8aXIiRrlFn4dtU9q/g=",
"path": "github.com/gin-gonic/gin",
diff --git a/views/base.html b/views/base.html
new file mode 100644
index 000000000..8d20b4ab6
--- /dev/null
+++ b/views/base.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8"/>
+ <meta name="viewport" content="width=device-width,initial-scale=1">
+ <link rel="stylesheet" type="text/css" href="/assets/semantic-ui-css/semantic.min.css">
+ <style type="text/css">
+ .ui.dividing.header,.first {
+ margin-top: 5em;
+ }
+ </style>
+ <title>{{block "title" .}}Default Title{{end}}</title>
+</head>
+<body>
+ <body>{{block "content" .}}This is the default body.{{end}}</body>
+</body>
+</html>
diff --git a/views/index.html b/views/index.html
index 06435c84f..6447d48e7 100644
--- a/views/index.html
+++ b/views/index.html
@@ -1,17 +1,8 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset="utf-8"/>
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <link rel="stylesheet" type="text/css" href="/assets/semantic-ui-css/semantic.min.css">
- <style type="text/css">
- .ui.dividing.header,.first {
- margin-top: 5em;
- }
- </style>
- <title>{{ .Tenant.Name }}</title>
-</head>
-<body>
+{{define "title"}}
+ {{ .Tenant.Name }}
+{{end}}
+
+{{define "content"}}
<div class="ui text container">
<h1 class="ui dividing header">{{ .Tenant.Name }}</h1>
<p>Welcome to our feedback forum.</p>
@@ -31,6 +22,4 @@
<div class="column"></div>
</div>
</div>
-
-</body>
-</html>
+{{end}}
\ No newline at end of file