Java Code Examples for com.hubspot.jinjava.interpret.JinjavaInterpreter#render()
The following examples show how to use
com.hubspot.jinjava.interpret.JinjavaInterpreter#render() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallTag.java From jinjava with Apache License 2.0 | 6 votes |
@Override public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) { String macroExpr = "{{" + tagNode.getHelpers().trim() + "}}"; try (InterpreterScopeClosable c = interpreter.enterScope()) { LinkedHashMap<String, Object> args = new LinkedHashMap<>(); MacroFunction caller = new MacroFunction( tagNode.getChildren(), "caller", args, true, interpreter.getContext(), interpreter.getLineNumber(), interpreter.getPosition() ); interpreter.getContext().addGlobalMacro(caller); return interpreter.render(macroExpr); } }
Example 2
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 6 votes |
@Test public void itAvoidsSimpleImportCycle() throws IOException { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.render( Resources.toString( Resources.getResource("tags/importtag/imports-self.jinja"), StandardCharsets.UTF_8 ) ); assertThat(context.get("c")).isEqualTo("hello"); assertThat(interpreter.getErrorsCopy().get(0).getMessage()) .contains("Import cycle detected", "imports-self.jinja"); }
Example 3
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 6 votes |
@Test public void itAvoidsNestedImportCycle() throws IOException { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.render( Resources.toString( Resources.getResource("tags/importtag/a-imports-b.jinja"), StandardCharsets.UTF_8 ) ); assertThat(context.get("a")).isEqualTo("foo"); assertThat(context.get("b")).isEqualTo("bar"); assertThat(interpreter.getErrorsCopy().get(0).getMessage()) .contains("Import cycle detected", "b-imports-a.jinja"); }
Example 4
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 5 votes |
@Test public void itImportsMacroWithCall() throws IOException { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); String renderResult = interpreter.render( Resources.toString( Resources.getResource("tags/importtag/imports-macro.jinja"), StandardCharsets.UTF_8 ) ); assertThat(renderResult.trim()).isEqualTo(""); assertThat(interpreter.getErrorsCopy()).hasSize(0); }