Przeglądaj źródła

apply handlebars to onlyIf/unless checks

tags/2.0.1
Jonathan Cobb 4 lat temu
rodzic
commit
33c38a7d30
2 zmienionych plików z 10 dodań i 8 usunięć
  1. +1
    -1
      wizard-common/src/main/java/org/cobbzilla/wizard/client/script/ApiRunner.java
  2. +9
    -7
      wizard-common/src/main/java/org/cobbzilla/wizard/client/script/ApiScript.java

+ 1
- 1
wizard-common/src/main/java/org/cobbzilla/wizard/client/script/ApiRunner.java Wyświetl plik

@@ -142,7 +142,7 @@ public class ApiRunner {
public boolean run(ApiScript script) throws Exception {
if (listener != null) listener.setCtxVars(ctx);
currentApi = script.getConnection(this.api, currentApi, alternateApis, getHandlebars(), ctx);
if (script.shouldSkip(js, ctx)) return true;
if (script.shouldSkip(js, getHandlebars(), ctx)) return true;
if (script.hasInclude()) {
if (script.isIncludeDefaults()) return true; // skip this block. used in validation before running included script
final String logPrefix = (script.hasComment() ? script.getComment()+"\n" : "") + ">>> ";


+ 9
- 7
wizard-common/src/main/java/org/cobbzilla/wizard/client/script/ApiScript.java Wyświetl plik

@@ -138,14 +138,15 @@ public class ApiScript {
}
}

public boolean shouldSkip(StandardJsEngine js, Map<String, Object> ctx) {
public boolean shouldSkip(StandardJsEngine js, Handlebars handlebars, Map<String, Object> ctx) {
if (hasOnlyIf()) {
try {
if (js.evaluateBoolean(getOnlyIf(), ctx, false)) {
log.info("onlyIf '"+getOnlyIf()+"' returned true, NOT skipping script");
final String onlyIf = HandlebarsUtil.apply(handlebars, getOnlyIf(), ctx);
if (js.evaluateBoolean(onlyIf, ctx, false)) {
log.info("onlyIf '"+onlyIf+"' returned true, NOT skipping script");
return false;
} else {
log.info("onlyIf '"+getOnlyIf()+"' returned false, skipping script");
log.info("onlyIf '"+onlyIf+"' returned false, skipping script");
return true;
}
} catch (Exception e) {
@@ -154,11 +155,12 @@ public class ApiScript {
}
if (hasUnless()) {
try {
if (js.evaluateBoolean(getUnless(), ctx, false)) {
log.info("unless '"+getUnless()+"' returned true, skipping script");
final String unless = HandlebarsUtil.apply(handlebars, getUnless(), ctx);
if (js.evaluateBoolean(unless, ctx, false)) {
log.info("unless '"+unless+"' returned true, skipping script");
return true;
} else {
log.info("unless '"+getUnless()+"' returned false, NOT skipping script");
log.info("unless '"+unless+"' returned false, NOT skipping script");
return false;
}
} catch (Exception e) {


Ładowanie…
Anuluj
Zapisz