use of io.kestra.core.runners.pebble.JsonWriter in project kestra by kestra-io.
the class VariableRenderer method recursiveRender.
public String recursiveRender(String inline, Map<String, Object> variables) throws IllegalVariableEvaluationException {
if (inline == null) {
return null;
}
boolean isSame = false;
String currentTemplate = inline;
String current = "";
PebbleTemplate compiledTemplate;
while (!isSame) {
try {
compiledTemplate = pebbleEngine.getLiteralTemplate(currentTemplate);
Writer writer = new JsonWriter(new StringWriter());
compiledTemplate.evaluate(writer, variables);
current = writer.toString();
} catch (IOException | PebbleException e) {
if (this.variableConfiguration.disableHandlebars) {
if (e instanceof PebbleException) {
throw properPebbleException((PebbleException) e);
}
throw new IllegalVariableEvaluationException(e);
}
try {
Template template = handlebars.compileInline(currentTemplate);
current = template.apply(variables);
} catch (HandlebarsException | IOException hbE) {
throw new IllegalVariableEvaluationException("Pebble evaluation failed with '" + e.getMessage() + "' " + "and Handlebars fallback failed also with '" + hbE.getMessage() + "'", e);
}
}
isSame = currentTemplate.equals(current);
currentTemplate = current;
}
return current;
}
Aggregations