PebbleEngine pebble = this.pebble.build(); binder.bind(PebbleEngine.class).toInstance(pebble);
.loader(cpathloader) .templateCache(CacheBuilder.newBuilder().maximumSize(10).build()) .build();
public static PebbleEngine getNewEngine() { PebbleEngine engine; try { Loader<?> loader = new ClasspathLoader(); engine = new PebbleEngine.Builder().loader(loader).strictVariables(false).build(); } catch (PebbleException e) { e.printStackTrace(); throw new IllegalStateException(e); } return engine; }
PebbleEngine pebble = this.pebble.build(); binder.bind(PebbleEngine.class).toInstance(pebble);
@Bean public PebbleEngine pebbleEngine() { PebbleEngine.Builder builder = new PebbleEngine.Builder(); builder.loader(this.pebbleLoader); builder.extension(this.pebbleSpringExtension()); if (this.extensions != null && !this.extensions.isEmpty()) { builder.extension(this.extensions.toArray(new Extension[this.extensions.size()])); } if (!this.properties.isCache()) { builder.cacheActive(false); } if (this.properties.getDefaultLocale() != null) { builder.defaultLocale(this.properties.getDefaultLocale()); } builder.strictVariables(this.properties.isStrictVariables()); return builder.build(); } }
@Test public void testPebble() throws IOException, PebbleException, MessagingException { PebbleEngine engine = new PebbleEngine.Builder().build(); PebbleTemplate compiledTemplate = engine.getTemplate("register.html"); Map<String, Object> context = new HashMap<String, Object>(); context.put("username", "biezhi"); context.put("email", "admin@java-china.org"); Writer writer = new StringWriter(); compiledTemplate.evaluate(writer, context); String output = writer.toString(); System.out.println(output); OhMyEmail.subject("这是一封测试Pebble模板邮件") .from("王爵的QQ邮箱") .to("921293209@qq.com") .html(output); // .send(); }
@Test public void customBuilderShouldRender(TestContext should) { final Async test = should.async(); final TemplateEngine engine = PebbleTemplateEngine.create(new PebbleEngine.Builder().extension(new TestExtension()).loader(new PebbleVertxLoader(vertx)).build()); final JsonObject context = new JsonObject() .put("foo", "badger") .put("bar", "fox") .put("context", new JsonObject().put("path", "/test-pebble-template5.peb")); engine.render(context, "src/test/filesystemtemplates/test-pebble-template5.peb", render -> { should.assertTrue(render.succeeded()); should.assertEquals("Hello badger and foxString is TESTRequest path is /test-pebble-template5.peb", render.result().toString()); test.complete(); }); }
public PebbleTemplateEngineImpl(Vertx vertx) { this(new PebbleEngine.Builder().loader(new PebbleVertxLoader(vertx)).cacheActive(false).build()); }
/** * Construct a new template engine using pebble with a default engine. */ public PebbleTemplateEngine() { this.engine = new PebbleEngine.Builder().build(); }
public static PebbleEngine getNewEngine() { PebbleEngine engine; try { Loader<?> loader = new ClasspathLoader(); engine = new PebbleEngine.Builder().loader(loader).strictVariables(false).build(); } catch (PebbleException e) { e.printStackTrace(); throw new IllegalStateException(e); } return engine; }
/** * Construct a new template engine using pebble with an engine using a special loader. */ public PebbleTemplateEngine(Loader loader) { this.engine = new PebbleEngine.Builder().loader(loader).build(); }
@Setup public void setup() throws PebbleException { PebbleEngine engine = new PebbleEngine.Builder().autoEscaping(false).build(); template = engine.getTemplate("templates/stocks.pebble.html"); this.context = getContext(); }
engine = builder.build();
@Override public void renderString(String templateContent, Map<String, Object> model, Writer writer) { String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = getLanguageOrDefault(language); } Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = getLocaleOrDefault(language); } try { PebbleEngine stringEngine = new PebbleEngine.Builder() .loader(new StringLoader()) .strictVariables(engine.isStrictVariables()) .templateCache(null) .build(); PebbleTemplate template = stringEngine.getTemplate(templateContent); template.evaluate(writer, model, locale); writer.flush(); } catch (Exception e) { throw new PippoRuntimeException(e); } }
@Bean public PebbleEngine pebbleEngine() { PebbleEngine.Builder builder = new PebbleEngine.Builder(); builder.loader(this.pebbleLoader); builder.extension(this.pebbleSpringExtension()); if (this.extensions != null && !this.extensions.isEmpty()) { builder.extension(this.extensions.toArray(new Extension[this.extensions.size()])); } if (!this.properties.isCache()) { builder.cacheActive(false); } if (this.properties.getDefaultLocale() != null) { builder.defaultLocale(this.properties.getDefaultLocale()); } builder.strictVariables(this.properties.isStrictVariables()); builder.greedyMatchMethod(this.properties.isGreedyMatchMethod()); return builder.build(); } }
@Bean public PebbleEngine pebbleEngine() { PebbleEngine.Builder builder = new PebbleEngine.Builder(); builder.loader(this.pebbleLoader); builder.extension(this.pebbleSpringExtension()); if (this.extensions != null && !this.extensions.isEmpty()) { builder.extension(this.extensions.toArray(new Extension[this.extensions.size()])); } if (!this.properties.isCache()) { builder.cacheActive(false); } if (this.properties.getDefaultLocale() != null) { builder.defaultLocale(this.properties.getDefaultLocale()); } builder.strictVariables(this.properties.isStrictVariables()); builder.greedyMatchMethod(this.properties.isGreedyMatchMethod()); return builder.build(); } }