Browse Source

Added setting to enable and disable the static assets bundling

Wirecog 6 years ago
parent
commit
9a45095ae3
3 changed files with 13 additions and 4 deletions
  1. 4
    0
      static.go
  2. 1
    0
      template.go
  3. 8
    4
      templateset.go

+ 4
- 0
static.go View File

101
 
101
 
102
 func BundleStaticAssets() {
102
 func BundleStaticAssets() {
103
 
103
 
104
+	if ShouldBundleStaticAssets == false {
105
+		return
106
+	}
107
+
104
 	jsfiles := findStaticAssets(".js", CogStaticAssetsSearchPaths)
108
 	jsfiles := findStaticAssets(".js", CogStaticAssetsSearchPaths)
105
 	bundleJavaScript(jsfiles)
109
 	bundleJavaScript(jsfiles)
106
 	cssfiles := findStaticAssets(".css", CogStaticAssetsSearchPaths)
110
 	cssfiles := findStaticAssets(".css", CogStaticAssetsSearchPaths)

+ 1
- 0
template.go View File

29
 	TemplateFilesPath            = "./templates"
29
 	TemplateFilesPath            = "./templates"
30
 	UseStaticTemplateBundleFile  = false
30
 	UseStaticTemplateBundleFile  = false
31
 	StaticTemplateBundleFilePath = ""
31
 	StaticTemplateBundleFilePath = ""
32
+	ShouldBundleStaticAssets     = true
32
 )
33
 )
33
 
34
 
34
 type Template struct {
35
 type Template struct {

+ 8
- 4
templateset.go View File

172
 
172
 
173
 func (t *TemplateSet) GatherTemplates() {
173
 func (t *TemplateSet) GatherTemplates() {
174
 
174
 
175
-	if UseStaticTemplateBundleFile == true && StaticTemplateBundleFileExists() == true {
176
-		return
175
+	if UseStaticTemplateBundleFile == true {
176
+		err := t.RestoreTemplateBundleFromDisk()
177
+		if err != nil {
178
+			log.Println("Didn't find a template bundle from disk, will generate a new template bundle.")
179
+		} else {
180
+			return
181
+		}
177
 	}
182
 	}
178
 
183
 
179
 	bundle := NewTemplateBundle()
184
 	bundle := NewTemplateBundle()
197
 
202
 
198
 func (t *TemplateSet) GatherCogTemplates(cogTemplatePath string, prefixName string, templateFileExtension string) {
203
 func (t *TemplateSet) GatherCogTemplates(cogTemplatePath string, prefixName string, templateFileExtension string) {
199
 
204
 
200
-	if UseStaticTemplateBundleFile == true && StaticTemplateBundleFileExists() == true {
205
+	if ShouldBundleStaticAssets == false || UseStaticTemplateBundleFile == true {
201
 		return
206
 		return
202
 	}
207
 	}
203
 
208
 
223
 func StaticTemplateBundleFileExists() bool {
228
 func StaticTemplateBundleFileExists() bool {
224
 
229
 
225
 	if _, err := os.Stat(StaticTemplateBundleFilePath); os.IsNotExist(err) {
230
 	if _, err := os.Stat(StaticTemplateBundleFilePath); os.IsNotExist(err) {
226
-
227
 		return false
231
 		return false
228
 	} else {
232
 	} else {
229
 		return true
233
 		return true