Added a Liquid template resolver to narrative generation to support include resolution in the publisher

This commit is contained in:
Bryn Rhodes 2022-02-21 15:05:42 -07:00
parent a63b2b2515
commit ab329c8c63
1 changed files with 14 additions and 0 deletions

View File

@ -32,12 +32,26 @@ public class LiquidRenderer extends ResourceRenderer {
this.rcontext = rcontext;
this.liquidTemplate = liquidTemplate;
}
private class LiquidRendererIncludeResolver implements LiquidEngine.ILiquidEngineIncludeResolver {
public LiquidRendererIncludeResolver(RenderingContext context) {
this.context = context;
}
private RenderingContext context;
@Override
public String fetchInclude(LiquidEngine engine, String name) {
return context.getTemplateProvider().findTemplate(name);
}
}
@Override
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
XhtmlNode xn;
try {
engine.setIncludeResolver(new LiquidRendererIncludeResolver(context.getTemplateProvider()));
LiquidDocument doc = engine.parse(liquidTemplate, "template");
String html = engine.evaluate(doc, r, rcontext);
xn = new XhtmlParser().parseFragment(html);