1. JStachio

JStachio A type-safe Java Mustache templating engine.

1.1. Usage

1) Add the dependency:

Maven
Gradle
<dependency>
  <groupId>io.jooby</groupId>
  <artifactId>jooby-jstachio</artifactId>
  <version>3.0.10</version>
</dependency>
Maven
Gradle
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <annotationProcessorPaths>
                    <path>
                        <groupId>io.jstach</groupId>
                        <artifactId>jstachio-apt</artifactId>
                        <version>1.3.5</version>
                    </path>
                    <!-- other annotation processors like jooby -->
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

3) Create your models and templates

Create a model and annotate with @JStache.

Java
Kotlin
@JStache(path="index.mustache")            (1)
public record IndexPage(String message){}
1 Path is a classpath resource usually in src/main/resources

Create a mustache template in src/main/resources

src/main/resources/index.mustache
<p>Hello {{message}}!</p>

4) Install and use JStachio

Java
Kotlin
import io.jooby.jstachio.JStachioModule;

{
  install(new JStachioModule());              (1)

  get("/", ctx -> {
    return new IndexPage("JStachio");         (2)
  });
}
1 Install JStachio
2 Returns an annotated model

1.2. Options

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

Java
Kotlin
import io.jooby.jstachio.JStachioModule;

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

JStachio has a hot reload mode that uses reflection via an extension. To add the extension the jar just needs to be in the classpath:

Maven
Gradle
<dependencies>
    <dependency>
        <groupId>io.jstach</groupId>
        <artifactId>jstachio-jmustache</artifactId>
        <version>1.3.5</version>
        <scope>runtime</scope>
    </dependency>
<dependencies>

To disable the extension for production either remove the dependency or set the property JSTACHIO_JMUSTACHE_DISABLE to true.