public InterpreterScopeClosable enterScope(Map<Context.Library, Set<String>> disabled) { context = new Context(context, null, disabled); scopeDepth++; return new InterpreterScopeClosable(); }
public JinjavaInterpreter(JinjavaInterpreter orig) { this(orig.application, new Context(orig.context), orig.config); scopeDepth = orig.getScopeDepth() + 1; }
/** * Create a new jinjava processor instance with the specified global config * * @param globalConfig * used for all render operations performed by this processor instance */ public Jinjava(JinjavaConfig globalConfig) { this.globalConfig = globalConfig; this.globalContext = new Context(); Properties expConfig = new Properties(); expConfig.setProperty(TreeBuilder.class.getName(), ExtendedSyntaxBuilder.class.getName()); TypeConverter converter = new TruthyTypeConverter(); this.expressionFactory = new ExpressionFactoryImpl(expConfig, converter); this.resourceLocator = new ClasspathResourceLocator(); }
@Before public void setUp() { context = new Context(); }
@Before public void setUp() { context = new Context(); }
@Test public void itRecursivelyAddsValuesUpTheContextChain() { Context child = new Context(context); child.addResolvedValue(RESOLVED_VALUE); child.addResolvedFunction(RESOLVED_FUNCTION); child.addResolvedExpression(RESOLVED_EXPRESSION); assertThat(context.getResolvedValues()).contains(RESOLVED_VALUE); assertThat(context.getResolvedFunctions()).contains(RESOLVED_FUNCTION); assertThat(context.getResolvedExpressions()).contains(RESOLVED_EXPRESSION); }
@Test public void itRecursivelyAddsValuesUpTheContextChain() { Context child = new Context(context); child.addResolvedValue(RESOLVED_VALUE); child.addResolvedFunction(RESOLVED_FUNCTION); child.addResolvedExpression(RESOLVED_EXPRESSION); assertThat(context.getResolvedValues()).contains(RESOLVED_VALUE); assertThat(context.getResolvedFunctions()).contains(RESOLVED_FUNCTION); assertThat(context.getResolvedExpressions()).contains(RESOLVED_EXPRESSION); }
@Test public void itAddsResolvedValuesFromAnotherContextObject() { Context donor = new Context(); donor.addResolvedValue(RESOLVED_VALUE); donor.addResolvedFunction(RESOLVED_FUNCTION); donor.addResolvedExpression(RESOLVED_EXPRESSION); assertThat(context.getResolvedValues()).doesNotContain(RESOLVED_VALUE); assertThat(context.getResolvedFunctions()).doesNotContain(RESOLVED_FUNCTION); assertThat(context.getResolvedExpressions()).doesNotContain(RESOLVED_EXPRESSION); context.addResolvedFrom(donor); assertThat(context.getResolvedValues()).contains(RESOLVED_VALUE); assertThat(context.getResolvedFunctions()).contains(RESOLVED_FUNCTION); assertThat(context.getResolvedExpressions()).contains(RESOLVED_EXPRESSION); }
@Test public void itAddsResolvedValuesFromAnotherContextObject() { Context donor = new Context(); donor.addResolvedValue(RESOLVED_VALUE); donor.addResolvedFunction(RESOLVED_FUNCTION); donor.addResolvedExpression(RESOLVED_EXPRESSION); assertThat(context.getResolvedValues()).doesNotContain(RESOLVED_VALUE); assertThat(context.getResolvedFunctions()).doesNotContain(RESOLVED_FUNCTION); assertThat(context.getResolvedExpressions()).doesNotContain(RESOLVED_EXPRESSION); context.addResolvedFrom(donor); assertThat(context.getResolvedValues()).contains(RESOLVED_VALUE); assertThat(context.getResolvedFunctions()).contains(RESOLVED_FUNCTION); assertThat(context.getResolvedExpressions()).contains(RESOLVED_EXPRESSION); }
@Before public void setup() { Jinjava jinjava = new Jinjava(); jinjava.setResourceLocator(new ResourceLocator() { @Override public String getString(String fullName, Charset encoding, JinjavaInterpreter interpreter) throws IOException { return Resources.toString( Resources.getResource(String.format("tags/macrotag/%s", fullName)), StandardCharsets.UTF_8); } }); context = new Context(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); JinjavaInterpreter.pushCurrent(interpreter); context.put("padding", 42); }
@Before public void setup() { Jinjava jinjava = new Jinjava(); jinjava.setResourceLocator(new ResourceLocator() { @Override public String getString(String fullName, Charset encoding, JinjavaInterpreter interpreter) throws IOException { return Resources.toString( Resources.getResource(String.format("tags/macrotag/%s", fullName)), StandardCharsets.UTF_8); } }); context = new Context(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); JinjavaInterpreter.pushCurrent(interpreter); context.put("padding", 42); }
Context context = new Context(globalContext, bindings, renderConfig.getDisabled());