3131import static io .jooby .TemplateEngine .TEMPLATE_PATH ;
3232import static io .jooby .TemplateEngine .normalizePath ;
3333
34+ /**
35+ * Freemarker module: https://jooby.io/modules/freemarker.
36+ *
37+ * Usage:
38+ *
39+ * <pre>{@code
40+ * {
41+ *
42+ * install(new FreemarkerModule());
43+ *
44+ * get("/", ctx -> {
45+ * User user = ...;
46+ * return new ModelAndView("index.ftl")
47+ * .put("user", user);
48+ * });
49+ * }
50+ * }</pre>
51+ *
52+ * The template engine looks for a file-system directory: <code>views</code> in the current
53+ * user directory. If the directory doesn't exist, it looks for the same directory in the project
54+ * classpath.
55+ *
56+ * You can specify a different template location:
57+ *
58+ * <pre>{@code
59+ * {
60+ *
61+ * install(new FreemarkerModule("mypath"));
62+ *
63+ * }
64+ * }</pre>
65+ *
66+ * The <code>mypath</code> location works in the same way: file-system or fallback to classpath.
67+ *
68+ * Direct access to {@link Configuration} is available via require call:
69+ *
70+ * <pre>{@code
71+ * {
72+ *
73+ * Configuration configuration = require(Configuration.class);
74+ *
75+ * }
76+ * }</pre>
77+ *
78+ * Complete documentation is available at: https://jooby.io/modules/freemarker.
79+ *
80+ * @author edgar
81+ * @since 2.0.0
82+ */
3483public class FreemarkerModule implements Extension {
3584
85+ /**
86+ * Utility class for creating {@link Configuration} instances.
87+ */
3688 public static class Builder {
3789
3890 private TemplateLoader templateLoader ;
@@ -43,26 +95,57 @@ public static class Builder {
4395
4496 private String templatesPath = TemplateEngine .PATH ;
4597
98+ /**
99+ * Template loader to use.
100+ *
101+ * @param loader Template loader to use.
102+ * @return This builder.
103+ */
46104 public @ Nonnull Builder setTemplateLoader (@ Nonnull TemplateLoader loader ) {
47105 this .templateLoader = loader ;
48106 return this ;
49107 }
50108
109+ /**
110+ * Set a freemarker option/setting.
111+ *
112+ * @param name Option name.
113+ * @param value Optiona value.
114+ * @return This builder.
115+ */
51116 public @ Nonnull Builder setSetting (@ Nonnull String name , @ Nonnull String value ) {
52117 this .settings .put (name , value );
53118 return this ;
54119 }
55120
121+ /**
122+ * Set output format.
123+ *
124+ * @param outputFormat Output format.
125+ * @return This builder.
126+ */
56127 public @ Nonnull Builder setOutputFormat (@ Nonnull OutputFormat outputFormat ) {
57128 this .outputFormat = outputFormat ;
58129 return this ;
59130 }
60131
132+ /**
133+ * Template path.
134+ *
135+ * @param templatesPath Set template path.
136+ * @return This builder.
137+ */
61138 public @ Nonnull Builder setTemplatesPath (@ Nonnull String templatesPath ) {
62139 this .templatesPath = templatesPath ;
63140 return this ;
64141 }
65142
143+ /**
144+ * Build method for creating a freemarker instance.
145+ *
146+ * @param env Application environment.
147+ * @return A new freemarker instance.
148+ */
66149 public @ Nonnull Configuration build (@ Nonnull Environment env ) {
67150 try {
68151 Configuration freemarker = new Configuration (
@@ -124,14 +207,28 @@ private TemplateLoader defaultTemplateLoader(Environment env, String templatesPa
124207
125208 private String templatesPath ;
126209
210+ /**
211+ * Creates a new freemarker module using a the given freemarker instance.
212+ *
213+ * @param freemarker Freemarker to use.
214+ */
127215 public FreemarkerModule (@ Nonnull Configuration freemarker ) {
128216 this .freemarker = freemarker ;
129217 }
130218
219+ /**
220+ * Freemarker module which look at the given path. It first look at the file-system or fallback
221+ * to classpath.
222+ *
223+ * @param templatesPath Template path.
224+ */
131225 public FreemarkerModule (@ Nonnull String templatesPath ) {
132226 this .templatesPath = templatesPath ;
133227 }
134228
229+ /**
230+ * Creates a new freemarker module using the default template path: <code>views</code>.
231+ */
135232 public FreemarkerModule () {
136233 this (TemplateEngine .PATH );
137234 }
@@ -146,7 +243,12 @@ public FreemarkerModule() {
146243 services .put (Configuration .class , freemarker );
147244 }
148245
149- public static FreemarkerModule .Builder create () {
246+ /**
247+ * Creates a new freemarker builder.
248+ *
249+ * @return A builder.
250+ */
251+ public static @ Nonnull FreemarkerModule .Builder create () {
150252 return new FreemarkerModule .Builder ();
151253 }
152254}
0 commit comments