Skip to content

Commit

Permalink
refactors HandlebarsEngine context.model() and assign helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa committed Dec 13, 2024
1 parent 7413cf8 commit a62bc55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,16 @@ public static Object uncapFirst(String text, Options options) throws IOException
}

public static Object assign(final String variableName, final Options options) throws IOException {
var model = (Map) options.context.model();
if (options.params.length == 1) {
if (options.param(0) != null) {
options.context.combine(Map.of(variableName, options.param(0)));
model.put(variableName, options.param(0));
} else {

}
} else {
CharSequence finalValue = options.apply(options.fn);
options.context.combine(Map.of(variableName, finalValue.toString().trim()));
model.put(variableName, finalValue.toString().trim());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public List<TemplateOutput> processTemplates(Map<String, Object> model, List<Tem

@Override
public List<TemplateOutput> processTemplates(String modelPrefix, Map<String, Object> apiModel, List<TemplateInput> templateInputs) {
Context context = Context.newBuilder(this.context).build();
if (modelPrefix != null) {
context.combine(modelPrefix, apiModel);
} else {
context.combine(apiModel);
}
var currentModel = new HashMap((Map)context.model());
((Map) context.model()).putAll(apiModel);
// Context context = Context.newBuilder(this.context).build();
// if (modelPrefix != null) {
// context.combine(modelPrefix, apiModel);
// } else {
// context.combine(apiModel);
// }
List<TemplateOutput> templateOutputList = new ArrayList<>();
templateInputs.forEach(templateInput -> {
if (templateInput.getSkip() == null || !Boolean.TRUE.equals(templateInput.getSkip().apply(apiModel))) {
Expand All @@ -66,6 +68,8 @@ public List<TemplateOutput> processTemplates(String modelPrefix, Map<String, Obj
}
}
});
((Map<?, ?>) context.model()).clear();
((Map) context.model()).putAll(currentModel);
return templateOutputList;
}
}

0 comments on commit a62bc55

Please sign in to comment.