From acb124b7fbb4f38ec2489bff9e8a83cc5c511c9c Mon Sep 17 00:00:00 2001 From: andreimarcu Date: Thu, 24 Sep 2015 23:21:37 -0400 Subject: [PATCH] Add template globals, disable template caching while debug --- display.go | 3 +-- pages.go | 2 +- server.go | 8 ++++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/display.go b/display.go index 664c3be..b26a89a 100644 --- a/display.go +++ b/display.go @@ -37,7 +37,7 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) { if strings.HasPrefix(mimetype, "image/") { tpl = pongo2.Must(pongo2.FromCache("templates/display/image.html")) - } else if strings.HasPrefix(mimetype, "video/") { + } else if strings.HasPrefix(mimetype, "video/") { tpl = pongo2.Must(pongo2.FromCache("templates/display/video.html")) } else { tpl = pongo2.Must(pongo2.FromCache("templates/display/file.html")) @@ -45,7 +45,6 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) { err = tpl.ExecuteWriter(pongo2.Context{ "mime": mimetype, - "sitename": Config.siteName, "filename": fileName, "size": fileInfo.Size(), }, w) diff --git a/pages.go b/pages.go index f75645a..bf222c7 100644 --- a/pages.go +++ b/pages.go @@ -10,7 +10,7 @@ import ( func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) { indexTpl := pongo2.Must(pongo2.FromCache("templates/index.html")) - err := indexTpl.ExecuteWriter(pongo2.Context{"sitename": Config.siteName}, w) + err := indexTpl.ExecuteWriter(pongo2.Context{}, w) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } diff --git a/server.go b/server.go index a6e903b..c96befa 100644 --- a/server.go +++ b/server.go @@ -7,6 +7,7 @@ import ( "net/http" "regexp" + "github.com/flosch/pongo2" "github.com/zenazn/goji" ) @@ -25,6 +26,13 @@ func main() { "name of the site") flag.Parse() + // Disable template caching -- keep until out of pre-alpha + pongo2.DefaultSet.Debug = true // will keep this until out of pre-alpha + + // Template Globals + pongo2.DefaultSet.Globals["sitename"] = Config.siteName + + // Routing setup nameRe := regexp.MustCompile(`^/(?P[a-z0-9-\.]+)$`) selifRe := regexp.MustCompile(`^/selif/(?P[a-z0-9-\.]+)$`)