Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions helpers/thirdParty.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -32,7 +47,6 @@ const whitelist = [
},
{
name: 'comparison',
module: require('./3p/comparison'),
include: [
'and',
'gt',
Expand Down Expand Up @@ -104,7 +118,6 @@ const whitelist = [
},
{
name: 'string',
module: require('./3p/string'),
include: [
'camelcase',
'capitalize',
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +85,10 @@ class HandlebarsRenderer {
this.overrideHelpers();
}

getHelpersForExternalUse() {
return helpers;
}

getResourceHints() {
return this.helperContext.resourceHints;
}
Expand Down Expand Up @@ -429,3 +437,4 @@ class HandlebarsRenderer {
}

module.exports = HandlebarsRenderer;
module.exports.HandlebarsRuntime = HandlebarsV4Runtime;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down