Add template globals, disable template caching while debug

This commit is contained in:
andreimarcu 2015-09-24 23:21:37 -04:00
parent 1f1211e81e
commit acb124b7fb
3 changed files with 10 additions and 3 deletions

View File

@ -37,7 +37,7 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(mimetype, "image/") { if strings.HasPrefix(mimetype, "image/") {
tpl = pongo2.Must(pongo2.FromCache("templates/display/image.html")) 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")) tpl = pongo2.Must(pongo2.FromCache("templates/display/video.html"))
} else { } else {
tpl = pongo2.Must(pongo2.FromCache("templates/display/file.html")) 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{ err = tpl.ExecuteWriter(pongo2.Context{
"mime": mimetype, "mime": mimetype,
"sitename": Config.siteName,
"filename": fileName, "filename": fileName,
"size": fileInfo.Size(), "size": fileInfo.Size(),
}, w) }, w)

View File

@ -10,7 +10,7 @@ import (
func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) { func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) {
indexTpl := pongo2.Must(pongo2.FromCache("templates/index.html")) 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 { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
} }

View File

@ -7,6 +7,7 @@ import (
"net/http" "net/http"
"regexp" "regexp"
"github.com/flosch/pongo2"
"github.com/zenazn/goji" "github.com/zenazn/goji"
) )
@ -25,6 +26,13 @@ func main() {
"name of the site") "name of the site")
flag.Parse() 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<name>[a-z0-9-\.]+)$`) nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`) selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)