void doRenderMulti(RapidoidThreadLocals locals, Writable output, List<Object> model) { // start using the render context RenderCtxImpl renderCtx = getRenderCtx(locals); renderCtx.out(output).factory(factory).filename(filename).multiModel(model); template.render(renderCtx); // stop using the render context renderCtx.reset(); }
void doRender(RapidoidThreadLocals locals, Writable output, Object model) { // start using the render context RenderCtxImpl renderCtx = getRenderCtx(locals); renderCtx.out(output).factory(factory).filename(filename).model(model); template.render(renderCtx); // stop using the render context renderCtx.reset(); }
@Override public Template compile(String source, Class<?> modelType) { return new RapidoidTemplate(null, TemplateParser.parse(source).compile(modelType), this); }
@Override public void call(String name) { RapidoidTemplate template = (RapidoidTemplate) factory.load(name + ext, Object.class); template.renderInContext(this); }
private RenderCtxImpl getRenderCtx(RapidoidThreadLocals locals) { RenderCtxImpl renderCtx = (RenderCtxImpl) locals.renderContext; if (renderCtx == null) { renderCtx = new RenderCtxImpl(); locals.renderContext = renderCtx; } if (!renderCtx.busy()) { renderCtx.claim(); return renderCtx; } else { return new RenderCtxImpl(); } }
protected TemplateRenderer loadTemplate(String filename) { String content; try { content = templateStore.loadTemplate(filename); } catch (Exception e) { throw U.rte("Couldn't load template: " + filename, e); } return TemplateParser.parse(content).compile(); }
@Override public void cleanUp() { Templates.reset(); }
public RapidoidTemplate loadAndCompile(String filename) { return new RapidoidTemplate(filename, loadTemplate(filename), this); }
public static String[] templatesPath() { return Templates.getPath(); }
protected View view(final Template template) { return (model, out) -> template.renderTo(out, model); }
public static Template compile(String source) { return compile(source, Object.class); }
private static String expr(Map<String, String> expressions, String expr) { expressions.put(expr, literal(expr)); return TemplateCompiler.retrieverId(expr); }
public static TemplateRenderer compile(XNode node, Class<?> modelType) { try { Map<String, String> expressions = U.map(); Map<String, String> constants = U.map(); String source = TemplateToCode.generate(node, expressions, constants, modelType); return tryToCompile(source, expressions, constants, modelType); } catch (Exception e) { throw U.rte(e); } }
public static void reset() { PATH = DEFAULT_PATH; DEFAULT_FACTORY.reset(); }
@Override public void val(ValueRetriever retriever, boolean escape) throws IOException { valOr(retriever, "N/A", escape); }
public RenderCtxImpl filename(String filename) { this.ext = calcFileExt(filename); return this; }
public TemplateRenderer compile() { return compile(Object.class); }
@Override public void restartApp() { Templates.reset(); }