@Test public void test_render() throws Exception { String templateVariable = "Hello Pebble!"; Map<String, Object> model = new HashMap<>(); model.put("message", templateVariable); String expected = String.format("<h1>%s</h1>", templateVariable); String actual = new PebbleTemplateEngine().render(new ModelAndView(model, "templates/hello.pebble")); assertEquals(expected, actual); }
@Override @SuppressWarnings("unchecked") public String render(ModelAndView modelAndView) { Object model = modelAndView.getModel(); if (model == null || model instanceof Map) { try { StringWriter writer = new StringWriter(); PebbleTemplate template = engine.getTemplate(modelAndView.getViewName()); if (model == null) { template.evaluate(writer); } else { template.evaluate(writer, (Map<String, Object>) modelAndView.getModel()); } return writer.toString(); } catch (PebbleException | IOException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException("Invalid model, model must be instance of Map."); } }
PebbleTemplateEngine extends TemplateEngine { @Override @SuppressWarnings("unchecked") public String render(ModelAndView modelAndView) { Object model = modelAndView.getModel(); if (model == null || model instanceof Map) { try { StringWriter writer = new StringWriter(); PebbleTemplate template = engine.getTemplate(modelAndView.getViewName()); if (model == null) { template.evaluate(writer); } else { template.evaluate(writer, (Map<String, Object>) modelAndView.getModel()); } return writer.toString(); } catch (PebbleException | IOException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException("Invalid model, model must be instance of Map."); } } }
PebbleTemplateEngine extends TemplateEngine { @Override @SuppressWarnings("unchecked") public String render(ModelAndView modelAndView) { Object model = modelAndView.getModel(); if (model == null || model instanceof Map) { try { StringWriter writer = new StringWriter(); PebbleTemplate template = engine.getTemplate(modelAndView.getViewName()); if (model == null) { template.evaluate(writer); } else { template.evaluate(writer, (Map<String, Object>) modelAndView.getModel()); } return writer.toString(); } catch (PebbleException | IOException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException("Invalid model, model must be instance of Map."); } } PebbleTemplateEngine();  PebbleTemplateEngine(Loader loader);  PebbleTemplateEngine(PebbleEngine engine); }
PebbleTemplateEngine extends TemplateEngine { @Override @SuppressWarnings("unchecked") public String render(ModelAndView modelAndView) { Object model = modelAndView.getModel(); if (model == null || model instanceof Map) { try { StringWriter writer = new StringWriter(); PebbleTemplate template = engine.getTemplate(modelAndView.getViewName()); if (model == null) { template.evaluate(writer); } else { template.evaluate(writer, (Map<String, Object>) modelAndView.getModel()); } return writer.toString(); } catch (PebbleException | IOException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException("Invalid model, model must be instance of Map."); } } PebbleTemplateEngine();  PebbleTemplateEngine(Loader loader);  PebbleTemplateEngine(PebbleEngine engine); @Override @SuppressWarnings("unchecked") String render(ModelAndView modelAndView); }
PebbleTemplateEngine extends TemplateEngine { @Override @SuppressWarnings("unchecked") public String render(ModelAndView modelAndView) { Object model = modelAndView.getModel(); if (model == null || model instanceof Map) { try { StringWriter writer = new StringWriter(); PebbleTemplate template = engine.getTemplate(modelAndView.getViewName()); if (model == null) { template.evaluate(writer); } else { template.evaluate(writer, (Map<String, Object>) modelAndView.getModel()); } return writer.toString(); } catch (PebbleException | IOException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException("Invalid model, model must be instance of Map."); } } PebbleTemplateEngine();  PebbleTemplateEngine(Loader loader);  PebbleTemplateEngine(PebbleEngine engine); @Override @SuppressWarnings("unchecked") String render(ModelAndView modelAndView);  }