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,6 +101,10 @@ func bundleCSS(cssfiles []string) {
101 101
 
102 102
 func BundleStaticAssets() {
103 103
 
104
+	if ShouldBundleStaticAssets == false {
105
+		return
106
+	}
107
+
104 108
 	jsfiles := findStaticAssets(".js", CogStaticAssetsSearchPaths)
105 109
 	bundleJavaScript(jsfiles)
106 110
 	cssfiles := findStaticAssets(".css", CogStaticAssetsSearchPaths)

+ 1
- 0
template.go View File

@@ -29,6 +29,7 @@ var (
29 29
 	TemplateFilesPath            = "./templates"
30 30
 	UseStaticTemplateBundleFile  = false
31 31
 	StaticTemplateBundleFilePath = ""
32
+	ShouldBundleStaticAssets     = true
32 33
 )
33 34
 
34 35
 type Template struct {

+ 8
- 4
templateset.go View File

@@ -172,8 +172,13 @@ func (t *TemplateSet) RestoreTemplateBundleFromDisk() error {
172 172
 
173 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 184
 	bundle := NewTemplateBundle()
@@ -197,7 +202,7 @@ func (t *TemplateSet) GatherTemplates() {
197 202
 
198 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 206
 		return
202 207
 	}
203 208
 
@@ -223,7 +228,6 @@ func (t *TemplateSet) GatherCogTemplates(cogTemplatePath string, prefixName stri
223 228
 func StaticTemplateBundleFileExists() bool {
224 229
 
225 230
 	if _, err := os.Stat(StaticTemplateBundleFilePath); os.IsNotExist(err) {
226
-
227 231
 		return false
228 232
 	} else {
229 233
 		return true