diff --git a/helpers/thirdParty.js b/helpers/thirdParty.js index 9854a62..380ba39 100644 --- a/helpers/thirdParty.js +++ b/helpers/thirdParty.js @@ -1,5 +1,20 @@ 'use strict'; +const thirdPartyHelpers = { + array: require('./3p/array'), + collection: require('./3p/collection'), + comparison: require('./3p/comparison'), + html: require('./3p/html'), + inflection: require('./3p/inflection'), + markdown: require('./3p/markdown'), + math: require('./3p/math'), + misc: require('./3p/misc'), + number: require('./3p/number'), + object: require('./3p/object'), + string: require('./3p/string'), + url: require('./3p/url'), +}; + const whitelist = [ { name: 'array', @@ -32,7 +47,6 @@ const whitelist = [ }, { name: 'comparison', - module: require('./3p/comparison'), include: [ 'and', 'gt', @@ -104,7 +118,6 @@ const whitelist = [ }, { name: 'string', - module: require('./3p/string'), include: [ 'camelcase', 'capitalize', @@ -140,12 +153,7 @@ const whitelist = [ const exportedHelpers = []; for (let i = 0; i < whitelist.length; i++) { const spec = whitelist[i]; - - // Initialize module - const module = require(`./3p/${spec.name}`); - if (typeof spec.init === 'function') { - spec.init(module); - } + const module = thirdPartyHelpers[spec.name]; // Pluck whitelisted functions from each helper module and wrap in object of expected format const moduleWhitelist = spec.include; diff --git a/index.js b/index.js index 84272c7..af6942f 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ 'use strict'; const HandlebarsV3 = require('handlebars'); const HandlebarsV4 = require('@bigcommerce/handlebars-v4'); +const HandlebarsV4Runtime = require('@bigcommerce/handlebars-v4').runtime; const helpers = require('./helpers'); const AppError = require('./lib/appError'); @@ -39,6 +40,9 @@ class HandlebarsRenderer { constructor(siteSettings, themeSettings, hbVersion, logger = console, logLevel = 'info', params = {}) { // Figure out which version of Handlebars to use. switch(hbVersion) { + case 'v4-runtime': + this.handlebars = HandlebarsV4Runtime; + break; case 'v4': this.handlebars = HandlebarsV4.create(); break; @@ -81,6 +85,10 @@ class HandlebarsRenderer { this.overrideHelpers(); } + getHelpersForExternalUse() { + return helpers; + } + getResourceHints() { return this.helperContext.resourceHints; } @@ -429,3 +437,4 @@ class HandlebarsRenderer { } module.exports = HandlebarsRenderer; +module.exports.HandlebarsRuntime = HandlebarsV4Runtime; diff --git a/package.json b/package.json index 93dd89b..bc95514 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "homepage": "https://github.com/bigcommerce/paper-handlebars", "dependencies": { - "@bigcommerce/handlebars-v4": "4.7.8", + "@bigcommerce/handlebars-v4": "4.8.0", "chrono-node": "2.8.0", "handlebars": "3.0.8", "he": "^1.2.0",