Interface HelperRegistry

    • Method Detail

      • helper

        <C> Helper<C> helper​(String name)
        Find a helper by name.
        Type Parameters:
        C - The helper runtime type.
        Parameters:
        name - The helper's name. Required.
        Returns:
        A helper or null if it's not found.
      • helpers

        Set<Map.Entry<String,​Helper<?>>> helpers()
        List all the helpers from registry.
        Returns:
        Available helpers in the registry.
      • registerHelper

        <H> HelperRegistry registerHelper​(String name,
                                          Helper<H> helper)
        Register a helper in the helper registry.
        Type Parameters:
        H - The helper runtime type.
        Parameters:
        name - The helper's name. Required.
        helper - The helper object. Required.
        Returns:
        This handlebars.
      • registerHelperMissing

        <H> HelperRegistry registerHelperMissing​(Helper<H> helper)
        Register the special helper missing in the registry.
        Type Parameters:
        H - The helper runtime type.
        Parameters:
        helper - The helper object. Required.
        Returns:
        This handlebars.
      • registerHelpers

        HelperRegistry registerHelpers​(Object helperSource)

        Register all the helper methods for the given helper source.

        A helper method looks like:

         public static? CharSequence methodName(context?, parameter*, options?) {
         }
         
        Where:
        • A method can/can't be static
        • The method's name became the helper's name
        • Context, parameters and options are all optional
        • If context and options are present they must be the first and last method arguments.
        Instance and static methods will be registered as helpers.
        Parameters:
        helperSource - The helper source. Required.
        Returns:
        This handlebars object.
      • registerHelpers

        HelperRegistry registerHelpers​(Class<?> helperSource)

        Register all the helper methods for the given helper source.

        A helper method looks like:

         public static? CharSequence methodName(context?, parameter*, options?) {
         }
         
        Where:
        • A method can/can't be static
        • The method's name became the helper's name
        • Context, parameters and options are all optional
        • If context and options are present they must be the first and last method arguments.
        Only static methods will be registered as helpers.

        Enums are supported too

        Parameters:
        helperSource - The helper source. Enums are supported. Required.
        Returns:
        This handlebars object.
      • registerHelpers

        HelperRegistry registerHelpers​(URI location)
                                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:
        location - A classpath location. Required.
        Returns:
        This handlebars object.
        Throws:
        Exception - If the JavaScript helpers can't be registered.
      • registerHelpers

        HelperRegistry registerHelpers​(File input)
                                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:
        input - A JavaScript file name. Required.
        Returns:
        This handlebars object.
        Throws:
        Exception - If the JavaScript helpers can't be registered.
      • registerHelpers

        HelperRegistry registerHelpers​(String filename,
                                       Reader 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.
        Returns:
        This handlebars object.
        Throws:
        Exception - If the JavaScript helpers can't be registered.
      • registerHelpers

        HelperRegistry registerHelpers​(String filename,
                                       InputStream 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.
        Returns:
        This handlebars object.
        Throws:
        Exception - If the JavaScript helpers can't be registered.
      • registerHelpers

        HelperRegistry 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.
        Returns:
        This registry.
        Throws:
        Exception - If the JavaScript helpers can't be registered.
      • decorator

        Decorator decorator​(String name)
        Find a decorator by name.
        Parameters:
        name - A decorator's name.
        Returns:
        A decorator or null.
        Since:
        4.0.0
      • registerDecorator

        HelperRegistry registerDecorator​(String name,
                                         Decorator decorator)
        Register a decorator and make it accessible via decorator(String).
        Parameters:
        name - A decorator's name. Required.
        decorator - A decorator. Required.
        Returns:
        This registry.
        Since:
        4.0.0