Java Code Examples for com.hubspot.jinjava.Jinjava#newInterpreter()

The following examples show how to use com.hubspot.jinjava.Jinjava#newInterpreter() . 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: ValidationModeTest.java    From jinjava with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  validationFilter = new ValidationFilter();

  ELFunctionDefinition validationFunction = new ELFunctionDefinition(
    "",
    "validation_test",
    ValidationModeTest.class,
    "validationTestFunction"
  );

  jinjava = new Jinjava();
  jinjava.getGlobalContext().registerFilter(validationFilter);
  jinjava.getGlobalContext().registerFunction(validationFunction);
  interpreter = jinjava.newInterpreter();
  context = interpreter.getContext();

  validatingInterpreter =
    new JinjavaInterpreter(
      jinjava,
      context,
      JinjavaConfig.newBuilder().withValidationMode(true).build()
    );

  JinjavaInterpreter.pushCurrent(interpreter);
}
 
Example 2
Source File: IfTagTest.java    From jinjava with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  jinjava = new Jinjava();
  interpreter = jinjava.newInterpreter();
  context = interpreter.getContext();
  JinjavaInterpreter.pushCurrent(interpreter);
}
 
Example 3
Source File: FromTagTest.java    From jinjava with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  Jinjava jinjava = new Jinjava();
  jinjava.setResourceLocator(
    new ResourceLocator() {
      private RelativePathResolver relativePathResolver = new RelativePathResolver();

      @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
        );
      }

      @Override
      public Optional<LocationResolver> getLocationResolver() {
        return Optional.of(relativePathResolver);
      }
    }
  );

  interpreter = jinjava.newInterpreter();
  JinjavaInterpreter.pushCurrent(interpreter);

  context = interpreter.getContext();
  context.put("padding", 42);
}
 
Example 4
Source File: ForTagTest.java    From jinjava with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  jinjava = new Jinjava();
  interpreter = jinjava.newInterpreter();
  context = interpreter.getContext();

  tag = new ForTag();
}
 
Example 5
Source File: FreeipaJinjaTester.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void verifySingleSaltFile(Path path) throws IOException {
    String file = FileReaderUtils.readFileFromPath(path);
    Jinjava jinjava = new Jinjava();
    JinjavaInterpreter interpreter = jinjava.newInterpreter();
    interpreter.parse(file);
    List<TemplateError> errors = interpreter.getErrors();
    if (!errors.isEmpty()) {
        StringBuilder errorMsg = new StringBuilder();
        errorMsg.append("Jinja validation failed for sls file: " + path);
        errorMsg.append("\n");
        errors.forEach(error -> errorMsg.append(error));
        fail(errorMsg.toString());
    }
}
 
Example 6
Source File: CbJinjaTester.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void verifySingleSaltFile(Path path) throws IOException {
    String file = FileReaderUtils.readFileFromPath(path);
    Jinjava jinjava = new Jinjava();
    JinjavaInterpreter interpreter = jinjava.newInterpreter();
    interpreter.parse(file);
    List<TemplateError> errors = interpreter.getErrors();
    if (!errors.isEmpty()) {
        StringBuilder errorMsg = new StringBuilder();
        errorMsg.append("Jinja validation failed for sls file: " + path);
        errorMsg.append("\n");
        errors.forEach(error -> errorMsg.append(error));
        fail(errorMsg.toString());
    }
}
 
Example 7
Source File: JinjavaInterpreterTest.java    From jinjava with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  jinjava = new Jinjava();
  interpreter = jinjava.newInterpreter();
  symbols = interpreter.getConfig().getTokenScannerSymbols();
}
 
Example 8
Source File: DoTagTest.java    From jinjava with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  jinjava = new Jinjava();
  interpreter = jinjava.newInterpreter();
  context = interpreter.getContext();
}
 
Example 9
Source File: FromJsonFilterTest.java    From jinjava with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  jinjava = new Jinjava();
  interpreter = jinjava.newInterpreter();
  filter = new FromJsonFilter();
}
 
Example 10
Source File: ExpressionResolverTest.java    From jinjava with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  jinjava = new Jinjava();
  interpreter = jinjava.newInterpreter();
  context = interpreter.getContext();
}