Class: HandlebarsFormatterManager

HandlebarsFormatterManager

new HandlebarsFormatterManager(formatterMap, handlebarsInstanceopt)

A formatter that support all the functionality of Handlebars This supports full objects to use with handlebars and not just a function, as handlebars defaults to with helpers. This allows the passed in formatters to still work as a normal helper but keep the context of the object itself, something that is lost because handlebars justs wants a function when registering a helper
Parameters:
Name Type Attributes Default Description
formatterMap Object.<string, Formatter> Map of formatters where the key is the id of the helper (what will match in the {{ }}) and the value is the Formatter object that implements .format(value) and returns a string
handlebarsInstance Handlerbars <optional>
Handlebars.create() An instance (cannot be global) of handlebars to use. This allows for the preregistration of handlebars functionality if required. Defaults to Handlebars.create();
Implements:
Source:

Methods

addFormatters(formatterMap)

Adds a formatter. In the case of handlebars and this object, a 'Helper' object (not just the function) This supports full objects to use with handlebars and not just a function, as handlebars defaults to with helpers. This allows the passed in formatters to still work as a normal helper but keep the context of the object itself, something that is lost because handlebars justs wants a function when registering a helper
Parameters:
Name Type Description
formatterMap Object.<string, Formatter> Map of formatters where the key is the id of the helper (what will match in the {{ }}) and the value is the Formatter object that implements .format(value) and returns a string
Implements:
Source:

format(string, valuesMap) → {String}

Formats the string uses the values in the valueMap. If formatters have been registered the values will first be passed to the formatter to format the value and the resulting string will be placed in the placeholder ({{ }}) location in the passed in string
Parameters:
Name Type Description
string String The string to format
valuesMap Object.<string, Object> The values map where the key is equal to some variable in the handlebars placeholder ({{}}) and the value is the value to place in the placeholder (once passed through a formatter, if registered)
Implements:
Source:
Returns:
The final formatted string
Type
String

getFormatter(formatterId) → {Formatter}

Returns the formatter stored under the formatterId
Parameters:
Name Type Description
formatterId String The Id of the formatter to return
Implements:
Source:
Returns:
The formatter, null if not found;
Type
Formatter