public class Pebble extends Object implements Jooby.Module
Pebble a lightweight but rock solid Java templating engine.
{
use(new Pebble());
get("/", req -> Results.html("index").put("model", new MyModel());
// or Pebble API
get("/pebble-api", req -> {
PebbleEngine pebble = req.require(PebbleEngine.class);
PebbleTemplate template = pebble.getTemplate("template");
template.evaluate(...);
});
}
Templates are loaded from root of classpath: / and must end with: .html
file extension.
Templates are loaded from the root of classpath and must end with .html. You can
change the default template location and extensions too:
{
use(new Pebble("templates", ".pebble"));
}
Cache is OFF when env=dev (useful for template reloading), otherwise is ON.
Cache is backed by Guava and the default cache will expire after 200 entries.
If 200 entries is not enough or you need a more advanced cache setting, just set the
pebble.cache option:
pebble.cache = "expireAfterWrite=1h;maximumSize=200"
See CacheBuilderSpec.
It works like template cache, except the cache is controlled by the property:
pebble.tagCache
Advanced configuration if provided by callback:
{
use(new Pebble().doWith(pebble -> {
pebble.extension(...);
pebble.loader(...);
}));
}
That's all folks! Enjoy it!!!
| Constructor and Description |
|---|
Pebble()
Creates a new
Pebble module. |
Pebble(String suffix)
Creates a new
Pebble module. |
Pebble(String prefix,
String suffix)
Creates a new
Pebble module. |
| Modifier and Type | Method and Description |
|---|---|
com.typesafe.config.Config |
config() |
void |
configure(Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder) |
Pebble |
doWith(BiConsumer<com.mitchellbosecke.pebble.PebbleEngine.Builder,com.typesafe.config.Config> callback)
Advanced configuration callback for
PebbleEngine.Builder. |
Pebble |
doWith(Consumer<com.mitchellbosecke.pebble.PebbleEngine.Builder> callback)
Advanced configuration callback for
PebbleEngine.Builder. |
public Pebble(String prefix, String suffix)
Pebble module. Add a ClasspathLoader and set prefix and suffix on
it.prefix - Template prefix location (might be null).suffix - Template extension.public Pebble(String suffix)
Pebble module. Add a ClasspathLoader that loads template from
root of classpath and ends with the given suffix.suffix - Template extension.public Pebble()
Pebble module. Add a ClasspathLoader that loads template from
root of classpath and ends with the given .html.public Pebble doWith(BiConsumer<com.mitchellbosecke.pebble.PebbleEngine.Builder,com.typesafe.config.Config> callback)
PebbleEngine.Builder.callback - A callback to finish setup.public Pebble doWith(Consumer<com.mitchellbosecke.pebble.PebbleEngine.Builder> callback)
PebbleEngine.Builder.callback - A callback to finish setup.public void configure(Env env, com.typesafe.config.Config conf, com.google.inject.Binder binder)
configure in interface Jooby.Modulepublic com.typesafe.config.Config config()
config in interface Jooby.ModuleCopyright © 2015. All rights reserved.