Skip to content

Commit 9ca3f73

Browse files
committed
rocker doc
1 parent 1d5f57c commit 9ca3f73

File tree

5 files changed

+127
-3
lines changed

5 files changed

+127
-3
lines changed

docs/asciidoc/modules.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ Available modules are listed next.
2828
=== Template Engine
2929
* link:modules/handlebars[Handlebars]: Handlebars templates for Jooby.
3030
* link:modules/freemarker[Freemarker]: Freemarker templates for Jooby.
31+
* link:modules/rocker[Rocker]: Rocker templates for Jooby.
3132

3233
.

docs/asciidoc/modules/freemarker.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ http://freemarker.org[Freemarker templates] for Jooby.
1717
<p> Hello ${name}! </p>
1818
----
1919

20-
2) Install and use freemarker templates
20+
3) Install and use freemarker templates
2121

2222
.Java
2323
[source, java, role="primary"]

docs/asciidoc/modules/handlebars.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ https://github.com/jknack/handlebars.java[Handlebars templates] for Jooby.
1717
<p> Hello {{name}}! </p>
1818
----
1919

20-
2) Install and use freemarker templates
20+
3) Install and use freemarker templates
2121

2222
.Java
2323
[source, java, role="primary"]

docs/asciidoc/modules/rocker.adoc

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
== Rocker
2+
3+
https://github.com/fizzed/rocker[Rocker] is a Java 8 optimized, memory efficient, speedy template
4+
engine producing statically typed, plain java objects.
5+
6+
=== Usage
7+
8+
1) Add the dependency:
9+
10+
[dependency, artifactId="jooby-rocker"]
11+
.
12+
13+
2) Configure code generator
14+
15+
.Maven
16+
[source,xml,role="primary",subs="verbatim,attributes"]
17+
----
18+
<plugin>
19+
<groupId>com.fizzed</groupId>
20+
<artifactId>rocker-maven-plugin</artifactId>
21+
<version>{rockerVersion}</version>
22+
<configuration>
23+
<templateDirectory>src/rocker</templateDirectory>
24+
</configuration>
25+
<executions>
26+
<execution>
27+
<id>generate-rocker-templates</id>
28+
<phase>generate-sources</phase>
29+
<goals>
30+
<goal>generate</goal>
31+
</goals>
32+
</execution>
33+
</executions>
34+
</plugin>
35+
----
36+
37+
.Gradle
38+
[source,groovy,role="secondary",subs="verbatim,attributes"]
39+
----
40+
plugins {
41+
id "com.fizzed.rocker" version "{rockerVersion}"
42+
}
43+
44+
sourceSets {
45+
main {
46+
rocker {
47+
srcDir('src/rocker')
48+
}
49+
}
50+
}
51+
----
52+
53+
NOTE: Complete code generator options are https://github.com/fizzed/rocker#integrate-parsergenerator-in-build-tool[available here]
54+
55+
3) Write your templates inside the `src/rocker/views` folder
56+
57+
.src/rocker/views/index.rocker.html
58+
[source, html]
59+
----
60+
@args (String message)
61+
62+
<p>Hello @message!</p>
63+
----
64+
65+
4) Install and use rocker templates
66+
67+
.Java
68+
[source, java, role="primary"]
69+
----
70+
import io.jooby.rocker.Rockerby;
71+
72+
{
73+
install(new Rockerby()); <1>
74+
75+
get("/", ctx -> {
76+
return views.index.template("Rocker"); <2>
77+
});
78+
}
79+
----
80+
81+
.Kotlin
82+
[source, kt, role="secondary"]
83+
----
84+
import io.jooby.rocker.Rockerby
85+
86+
{
87+
install(Rockerby()) <1>
88+
89+
get("/") { ctx ->
90+
views.index.template("Rocker") <2>
91+
}
92+
}
93+
----
94+
95+
<1> Install Rocker
96+
<2> Returns a rocker view

docs/src/main/java/io/jooby/adoc/DocGenerator.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ private static void processModule(Asciidoctor asciidoctor, Path basedir, Path mo
124124
}
125125
}
126126

127-
private static Options createOptions(Path basedir, Path outdir, String version, String title) {
127+
private static Options createOptions(Path basedir, Path outdir, String version, String title)
128+
throws IOException {
128129
Attributes attributes = new Attributes();
129130
attributes.setAttribute("joobyVersion", version);
130131
attributes.setAttribute("love", "&#9825;");
@@ -151,6 +152,12 @@ private static Options createOptions(Path basedir, Path outdir, String version,
151152
attributes.setAttribute("highlightjs-theme", "agate");
152153
attributes.setAttribute("favicon", "images/favicon96.png");
153154

155+
// versions:
156+
Document pom = Jsoup
157+
.parse(DocGenerator.basedir().getParent().resolve("pom.xml").toFile(), "UTF-8");
158+
pom.select("properties > *").stream()
159+
.forEach(tag -> attributes.setAttribute(toJavaName(tag.tagName()), tag.text().trim()));
160+
154161
Options options = new Options();
155162
options.setBackend("html");
156163

@@ -164,6 +171,26 @@ private static Options createOptions(Path basedir, Path outdir, String version,
164171
return options;
165172
}
166173

174+
private static String toJavaName(String tagName) {
175+
StringBuilder name = new StringBuilder();
176+
name.append(tagName.charAt(0));
177+
boolean up = false;
178+
for (int i = 1; i < tagName.length(); i++) {
179+
char ch = tagName.charAt(i);
180+
if (Character.isJavaIdentifierPart(ch)) {
181+
if (up) {
182+
name.append(Character.toUpperCase(ch));
183+
up = false;
184+
} else {
185+
name.append(ch);
186+
}
187+
} else {
188+
up = true;
189+
}
190+
}
191+
return name.toString();
192+
}
193+
167194
private static String document(Path index) {
168195
try {
169196
Document doc = Jsoup.parse(index.toFile(), "UTF-8");

0 commit comments

Comments
 (0)