From 960993b2572e6a673cbb0e4f7a2940c672581599 Mon Sep 17 00:00:00 2001 From: Vikas Potluri Date: Mon, 25 Mar 2019 23:36:41 -0500 Subject: [PATCH] Migrated asset and author helpers to es6 (#10611) refs #9589 * update asset helper to use newer code standards * update authors helper to use newer code standards --- core/server/helpers/asset.js | 12 +++++----- core/server/helpers/authors.js | 44 ++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/core/server/helpers/asset.js b/core/server/helpers/asset.js index 529ccdebb92f..36a7d93d0ea4 100644 --- a/core/server/helpers/asset.js +++ b/core/server/helpers/asset.js @@ -1,11 +1,11 @@ // # Asset helper -// Usage: `{{asset "css/screen.css"}}`, `{{asset "css/screen.css" ghost="true"}}` +// Usage: `{{asset "css/screen.css"}}` // -// Returns the path to the specified asset. The ghost flag outputs the asset path for the Ghost admin -const proxy = require('./proxy'), - get = require('lodash/get'), - getAssetUrl = proxy.metaData.getAssetUrl, - SafeString = proxy.SafeString; +// Returns the path to the specified asset. +const proxy = require('./proxy'); +const get = require('lodash/get'); +const {SafeString} = proxy; +const {getAssetUrl} = proxy.metaData; module.exports = function asset(path, options) { const hasMinFile = get(options, 'hash.hasMinFile'); diff --git a/core/server/helpers/authors.js b/core/server/helpers/authors.js index 6010871c4214..0e2513a38564 100644 --- a/core/server/helpers/authors.js +++ b/core/server/helpers/authors.js @@ -6,27 +6,31 @@ // By default, authors are separated by commas. // // Note that the standard {{#each authors}} implementation is unaffected by this helper. -const proxy = require('./proxy'), - _ = require('lodash'), - urlService = require('../services/url'), - SafeString = proxy.SafeString, - templates = proxy.templates, - models = proxy.models; - -module.exports = function authors(options) { - options = options || {}; - options.hash = options.hash || {}; +const proxy = require('./proxy'); +const _ = require('lodash'); +const urlService = require('../services/url'); +const {SafeString, templates, models} = proxy; - const autolink = !(_.isString(options.hash.autolink) && options.hash.autolink === 'false'), - separator = _.isString(options.hash.separator) ? options.hash.separator : ', ', - prefix = _.isString(options.hash.prefix) ? options.hash.prefix : '', - suffix = _.isString(options.hash.suffix) ? options.hash.suffix : '', - limit = options.hash.limit ? parseInt(options.hash.limit, 10) : undefined, - visibilityArr = models.Base.Model.parseVisibilityString(options.hash.visibility); +module.exports = function authors(options = {}) { + options.hash = options.hash || {}; - let output = '', - from = options.hash.from ? parseInt(options.hash.from, 10) : 1, - to = options.hash.to ? parseInt(options.hash.to, 10) : undefined; + let { + autolink, + separator = ', ', + prefix = '', + suffix = '', + limit, + visibility, + from = 1, + to + } = options.hash; + let output = ''; + const visibilityArr = models.Base.Model.parseVisibilityString(visibility); + + autolink = !(_.isString(autolink) && autolink === 'false'); + limit = limit ? parseInt(limit, 10) : limit; + from = from ? parseInt(from, 10) : from; + to = to ? parseInt(to, 10) : to; function createAuthorsList(authors) { function processAuthor(author) { @@ -36,7 +40,7 @@ module.exports = function authors(options) { }) : _.escape(author.name); } - return models.Base.Model.filterByVisibility(authors, visibilityArr, !!options.hash.visibility, processAuthor); + return models.Base.Model.filterByVisibility(authors, visibilityArr, !!visibility, processAuthor); } if (this.authors && this.authors.length) {