Class HandlebarsJs


  • public abstract class HandlebarsJs
    extends java.lang.Object
    The main motivation of HandlebarsJs is the ability of reuse JavaScript helpers in the server and the client.
    Since:
    1.1.0
    • Method Detail

      • registerHelpers

        public abstract void registerHelpers​(java.lang.String filename,
                                             java.lang.String source)
                                      throws java.lang.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:
        java.lang.Exception - If the JavaScript helpers can't be registered.
      • createRhino

        public static HandlebarsJs createRhino​(HelperRegistry helperRegistry,
                                               int optimizationLevel)
        Creates a HandlebarsJs object.
        Parameters:
        helperRegistry - The helperRegistry object. Required.
        optimizationLevel - The optimization level of rhino.
        Returns:
        A new HandlebarsJs object.