Merge pull request #750 from cqframework/master

Fix include resolution in LiquidRenderer
This commit is contained in:
Grahame Grieve 2022-03-03 07:46:12 +11:00 committed by GitHub
commit 38e84a46f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -32,12 +32,30 @@ public class LiquidRenderer extends ResourceRenderer {
this.rcontext = rcontext;
this.liquidTemplate = liquidTemplate;
}
/**
* This class provides an implementation of the ILiquidEngineIncludeResolver that makes use of the
* template provider available in the rendering context to support resolving includes.
*/
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(context, 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));
LiquidDocument doc = engine.parse(liquidTemplate, "template");
String html = engine.evaluate(doc, r, rcontext);
xn = new XhtmlParser().parseFragment(html);