2525import java .util .LinkedList ;
2626import java .util .Set ;
2727import java .util .function .BiConsumer ;
28+ import java .util .function .Consumer ;
2829
2930import org .jooby .Env ;
3031import org .jooby .Jooby ;
5455import com .typesafe .config .ConfigValueFactory ;
5556
5657/**
57- * Exposes a {@link Handlebars} and a {@link Renderer}.
58+ * <h1>handlebars</h1>
59+ * <p>
60+ * Logic-less and semantic Mustache templates via
61+ * <a href="https://github.com/jknack/handlebars.java">handlebars.java</a>.
62+ * </p>
63+ *
64+ * <h2>exports</h2>
65+ * <ul>
66+ * <li>{@link Handlebars} object.</li>
67+ * <li>{@link Renderer} object.</li>
68+ * </ul>
5869 *
59- * <h1 >usage</h1 >
70+ * <h2 >usage</h2 >
6071 * <p>
6172 * It is pretty straightforward:
6273 * </p>
8192 * file extension.
8293 * </p>
8394 *
84- * <h1>helpers</h1>
95+ * <h2>options</h2>
96+ * <h13helpers</h3>
8597 * <p>
8698 * Simple/basic helpers are add it at startup time:
8799 * </p>
111123 * helper method.
112124 * </p>
113125 *
114- * <h1 >template loader</h1 >
126+ * <h3 >template loader</h3 >
115127 * <p>
116128 * Templates are loaded from the root of classpath and must end with <code>.html</code>. You can
117129 * change the default template location and extensions too:
123135 * }
124136 * </pre>
125137 *
126- * <h1 >cache</h1 >
138+ * <h3 >cache</h3 >
127139 * <p>
128140 * Cache is OFF when <code>env=dev</code> (useful for template reloading), otherwise is ON.
129141 * </p>
@@ -154,12 +166,19 @@ public class Hbs implements Jooby.Module {
154166
155167 private final Handlebars hbs ;
156168
157- private BiConsumer <Handlebars , Config > configurer ;
169+ private BiConsumer <Handlebars , Config > callback ;
158170
159171 private Set <Class <?>> helpers = new HashSet <>();
160172
161173 private Deque <ValueResolver > resolvers = new LinkedList <>();
162174
175+ /**
176+ * Creates a new {@link Hbs} module.
177+ *
178+ * @param prefix Template prefix.
179+ * @param suffix Template suffix.
180+ * @param helpers Optional list of helpers.
181+ */
163182 public Hbs (final String prefix , final String suffix , final Class <?>... helpers ) {
164183 this .hbs = new Handlebars (new ClassPathTemplateLoader (prefix , suffix ));
165184 with (helpers );
@@ -173,26 +192,81 @@ public Hbs(final String prefix, final String suffix, final Class<?>... helpers)
173192 this .resolvers .add (FieldValueResolver .INSTANCE );
174193 }
175194
195+ /**
196+ * Creates a new {@link Hbs} module.
197+ *
198+ * @param prefix Template prefix.
199+ * @param helpers Optional list of helpers.
200+ */
176201 public Hbs (final String prefix , final Class <?>... helpers ) {
177202 this (prefix , ".html" , helpers );
178203 }
179204
205+ /**
206+ * Creates a new {@link Hbs} module.
207+ *
208+ * @param helpers Optional list of helpers.
209+ */
180210 public Hbs (final Class <?>... helpers ) {
181211 this ("/" , helpers );
182212 }
183213
184- public Hbs doWith (final BiConsumer <Handlebars , Config > configurer ) {
185- this .configurer = requireNonNull (configurer , "Configurer is required." );
214+ /**
215+ * Set a handlebars callback. Usage:
216+ *
217+ * <pre>{@code
218+ * {
219+ * use(new Hbs().doWith((hbs, conf) -> {
220+ * ...
221+ * });
222+ * }
223+ * }</pre>
224+ *
225+ * @param callback Configurer callback.
226+ * @return This module.
227+ */
228+ public Hbs doWith (final BiConsumer <Handlebars , Config > callback ) {
229+ this .callback = requireNonNull (callback , "Configurer is required." );
186230 return this ;
187231 }
188232
233+ /**
234+ * Set a handlebars callback.
235+ *
236+ * <pre>{@code
237+ * {
238+ * use(new Hbs().doWith((hbs, conf) -> {
239+ * ...
240+ * });
241+ * }
242+ * }</pre>
243+ * @param callback Configurer callback.
244+ * @return This module.
245+ */
246+ public Hbs doWith (final Consumer <Handlebars > callback ) {
247+ requireNonNull (callback , "Configurer is required." );
248+ return doWith ((hbs , conf ) -> callback .accept (hbs ));
249+ }
250+
251+ /**
252+ * Append one or more helper classes.
253+ *
254+ * @param helper Helper class.
255+ * @return This module.
256+ */
189257 public Hbs with (final Class <?>... helper ) {
190258 for (Class <?> h : helper ) {
191259 helpers .add (h );
192260 }
193261 return this ;
194262 }
195263
264+ /**
265+ * Append a {@link ValueResolver}.
266+ *
267+ * @param resolver Resolver.
268+ * @return This module.
269+ */
196270 public Hbs with (final ValueResolver resolver ) {
197271 requireNonNull (resolver , "Value resolver is required." );
198272 this .resolvers .addFirst (resolver );
@@ -213,8 +287,8 @@ public void configure(final Env env, final Config config, final Binder binder) {
213287 .build ()));
214288 }
215289
216- if (configurer != null ) {
217- configurer .accept (hbs , config );
290+ if (callback != null ) {
291+ callback .accept (hbs , config );
218292 }
219293
220294 /** XSS */
0 commit comments