Package com.github.jknack.handlebars.js
Class HandlebarsJs
- java.lang.Object
-
- com.github.jknack.handlebars.js.HandlebarsJs
-
public abstract class HandlebarsJs extends Object
The main motivation ofHandlebarsJs
is the ability of reuse JavaScript helpers in the server and the client.- Since:
- 1.1.0
-
-
Constructor Summary
Constructors Constructor Description HandlebarsJs(HelperRegistry helperRegistry)
Creates a newHelperRegistry
object.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static HandlebarsJs
create(HelperRegistry helperRegistry)
Creates aHandlebarsJs
object.static HandlebarsJs
createRhino(HelperRegistry helperRegistry, int optimizationLevel)
Creates aHandlebarsJs
object.abstract void
registerHelpers(String filename, String source)
Register helpers from a JavaScript source.
-
-
-
Constructor Detail
-
HandlebarsJs
public HandlebarsJs(HelperRegistry helperRegistry)
Creates a newHelperRegistry
object.- Parameters:
helperRegistry
- TheHelperRegistry
instance. Required.
-
-
Method Detail
-
registerHelpers
public abstract void registerHelpers(String filename, String source) throws Exception
Register helpers from a JavaScript source.
A JavaScript source file looks like:
Handlebars.registerHelper('hey', function (context) { return 'Hi ' + context.name; }); ... Handlebars.registerHelper('hey', function (context, options) { return 'Hi ' + context.name + options.hash['x']; }); ... Handlebars.registerHelper('hey', function (context, p1, p2, options) { return 'Hi ' + context.name + p1 + p2 + options.hash['x']; }); ...
To keep your helpers reusable between server and client avoid DOM manipulation.- Parameters:
filename
- The file name (just for debugging purpose). Required.source
- The JavaScript source. Required.- Throws:
Exception
- If the JavaScript helpers can't be registered.
-
create
public static HandlebarsJs create(HelperRegistry helperRegistry)
Creates aHandlebarsJs
object.- Parameters:
helperRegistry
- The helperRegistry object. Required.- Returns:
- A new
HandlebarsJs
object.
-
createRhino
public static HandlebarsJs createRhino(HelperRegistry helperRegistry, int optimizationLevel)
Creates aHandlebarsJs
object.- Parameters:
helperRegistry
- The helperRegistry object. Required.optimizationLevel
- The optimization level of rhino.- Returns:
- A new
HandlebarsJs
object.
-
-