public class Jade extends Object implements Jooby.Module
jade4j's intention is to be able to process jade templates in Java without the need of a JavaScript environment, while being fully compatible with the original jade syntax.
{
use(new Jade());
get("/", req -> Results.html("index").put("model", new MyModel());
// or via API
get("/jade-api", req -> {
JadeConfiguration jade = req.require(JadeConfiguration.class);
JadeTemplate template = jade.getTemplate("index");
template.renderTemplate(...);
});
}
Templates are loaded from root of classpath: / and must ends with:
.jade
file extension.
A template engine has access to ```request locals``` (a.k.a attributes). Here is an example:
{
use(new Jade());
get("*", req -> {
req.set("req", req);
req.set("session", req.session());
});
}
By default, there is no access to ```req``` or ```session``` from your template. This example shows how to do it.
Templates are loaded from the root of classpath and must ends with .jade. You can
change the extensions too:
{
use(new Jade(".html"));
}
Keep in mind if you change it file name must ends with: .html.jade.
Cache is OFF when application.env = dev (useful for template reloading), otherwise
is ON and does not expire, unless you explicitly set jade.caching.
Pretty print is on when application.env = dev , otherwise is off, unless unless you
explicitly set jade.prettyprint.
That's all folks! Enjoy it!!!
| Constructor and Description |
|---|
Jade()
Creates a
Jade instance with default suffix .jade. |
Jade(String suffix)
Creates a
Jade instance with a custom suffix. |
| Modifier and Type | Method and Description |
|---|---|
void |
configure(Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder) |
Jade |
doWith(BiConsumer<de.neuland.jade4j.JadeConfiguration,com.typesafe.config.Config> callback)
Configure callback that let you tweak or modified a
JadeConfiguration. |
Jade |
doWith(Consumer<de.neuland.jade4j.JadeConfiguration> callback)
Configure callback that let you tweak or modified a
JadeConfiguration. |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigpublic Jade(String suffix)
Jade instance with a custom suffix.suffix - A suffix like .html. But keep in mind the final extension will be
.html.jadepublic Jade()
Jade instance with default suffix .jade.public Jade doWith(Consumer<de.neuland.jade4j.JadeConfiguration> callback)
JadeConfiguration.callback - A callback.public Jade doWith(BiConsumer<de.neuland.jade4j.JadeConfiguration,com.typesafe.config.Config> callback)
JadeConfiguration.callback - A callback.public void configure(Env env, com.typesafe.config.Config conf, com.google.inject.Binder binder)
configure in interface Jooby.ModuleCopyright © 2017. All rights reserved.