Class DefaultHelperRegistry

    • Constructor Detail

      • DefaultHelperRegistry

        public DefaultHelperRegistry()
    • Method Detail

      • helper

        public <C> Helper<C> helper​(java.lang.String name)
        Description copied from interface: HelperRegistry
        Find a helper by name.
        Specified by:
        helper in interface HelperRegistry
        Type Parameters:
        C - The helper runtime type.
        Parameters:
        name - The helper's name. Required.
        Returns:
        A helper or null if it's not found.
      • registerHelper

        public <H> HelperRegistry registerHelper​(java.lang.String name,
                                                 Helper<H> helper)
        Description copied from interface: HelperRegistry
        Register a helper in the helper registry.
        Specified by:
        registerHelper in interface HelperRegistry
        Type Parameters:
        H - The helper runtime type.
        Parameters:
        name - The helper's name. Required.
        helper - The helper object. Required.
        Returns:
        This handlebars.
      • registerHelperMissing

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

        public HelperRegistry registerHelpers​(java.lang.Object helperSource)
        Description copied from interface: HelperRegistry

        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.
        Specified by:
        registerHelpers in interface HelperRegistry
        Parameters:
        helperSource - The helper source. Required.
        Returns:
        This handlebars object.
      • registerHelpers

        public HelperRegistry registerHelpers​(java.lang.Class<?> helperSource)
        Description copied from interface: HelperRegistry

        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

        Specified by:
        registerHelpers in interface HelperRegistry
        Parameters:
        helperSource - The helper source. Enums are supported. Required.
        Returns:
        This handlebars object.
      • registerHelpers

        public HelperRegistry registerHelpers​(java.net.URI location)
                                       throws java.lang.Exception
        Description copied from interface: HelperRegistry

        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.
        Specified by:
        registerHelpers in interface HelperRegistry
        Parameters:
        location - A classpath location. Required.
        Returns:
        This handlebars object.
        Throws:
        java.lang.Exception - If the JavaScript helpers can't be registered.
      • registerHelpers

        public HelperRegistry registerHelpers​(java.io.File input)
                                       throws java.lang.Exception
        Description copied from interface: HelperRegistry

        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.
        Specified by:
        registerHelpers in interface HelperRegistry
        Parameters:
        input - A JavaScript file name. Required.
        Returns:
        This handlebars object.
        Throws:
        java.lang.Exception - If the JavaScript helpers can't be registered.
      • registerHelpers

        public HelperRegistry registerHelpers​(java.lang.String filename,
                                              java.io.Reader source)
                                       throws java.lang.Exception
        Description copied from interface: HelperRegistry

        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.
        Specified by:
        registerHelpers in interface HelperRegistry
        Parameters:
        filename - The file name (just for debugging purpose). Required.
        source - The JavaScript source. Required.
        Returns:
        This handlebars object.
        Throws:
        java.lang.Exception - If the JavaScript helpers can't be registered.
      • registerHelpers

        public HelperRegistry registerHelpers​(java.lang.String filename,
                                              java.io.InputStream source)
                                       throws java.lang.Exception
        Description copied from interface: HelperRegistry

        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.
        Specified by:
        registerHelpers in interface HelperRegistry
        Parameters:
        filename - The file name (just for debugging purpose). Required.
        source - The JavaScript source. Required.
        Returns:
        This handlebars object.
        Throws:
        java.lang.Exception - If the JavaScript helpers can't be registered.
      • registerHelpers

        public HelperRegistry registerHelpers​(java.lang.String filename,
                                              java.lang.String source)
                                       throws java.io.IOException
        Description copied from interface: HelperRegistry

        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.
        Specified by:
        registerHelpers in interface HelperRegistry
        Parameters:
        filename - The file name (just for debugging purpose). Required.
        source - The JavaScript source. Required.
        Returns:
        This registry.
        Throws:
        java.io.IOException - If the JavaScript helpers can't be registered.
      • helpers

        public java.util.Set<java.util.Map.Entry<java.lang.String,​Helper<?>>> helpers()
        Description copied from interface: HelperRegistry
        List all the helpers from registry.
        Specified by:
        helpers in interface HelperRegistry
        Returns:
        Available helpers in the registry.
      • decorator

        public Decorator decorator​(java.lang.String name)
        Description copied from interface: HelperRegistry
        Find a decorator by name.
        Specified by:
        decorator in interface HelperRegistry
        Parameters:
        name - A decorator's name.
        Returns:
        A decorator or null.