Class DefaultHelperRegistry
java.lang.Object
com.github.jknack.handlebars.helper.DefaultHelperRegistry
- All Implemented Interfaces:
HelperRegistry
Default implementation of
HelperRegistry.- Since:
- 1.2.0
-
Field Summary
Fields inherited from interface com.github.jknack.handlebars.HelperRegistry
HELPER_MISSING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFind a decorator by name.<C> Helper<C> Find a helper by name.helpers()List all the helpers from registry.registerDecorator(String name, Decorator decorator) Register a decorator and make it accessible viaHelperRegistry.decorator(String).<H> HelperRegistryregisterHelper(String name, Helper<H> helper) Register a helper in the helper registry.<H> HelperRegistryregisterHelperMissing(Helper<H> helper) Register the special helper missing in the registry.registerHelpers(File input) Register helpers from a JavaScript source.registerHelpers(Class<?> helperSource) Register all the helper methods for the given helper source.registerHelpers(Object helperSource) Register all the helper methods for the given helper source.registerHelpers(String filename, InputStream source) Register helpers from a JavaScript source.registerHelpers(String filename, Reader source) Register helpers from a JavaScript source.registerHelpers(String filename, String source) Register helpers from a JavaScript source.registerHelpers(URI location) Register helpers from a JavaScript source.setCharset(Charset charset) Set the charset to use.
-
Constructor Details
-
DefaultHelperRegistry
public DefaultHelperRegistry()
-
-
Method Details
-
helper
Description copied from interface:HelperRegistryFind a helper by name.- Specified by:
helperin interfaceHelperRegistry- 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
Description copied from interface:HelperRegistryRegister a helper in the helper registry.- Specified by:
registerHelperin interfaceHelperRegistry- Type Parameters:
H- The helper runtime type.- Parameters:
name- The helper's name. Required.helper- The helper object. Required.- Returns:
- This handlebars.
-
registerHelperMissing
Description copied from interface:HelperRegistryRegister the special helper missing in the registry.- Specified by:
registerHelperMissingin interfaceHelperRegistry- Type Parameters:
H- The helper runtime type.- Parameters:
helper- The helper object. Required.- Returns:
- This handlebars.
-
registerHelpers
Description copied from interface:HelperRegistryRegister 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.
- Specified by:
registerHelpersin interfaceHelperRegistry- Parameters:
helperSource- The helper source. Required.- Returns:
- This handlebars object.
-
registerHelpers
Description copied from interface:HelperRegistryRegister 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.
Enums are supported too
- Specified by:
registerHelpersin interfaceHelperRegistry- Parameters:
helperSource- The helper source. Enums are supported. Required.- Returns:
- This handlebars object.
-
registerHelpers
Description copied from interface:HelperRegistryRegister 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:
registerHelpersin interfaceHelperRegistry- Parameters:
location- A classpath location. Required.- Returns:
- This handlebars object.
- Throws:
Exception- If the JavaScript helpers can't be registered.
-
registerHelpers
Description copied from interface:HelperRegistryRegister 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:
registerHelpersin interfaceHelperRegistry- Parameters:
input- A JavaScript file name. Required.- Returns:
- This handlebars object.
- Throws:
Exception- If the JavaScript helpers can't be registered.
-
registerHelpers
Description copied from interface:HelperRegistryRegister 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:
registerHelpersin interfaceHelperRegistry- 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
Description copied from interface:HelperRegistryRegister 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:
registerHelpersin interfaceHelperRegistry- 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
Description copied from interface:HelperRegistryRegister 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:
registerHelpersin interfaceHelperRegistry- Parameters:
filename- The file name (just for debugging purpose). Required.source- The JavaScript source. Required.- Returns:
- This registry.
- Throws:
IOException- If the JavaScript helpers can't be registered.
-
helpers
Description copied from interface:HelperRegistryList all the helpers from registry.- Specified by:
helpersin interfaceHelperRegistry- Returns:
- Available helpers in the registry.
-
decorator
Description copied from interface:HelperRegistryFind a decorator by name.- Specified by:
decoratorin interfaceHelperRegistry- Parameters:
name- A decorator's name.- Returns:
- A decorator or
null.
-
registerDecorator
Description copied from interface:HelperRegistryRegister a decorator and make it accessible viaHelperRegistry.decorator(String).- Specified by:
registerDecoratorin interfaceHelperRegistry- Parameters:
name- A decorator's name. Required.decorator- A decorator. Required.- Returns:
- This registry.
-
setCharset
Description copied from interface:HelperRegistrySet the charset to use.- Specified by:
setCharsetin interfaceHelperRegistry- Parameters:
charset- Charset.- Returns:
- This registry.
-