mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Updated local config helpers bind pattern
- The new @tryghost/config-url-helpers has a pattern of exposing bindAll() - Changed the local (non url) helpers to have the same pattern for consistency - Also fixed types as best I can
This commit is contained in:
parent
6aafb735b1
commit
8cf411e524
2 changed files with 18 additions and 7 deletions
|
@ -1,5 +1,10 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @callback isPrivacyDisabledFn
|
||||||
|
* @param {string} privacyFlag - the flag to be looked up
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
const isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
|
const isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
|
||||||
if (!this.get('privacy')) {
|
if (!this.get('privacy')) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -19,7 +24,9 @@ const isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* we can later support setting folder names via custom config values
|
* @callback getContentPathFn
|
||||||
|
* @param {string} type - the type of context you want the path for
|
||||||
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
const getContentPath = function getContentPath(type) {
|
const getContentPath = function getContentPath(type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -43,7 +50,12 @@ const getContentPath = function getContentPath(type) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
/**
|
||||||
isPrivacyDisabled,
|
* @typedef ConfigHelpers
|
||||||
getContentPath
|
* @property {isPrivacyDisabledFn} isPrivacyDisabled
|
||||||
|
* @property {getContentPathFn} getContentPath
|
||||||
|
*/
|
||||||
|
module.exports.bindAll = (nconf) => {
|
||||||
|
nconf.isPrivacyDisabled = isPrivacyDisabled.bind(nconf);
|
||||||
|
nconf.getContentPath = getContentPath.bind(nconf);
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,7 @@ const env = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} options
|
* @param {object} options
|
||||||
* @returns {Nconf.Provider & urlHelpers.BoundHelpers}
|
* @returns {Nconf.Provider & urlHelpers.BoundHelpers & helpers.ConfigHelpers}
|
||||||
*/
|
*/
|
||||||
function loadNconf(options) {
|
function loadNconf(options) {
|
||||||
debug('config start');
|
debug('config start');
|
||||||
|
@ -50,8 +50,7 @@ function loadNconf(options) {
|
||||||
nconf.checkUrlProtocol = localUtils.checkUrlProtocol.bind(nconf);
|
nconf.checkUrlProtocol = localUtils.checkUrlProtocol.bind(nconf);
|
||||||
|
|
||||||
// Expose dynamic utility methods
|
// Expose dynamic utility methods
|
||||||
nconf.isPrivacyDisabled = helpers.isPrivacyDisabled.bind(nconf);
|
helpers.bindAll(nconf);
|
||||||
nconf.getContentPath = helpers.getContentPath.bind(nconf);
|
|
||||||
urlHelpers.bindAll(nconf);
|
urlHelpers.bindAll(nconf);
|
||||||
|
|
||||||
// ## Sanitization
|
// ## Sanitization
|
||||||
|
|
Loading…
Add table
Reference in a new issue