@@ -17,7 +17,7 @@ https://jte.gg[Jte] Secure and speedy templates for Java and Kotlin.
1717<plugin>
1818 <groupId>gg.jte</groupId>
1919 <artifactId>jte-maven-plugin</artifactId>
20- <version>${jte.version }</version>
20+ <version>{jte_version }</version>
2121 <configuration>
2222 <sourceDirectory>${basedir}/src/main/jte</sourceDirectory> <!-- This is the directory where your .jte files are located. -->
2323 <contentType>Html</contentType>
@@ -38,11 +38,11 @@ https://jte.gg[Jte] Secure and speedy templates for Java and Kotlin.
3838----
3939plugins {
4040 id 'java'
41- id 'gg.jte.gradle' version '${jte.version }'
41+ id 'gg.jte.gradle' version '{jte_version }'
4242}
4343
4444dependencies {
45- implementation('gg.jte:jte:${jte.version }')
45+ implementation('gg.jte:jte:{jte_version }')
4646}
4747
4848jte {
@@ -70,10 +70,10 @@ NOTE: Complete code generator options are https://github.com/casid/jte/blob/main
7070import io.jooby.jte.JteModule;
7171
7272{
73- install(new JteModule(Paths.of ("src", "main", "jte"))); <1>
73+ install(new JteModule(Paths.get ("src", "main", "jte"))); <1>
7474
7575 get("/", ctx -> {
76- return new ModelAndView ("hello.jte", Map.of("name", "Jte")); <2>
76+ return new MapModelAndView ("hello.jte", Map.of("name", "Jte")); <2>
7777 });
7878}
7979----
@@ -84,10 +84,10 @@ import io.jooby.jte.JteModule;
8484import io.jooby.jte.JteModule
8585
8686{
87- install(JteModule(Paths.of ("src", "main", "jte"))) <1>
87+ install(JteModule(Paths.get ("src", "main", "jte"))) <1>
8888
8989 get("/") {
90- ModelAndView ("hello.jte", Map.of("name", "Jte")) <2>
90+ MapModelAndView ("hello.jte", Map.of("name", "Jte")) <2>
9191 }
9292}
9393----
@@ -100,13 +100,121 @@ will put all the generated classes in `src/main/jte/jte-classes`.
100100
101101In production will read the classes from classpath.
102102
103+ === Models
104+
105+ jte-models is a generator extension for jte that creates a typesafe facade for rendering templates.
106+
107+ 1) Add the dependency:
108+
109+ [dependency, groupId="gg.jte", artifactId="jte-models", version="jte.version"]
110+ .
111+
112+ 2) Configure code generator
113+
114+ .Maven
115+ [source,xml,role="primary",subs="verbatim,attributes"]
116+ ----
117+ <plugin>
118+ <groupId>gg.jte</groupId>
119+ <artifactId>jte-maven-plugin</artifactId>
120+ <version>{jte_version}</version>
121+ <configuration>
122+ <sourceDirectory>${project.basedir}/src/main/jte</sourceDirectory>
123+ <contentType>Html</contentType>
124+ <extensions>
125+ <extension>
126+ <className>gg.jte.models.generator.ModelExtension</className>
127+ </extension>
128+ </extensions>
129+ </configuration>
130+ <executions>
131+ <execution>
132+ <phase>generate-sources</phase>
133+ <goals>
134+ <goal>generate</goal>
135+ </goals>
136+ </execution>
137+ </executions>
138+ <dependencies>
139+ <dependency>
140+ <groupId>gg.jte</groupId>
141+ <artifactId>jte-models</artifactId>
142+ <version>{jte_version}</version>
143+ </dependency>
144+ </dependencies>
145+ </plugin>
146+ ----
147+
148+ .Gradle
149+ [source,groovy,role="secondary",subs="verbatim,attributes"]
150+ ----
151+ plugins {
152+ id 'gg.jte.gradle' version '{jte_version}'
153+ }
154+
155+ dependencies {
156+ implementation 'gg.jte:jte-runtime:{jte_version}'
157+ jteGenerate 'gg.jte:jte-models:{jte_version}'
158+ }
159+
160+ jte {
161+ generate()
162+ binaryStaticContent = true
163+ jteExtension 'gg.jte.models.generator.ModelExtension'
164+ }
165+ ----
166+
167+ ==== Usage
168+
169+ .Java
170+ [source,java,role="primary"]
171+ ----
172+ import io.jooby.jte.JteModule;
173+
174+ {
175+ install(new JteModule(Paths.get("src", "main", "jte")));
176+
177+ get("/static", ctx -> {
178+ var templates = new StaticTemplates();
179+ return templates.helloWorld("Hi!");
180+ });
181+
182+ get("/dynamic", ctx -> {
183+ var templates = new DynamicTemplates(require(TemplateEngine.class));
184+ return templates.helloWorld("Hi!");
185+ });
186+ }
187+ ----
188+
189+ .Kotlin
190+ [source, kt, role="secondary"]
191+ ----
192+ import io.jooby.jte.JteModule
193+
194+ {
195+ install(JteModule(Paths.get("src", "main", "jte")))
196+
197+ get("/static") {
198+ val templates = StaticTemplates()
199+ templates.helloWorld("Hi!")
200+ }
201+
202+ get("/dynamic") {
203+ val templates = DynamicTemplates(require(TemplateEngine::class))
204+ templates.helloWorld("Hi!")
205+ }
206+ }
207+ ----
208+
209+ More at https://jte.gg/jte-models/[jte-models].
210+
103211=== Options
104212
105213==== Custom class directory
106214
107215If you prefer a custom directory for compiled templates you need to do use:
108216
109- install(new JteModule(Paths.of ("src", "main", "jte"), Paths.of ("compiled-templates")));
217+ install(new JteModule(Paths.get ("src", "main", "jte"), Paths.get ("compiled-templates")));
110218
111219Also, you need to configure Maven or Gradle to generate templates classes:
112220
@@ -156,5 +264,8 @@ You need to make sure to copy the `compiled-templates` folder as part of your de
156264
157265It is possible to provide your own/custom template engine:
158266
267+ [source,java]
268+ ----
159269 var templateEngine = TemplateEngine.create(...) or TemplateEngine.createPrecompiled(..)
160270 install(new JteModule(templateEngine));
271+ ----
0 commit comments