Skip to content

Commit 946f2af

Browse files
committed
Added support for Pebble template engine
1 parent f9ae4a4 commit 946f2af

File tree

10 files changed

+589
-0
lines changed

10 files changed

+589
-0
lines changed

docs/asciidoc/modules.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ Available modules are listed next.
2626
* link:modules/handlebars[Handlebars]: Handlebars templates for Jooby.
2727
* link:modules/freemarker[Freemarker]: Freemarker templates for Jooby.
2828
* link:modules/rocker[Rocker]: Rocker templates for Jooby.
29+
* link:modules/pebble[Pebble]: Pebble templates for Jooby.
2930

3031
.

docs/asciidoc/modules/pebble.adoc

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
== Pebble
2+
3+
https://pebbletemplates.io/[Pebble templates] for Jooby.
4+
5+
=== Usage
6+
7+
1) Add the dependency:
8+
9+
[dependency, artifactId="jooby-pebble"]
10+
.
11+
12+
2) Write your templates inside the `views` folder
13+
14+
.views/index.peb
15+
[source, html]
16+
----
17+
<p> Hello {{name}}! </p>
18+
----
19+
20+
3) Install and use pebble templates
21+
22+
.Java
23+
[source, java, role="primary"]
24+
----
25+
import io.jooby.pebble.PebbleModule;
26+
27+
{
28+
install(new PebbleModule());
29+
30+
get("/", ctx -> {
31+
return new ModelAndView("index.peb")
32+
.put("name", "Jooby");
33+
});
34+
}
35+
----
36+
37+
.Kotlin
38+
[source, kt, role="secondary"]
39+
----
40+
import io.jooby.pebble.PebbleModule
41+
42+
{
43+
install(PebbleModule())
44+
45+
get("/") {
46+
ModelAndView("index.peb")
47+
.put("name", "Jooby")
48+
}
49+
}
50+
----
51+
52+
Template engine supports the following file extensions: `.peb`, `.pebble` and `.html`.
53+
54+
=== Templates Location
55+
56+
Default template location is set to `views`. The `views` folder/location is expected to be at the current
57+
user directory or at root of classpath.
58+
59+
You can override the default location by setting the `templates.path` property in the application
60+
configuration file or programmatically at creation time.
61+
62+
=== Template Cache
63+
64+
The pebble module turn off cache while running in `dev` or `test` environment.
65+
66+
=== Custom configuration
67+
68+
Custom Pebble object can be provided it programmatically:
69+
70+
.Java
71+
[source, java, role="primary"]
72+
----
73+
import io.jooby.pebble.PebbleModule;
74+
75+
{
76+
// Apply custom configuration via builder
77+
78+
PebbleEngine.Builder builder = PebbleModule.create()
79+
.setTemplatesPath("template")
80+
.build(getEnvironment());
81+
82+
install(new PebbleModule(builder));
83+
}
84+
----
85+
86+
.Kotlin
87+
[source, kt, role="secondary"]
88+
----
89+
import io.jooby.pebble.PebbleModule
90+
91+
{
92+
val builder = PebbleModule.create()
93+
.setTemplatesPath("template")
94+
.build(getEnvironment())
95+
96+
install(PebbleModule(builder))
97+
}
98+
----

modules/jooby-bom/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<guice.version>4.2.2</guice.version>
4545
<h2.version>1.4.199</h2.version>
4646
<handlebars.version>4.1.2</handlebars.version>
47+
<pebble.version>3.0.10</pebble.version>
4748
<hibernate.version>5.4.3.Final</hibernate.version>
4849
<jackson-databind.version>2.9.9.2</jackson-databind.version>
4950
<jackson.version>2.9.9</jackson.version>
@@ -279,6 +280,11 @@
279280
<artifactId>handlebars</artifactId>
280281
<version>${handlebars.version}</version>
281282
</dependency>
283+
<dependency>
284+
<groupId>io.pebbletemplates</groupId>
285+
<artifactId>pebble</artifactId>
286+
<version>${pebble.version}</version>
287+
</dependency>
282288
<dependency>
283289
<groupId>com.googlecode.log4jdbc</groupId>
284290
<artifactId>log4jdbc</artifactId>

modules/jooby-pebble/pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
6+
<parent>
7+
<groupId>io.jooby</groupId>
8+
<artifactId>modules</artifactId>
9+
<version>2.0.6-SNAPSHOT</version>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
<artifactId>jooby-pebble</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.google.code.findbugs</groupId>
18+
<artifactId>jsr305</artifactId>
19+
<scope>provided</scope>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>io.jooby</groupId>
24+
<artifactId>jooby</artifactId>
25+
<version>${jooby.version}</version>
26+
</dependency>
27+
28+
<!-- pebble -->
29+
<dependency>
30+
<groupId>io.pebbletemplates</groupId>
31+
<artifactId>pebble</artifactId>
32+
</dependency>
33+
34+
<!-- Test dependencies -->
35+
<dependency>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter-engine</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.jacoco</groupId>
43+
<artifactId>org.jacoco.agent</artifactId>
44+
<classifier>runtime</classifier>
45+
<scope>test</scope>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>io.jooby</groupId>
50+
<artifactId>jooby-test</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
</dependencies>
54+
</project>

0 commit comments

Comments
 (0)