public static Optional<JinjavaInterpreter> getCurrentMaybe() { return Optional.ofNullable(getCurrent()); }
@Override public Method resolveFunction(String prefix, String localName) { final Context context = JinjavaInterpreter.getCurrent().getContext(); MacroFunction macroFunction = context.getGlobalMacro(localName); if (macroFunction != null) { return AbstractCallableMethod.EVAL_METHOD; } final String functionName = buildFunctionName(prefix, localName); if (context.isFunctionDisabled(functionName)) { throw new DisabledException(functionName); } if (map.containsKey(functionName)) { context.addResolvedFunction(functionName); } return map.get(functionName); }
@Override public Object doEvaluate(Map<String, Object> argMap, Map<String, Object> kwargMap, List<Object> varArgs) { JinjavaInterpreter interpreter = JinjavaInterpreter.getCurrent(); try (InterpreterScopeClosable c = interpreter.enterScope()) { for (Map.Entry<String, Object> scopeEntry : localContextScope.getScope().entrySet()) { if (scopeEntry.getValue() instanceof MacroFunction) { interpreter.getContext().addGlobalMacro((MacroFunction) scopeEntry.getValue()); } else { interpreter.getContext().put(scopeEntry.getKey(), scopeEntry.getValue()); } } // named parameters for (Map.Entry<String, Object> argEntry : argMap.entrySet()) { interpreter.getContext().put(argEntry.getKey(), argEntry.getValue()); } // parameter map interpreter.getContext().put("kwargs", kwargMap); // varargs list interpreter.getContext().put("varargs", varArgs); LengthLimitingStringBuilder result = new LengthLimitingStringBuilder(interpreter.getConfig().getMaxOutputSize()); for (Node node : content) { result.append(node.render(interpreter)); } return result.toString(); } }
@JinjavaDoc(value = "Only usable within blocks, will render the contents of the parent block by calling super.", snippets = { @JinjavaSnippet(desc = "This gives back the results of the parent block", code = "{% block sidebar %}\n" + " <h3>Table Of Contents</h3>\n\n" + " ...\n" + " {{ super() }}\n" + "{% endblock %}") }) public static String renderSuperBlock() { JinjavaInterpreter interpreter = JinjavaInterpreter.getCurrent(); LengthLimitingStringBuilder result = new LengthLimitingStringBuilder(interpreter.getConfig().getMaxOutputSize()); List<? extends Node> superBlock = interpreter.getContext().getSuperBlock(); if (superBlock != null) { for (Node n : superBlock) { result.append(n.render(interpreter)); } } return result.toString(); }
Context context = new Context(globalContext, bindings, renderConfig.getDisabled()); JinjavaInterpreter parentInterpreter = JinjavaInterpreter.getCurrent(); if (parentInterpreter != null) { renderConfig = parentInterpreter.getConfig();