1. Rocker

Rocker is a Java 8 optimized, memory efficient, speedy template engine producing statically typed, plain java objects.

1.1. Usage

1) Add the dependency:

Maven
Gradle
<dependency>
  <groupId>io.jooby</groupId>
  <artifactId>jooby-rocker</artifactId>
  <version>3.5.3</version>
</dependency>

2) Configure code generator

Maven
Gradle
<plugin>
    <groupId>com.fizzed</groupId>
    <artifactId>rocker-maven-plugin</artifactId>
    <version>2.1.0</version>
    <configuration>
        <templateDirectory>src/rocker</templateDirectory>
    </configuration>
    <executions>
        <execution>
            <id>generate-rocker-templates</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Complete code generator options are available here

3) Write your templates inside the src/rocker/views folder

src/rocker/views/index.rocker.html
@args (String message)

<p>Hello @message!</p>

4) Install and use rocker templates

Java
Kotlin
import io.jooby.rocker.RockerModule;

{
  install(new RockerModule());              (1)

  get("/", ctx -> {
    return views.index.template("Rocker");  (2)
  });
}
1 Install Rocker
2 Returns a rocker view

1.2. Options

Rocker uses a byte buffer to render a view. Default byte buffer size is 4k. To change the buffer size:

Java
Kotlin
import io.jooby.rocker.RockerModule;

{
  install(new RockerModule().bufferSize(1024));
}

You can reuse/recycle the buffer using a thread-local approach by setting reuseBuffer(true):

Java
Kotlin
import io.jooby.rocker.RockerModule;

{
  install(new RockerModule().reuseBuffer(true));
}
Use with caution due it creates a buffer per thread memory consumption might be high. This technique works when the number of available threads is low enough (like the number of available processors).