@bigcommerce/stencil-paper-handlebars
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -11,1 +11,7 @@ # Changelog | ||
- Remove logging interface since we don't use it anymore. | ||
## 3.0.0 | ||
- Change addContent() to setContent() for consistency with other setters. | ||
- Add getter and setter for siteSettings and themeSettings, and change helper context | ||
to use a bound function for accessing these data to allow for deferred setting. | ||
Callers should no longer access siteSettings and themeSettings directly. |
@@ -59,3 +59,3 @@ 'use strict'; | ||
_.each(globals.themeSettings, function (value, key) { | ||
_.each(globals.getThemeSettings(), function (value, key) { | ||
var split; | ||
@@ -62,0 +62,0 @@ |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var sizeRegex = /^(\d+?)x(\d+?)$/g; | ||
var settings = globals.themeSettings || {}; | ||
var settings = globals.getThemeSettings() || {}; | ||
var presets = settings._images; | ||
@@ -11,0 +11,0 @@ var size; |
@@ -5,7 +5,10 @@ 'use strict'; | ||
module.exports = globals => { | ||
const cdnUrl = globals.siteSettings['cdn_url'] || ''; | ||
const versionId = globals.siteSettings['theme_version_id']; | ||
const editSessionId = globals.siteSettings['theme_session_id']; | ||
const cdnSettings = globals.themeSettings.cdn; | ||
const siteSettings = globals.getSiteSettings(); | ||
const themeSettings = globals.getThemeSettings(); | ||
const cdnUrl = siteSettings.cdn_url || ''; | ||
const versionId = siteSettings.theme_version_id; | ||
const editSessionId = siteSettings.theme_session_id; | ||
const cdnSettings = themeSettings.cdn; | ||
/** | ||
@@ -12,0 +15,0 @@ * Add CDN base url to the relative path |
@@ -21,3 +21,4 @@ 'use strict'; | ||
return function(value) { | ||
var money = globals.siteSettings.money; | ||
const siteSettings = globals.getSiteSettings(); | ||
const money = siteSettings.money; | ||
@@ -24,0 +25,0 @@ if (!_.isNumber(value)) { |
@@ -8,6 +8,8 @@ 'use strict'; | ||
const cdnify = buildCDNHelper(globals); | ||
const siteSettings = globals.getSiteSettings(); | ||
const configId = siteSettings.theme_config_id; | ||
return function(assetPath) { | ||
const options = arguments[arguments.length - 1]; | ||
const configId = globals.siteSettings['theme_config_id']; | ||
// append the configId only if the asset path starts with assets/css/ | ||
@@ -14,0 +16,0 @@ const path = configId && assetPath.match(/^\/?assets\/css\//) |
113
index.js
@@ -52,11 +52,13 @@ 'use strict'; | ||
this._translator = null; | ||
this._decorators = []; | ||
this._contentRegions = {}; | ||
this.setSiteSettings(siteSettings || {}); | ||
this.setThemeSettings(themeSettings || {}); | ||
this.setTranslator(null); | ||
this.setContent({}); | ||
this.resetDecorators(); | ||
// Build global context for helpers | ||
this.helperContext = { | ||
siteSettings: siteSettings || {}, | ||
themeSettings: themeSettings || {}, | ||
handlebars: this.handlebars, | ||
getSiteSettings: this.getSiteSettings.bind(this), | ||
getThemeSettings: this.getThemeSettings.bind(this), | ||
getTranslator: this.getTranslator.bind(this), | ||
@@ -76,3 +78,3 @@ getContent: this.getContent.bind(this), | ||
* | ||
* @param {Translator} A paper.Translator instance used to translate strings in helpers | ||
* @param {Translator} translator A paper.Translator instance used to translate strings in helpers | ||
*/ | ||
@@ -85,2 +87,4 @@ setTranslator(translator) { | ||
* Get the paper.Translator instance used to translate strings in helpers. | ||
* | ||
* @return {Translator} A paper.Translator instance used to translate strings in helpers | ||
*/ | ||
@@ -92,2 +96,72 @@ getTranslator() { | ||
/** | ||
* Set the siteSettings object containing global site settings. | ||
* | ||
* @param {object} settings An object containing global site settings. | ||
*/ | ||
setSiteSettings(settings) { | ||
this._siteSettings = settings; | ||
}; | ||
/** | ||
* Get the siteSettings object containing global site settings. | ||
* | ||
* @return {object} settings An object containing global site settings. | ||
*/ | ||
getSiteSettings() { | ||
return this._siteSettings; | ||
}; | ||
/** | ||
* Set the themeSettings object containing the theme configuration. | ||
* | ||
* @param {object} settings An object containing the theme configuration. | ||
*/ | ||
setThemeSettings(settings) { | ||
this._themeSettings = settings; | ||
}; | ||
/** | ||
* Get the themeSettings object containing the theme configuration. | ||
* | ||
* @return {object} settings An object containing the theme configuration. | ||
*/ | ||
getThemeSettings() { | ||
return this._themeSettings; | ||
}; | ||
/** | ||
* Reset decorator list. | ||
*/ | ||
resetDecorators() { | ||
this._decorators = []; | ||
}; | ||
/** | ||
* Add a decorator to be applied at render time. | ||
* | ||
* @param {Function} decorator | ||
*/ | ||
addDecorator(decorator) { | ||
this._decorators.push(decorator); | ||
}; | ||
/** | ||
* Setup content regions to be used by the `region` helper. | ||
* | ||
* @param {Object} Regions with widgets | ||
*/ | ||
setContent(regions) { | ||
this._contentRegions = regions; | ||
}; | ||
/** | ||
* Get content regions. | ||
* | ||
* @param {Object} Regions with widgets | ||
*/ | ||
getContent() { | ||
return this._contentRegions; | ||
}; | ||
/** | ||
* Add templates to the active set of partials. The templates can either be raw | ||
@@ -167,29 +241,2 @@ * template strings, or the result coming from the preProcessor function. | ||
/** | ||
* Add a decorator to be applied at render time. | ||
* | ||
* @param {Function} decorator | ||
*/ | ||
addDecorator(decorator) { | ||
this._decorators.push(decorator); | ||
}; | ||
/** | ||
* Add content regions to be used by the `region` helper. | ||
* | ||
* @param {Object} Regions with widgets | ||
*/ | ||
addContent(regions) { | ||
this._contentRegions = regions; | ||
}; | ||
/** | ||
* Get content regions. | ||
* | ||
* @param {Object} Regions with widgets | ||
*/ | ||
getContent() { | ||
return this._contentRegions; | ||
}; | ||
/** | ||
* Render a template with the given context | ||
@@ -196,0 +243,0 @@ * |
{ | ||
"name": "@bigcommerce/stencil-paper-handlebars", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "A paper plugin to render pages using Handlebars.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,3 +26,3 @@ 'use strict'; | ||
renderer = buildRenderer(); | ||
renderer.addContent(context); | ||
renderer.setContent(context); | ||
@@ -29,0 +29,0 @@ done(); |
@@ -67,3 +67,3 @@ 'use strict'; | ||
it('puts empty site settings into the helper context when not provided', done => { | ||
expect(renderer.helperContext.siteSettings).to.equal({}); | ||
expect(renderer.helperContext.getSiteSettings()).to.equal({}); | ||
done(); | ||
@@ -75,3 +75,3 @@ }); | ||
renderer = new HandlebarsRenderer(siteSettings); | ||
expect(renderer.helperContext.siteSettings).to.equal(siteSettings); | ||
expect(renderer.helperContext.getSiteSettings()).to.equal(siteSettings); | ||
done(); | ||
@@ -81,3 +81,3 @@ }); | ||
it('puts empty theme settings into the helper context when not provided', done => { | ||
expect(renderer.helperContext.themeSettings).to.equal({}); | ||
expect(renderer.helperContext.getThemeSettings()).to.equal({}); | ||
done(); | ||
@@ -89,3 +89,3 @@ }); | ||
renderer = new HandlebarsRenderer({}, themeSettings); | ||
expect(renderer.helperContext.themeSettings).to.equal(themeSettings); | ||
expect(renderer.helperContext.getThemeSettings()).to.equal(themeSettings); | ||
done(); | ||
@@ -103,3 +103,3 @@ }); | ||
const content = { foo: 'bar' }; | ||
renderer.addContent(content); | ||
renderer.setContent(content); | ||
expect(renderer.helperContext.getContent()).to.equal(content); | ||
@@ -106,0 +106,0 @@ done(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131269
3328
3512