Java Code Examples for com.hubspot.jinjava.Jinjava#getGlobalConfig()
The following examples show how to use
com.hubspot.jinjava.Jinjava#getGlobalConfig() .
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: 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 2
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 3
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 6 votes |
@Test public void itDoesNotRenderTagsDependingOnDeferredImport() { try { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.getContext().put("primary_font_size_num", DeferredValue.instance()); String renderedImport = fixture("import-property-global"); assertThat(renderedImport) .isEqualTo( Resources.toString( Resources.getResource("tags/macrotag/import-property-global.jinja"), StandardCharsets.UTF_8 ) ); } catch (IOException e) { throw new RuntimeException(); } }
Example 4
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 6 votes |
@Test public void itDoesNotRenderTagsDependingOnDeferredGlobalImport() { try { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.getContext().put("primary_font_size_num", DeferredValue.instance()); String renderedImport = fixture("import-property"); assertThat(renderedImport) .isEqualTo( Resources.toString( Resources.getResource("tags/macrotag/import-property.jinja"), StandardCharsets.UTF_8 ) ); } catch (IOException e) { throw new RuntimeException(); } }
Example 5
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 6 votes |
@Test public void itAddsAllDeferredNodesOfImport() { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.getContext().put("primary_font_size_num", DeferredValue.instance()); fixture("import-property"); Set<String> deferredImages = interpreter .getContext() .getDeferredNodes() .stream() .map(Node::reconstructImage) .collect(Collectors.toSet()); assertThat( deferredImages .stream() .filter(image -> image.contains("{% set primary_line_height")) .collect(Collectors.toSet()) ) .isNotEmpty(); }
Example 6
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 6 votes |
@Test public void itAddsAllDeferredNodesOfGlobalImport() { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.getContext().put("primary_font_size_num", DeferredValue.instance()); fixture("import-property-global"); Set<String> deferredImages = interpreter .getContext() .getDeferredNodes() .stream() .map(Node::reconstructImage) .collect(Collectors.toSet()); assertThat( deferredImages .stream() .filter(image -> image.contains("{% set primary_line_height")) .collect(Collectors.toSet()) ) .isNotEmpty(); }
Example 7
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 5 votes |
@Test public void itDefersImportedVariableKey() { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.getContext().put("primary_font_size_num", DeferredValue.instance()); fixture("import-property"); assertThat(interpreter.getContext().get("pegasus")).isInstanceOf(DeferredValue.class); //If pegasus was deferred at the key.prop level instead of key this would resolve to a value assertThat(interpreter.getContext().get("expected_to_be_deferred")) .isInstanceOf(DeferredValue.class); DeferredValue deferredValue = (DeferredValue) interpreter.getContext().get("pegasus"); Map originalValue = (Map) deferredValue.getOriginalValue(); assertThat(originalValue.get("primary_line_height")).isNotNull(); }
Example 8
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 5 votes |
@Test public void itDefersGloballyImportedVariables() { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.getContext().put("primary_font_size_num", DeferredValue.instance()); fixture("import-property-global"); assertThat(interpreter.getContext().get("primary_line_height")) .isInstanceOf(DeferredValue.class); }
Example 9
Source File: ImportTagTest.java From jinjava with Apache License 2.0 | 5 votes |
@Test public void itReconstructsDeferredImportTag() { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.getContext().put("primary_font_size_num", DeferredValue.instance()); String renderedImport = fixture("import-property"); assertThat(renderedImport) .contains("{% import \"tags/settag/set-var-exp.jinja\" as pegasus %}"); }
Example 10
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); }