Sfoglia il codice sorgente

allow icon js debug loading. only load debug template if newer than jar

pull/44/head
Jonathan Cobb 4 anni fa
parent
commit
628df3bf35
2 ha cambiato i file con 10 aggiunte e 5 eliminazioni
  1. +8
    -4
      bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java
  2. +2
    -1
      bubble-server/src/main/java/bubble/rule/RequestModifierRule.java

+ 8
- 4
bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java Vedi File

@@ -39,6 +39,7 @@ import java.util.Map;


import static bubble.ApiConstants.HOME_DIR; import static bubble.ApiConstants.HOME_DIR;
import static bubble.rule.RequestModifierRule.ICON_JS_TEMPLATE; import static bubble.rule.RequestModifierRule.ICON_JS_TEMPLATE;
import static bubble.rule.RequestModifierRule.ICON_JS_TEMPLATE_NAME;
import static org.cobbzilla.util.daemon.ZillaRuntime.die; import static org.cobbzilla.util.daemon.ZillaRuntime.die;
import static org.cobbzilla.util.daemon.ZillaRuntime.empty; import static org.cobbzilla.util.daemon.ZillaRuntime.empty;
import static org.cobbzilla.util.io.FileUtil.abs; import static org.cobbzilla.util.io.FileUtil.abs;
@@ -122,14 +123,16 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {
return loadTemplate(defaultSiteTemplate, requestModConfig().getSiteJsTemplate()); return loadTemplate(defaultSiteTemplate, requestModConfig().getSiteJsTemplate());
} }


@Getter(lazy=true) private final long jarTime = configuration.getBubbleJar().lastModified();

protected String loadTemplate(String defaultTemplate, String templatePath) { protected String loadTemplate(String defaultTemplate, String templatePath) {
if (configuration.getEnvironment().containsKey("DEBUG_RULE_TEMPLATES")) { if (configuration.getEnvironment().containsKey("DEBUG_RULE_TEMPLATES")) {
final File templateFile = new File(HOME_DIR + "/debugTemplates/" + templatePath); final File templateFile = new File(HOME_DIR + "/debugTemplates/" + templatePath);
if (templateFile.exists()) {
log.error("loadTemplate: debug file found (using it): "+abs(templateFile));
if (templateFile.exists() && templateFile.lastModified() > getJarTime()) {
log.error("loadTemplate: debug file found and newer than bubble jar, using it: "+abs(templateFile));
return FileUtil.toStringOrDie(templateFile); return FileUtil.toStringOrDie(templateFile);
} else { } else {
log.error("loadTemplate: debug file not found (using default): "+abs(templateFile));
log.error("loadTemplate: debug file not found or older than bubble jar, using default: "+abs(templateFile));
} }
} }
return defaultTemplate; return defaultTemplate;
@@ -185,7 +188,8 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {
ctx.put(siteJsInsertionVar, siteJs); ctx.put(siteJsInsertionVar, siteJs);
} }
if (showIcon) { if (showIcon) {
ctx.put(CTX_ICON_JS, HandlebarsUtil.apply(getHandlebars(), ICON_JS_TEMPLATE, ctx));
final String iconJs = loadTemplate(ICON_JS_TEMPLATE, ICON_JS_TEMPLATE_NAME);
ctx.put(CTX_ICON_JS, HandlebarsUtil.apply(getHandlebars(), iconJs, ctx));
} }
return HandlebarsUtil.apply(getHandlebars(), bubbleJsTemplate, ctx); return HandlebarsUtil.apply(getHandlebars(), bubbleJsTemplate, ctx);
} }


+ 2
- 1
bubble-server/src/main/java/bubble/rule/RequestModifierRule.java Vedi File

@@ -12,6 +12,7 @@ public interface RequestModifierRule {
RequestModifierConfig getRequestModifierConfig (); RequestModifierConfig getRequestModifierConfig ();


Class<RequestModifierRule> RMR = RequestModifierRule.class; Class<RequestModifierRule> RMR = RequestModifierRule.class;
String ICON_JS_TEMPLATE = stream2string(getPackagePath(RMR)+"/"+ RMR.getSimpleName()+"_icon.js.hbs");
String ICON_JS_TEMPLATE_NAME = RMR.getSimpleName() + "_icon.js.hbs";
String ICON_JS_TEMPLATE = stream2string(getPackagePath(RMR) + "/" + ICON_JS_TEMPLATE_NAME);


} }

Caricamento…
Annulla
Salva