Merge pull request #2 from cqframework/fix-liquid-template-resolver
Added a Liquid template resolver to narrative generation to support i…
This commit is contained in:
commit
3d30d946b7
|
@ -32,12 +32,30 @@ public class LiquidRenderer extends ResourceRenderer {
|
||||||
this.rcontext = rcontext;
|
this.rcontext = rcontext;
|
||||||
this.liquidTemplate = liquidTemplate;
|
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(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
|
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
|
||||||
LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
|
LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
|
||||||
XhtmlNode xn;
|
XhtmlNode xn;
|
||||||
try {
|
try {
|
||||||
|
engine.setIncludeResolver(new LiquidRendererIncludeResolver(context.getTemplateProvider()));
|
||||||
LiquidDocument doc = engine.parse(liquidTemplate, "template");
|
LiquidDocument doc = engine.parse(liquidTemplate, "template");
|
||||||
String html = engine.evaluate(doc, r, rcontext);
|
String html = engine.evaluate(doc, r, rcontext);
|
||||||
xn = new XhtmlParser().parseFragment(html);
|
xn = new XhtmlParser().parseFragment(html);
|
||||||
|
|
Loading…
Reference in New Issue