Skip to content
Browse files

Layout will refresh itself if changed.

  • Loading branch information...
1 parent 1043fb5 commit 5b7120e8d7383eef5b98122a9a5c416d55005248 @TheOnly92 committed Dec 30, 2011
Showing with 21 additions and 0 deletions.
  1. +21 −0 bloody.go
View
21 bloody.go
@@ -19,6 +19,7 @@ var mSession *mgo.Session
var mongoInit = false
var h *session.MHandler
var config *Config
+var layoutChanged int64
var layout *mustache.Template
@@ -32,7 +33,20 @@ func initMongo() {
}
}
+func getLayoutChanged() int64 {
+ dir, _ := os.Getwd()
+ f, err := os.Open(dir+"/templates/layout.mustache")
+ if err != nil {
+ panic(err)
+ }
+ defer f.Close()
+
+ info, _ := f.Stat()
+ return info.ModTime().Unix()
+}
+
func initLayout() {
+ layoutChanged = getLayoutChanged()
layout, _ = mustache.ParseFile("templates/layout.mustache")
}
@@ -44,6 +58,13 @@ func render(output string, title string) string {
}
p := PageModelInit()
vars["SidePages"] = p.Sidebar()
+
+ // Check if layout is changed
+ if getLayoutChanged() != layoutChanged {
+ layoutChanged = getLayoutChanged()
+ layout, _ = mustache.ParseFile("templates/layout.mustache")
+ }
+
return layout.Render(vars)
}

0 comments on commit 5b7120e

Please sign in to comment.
Something went wrong with that request. Please try again.