0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

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
This commit is contained in:
Vikas Potluri 2019-03-25 23:36:41 -05:00 committed by Rishabh Garg
parent 0c77033d51
commit 960993b257
2 changed files with 28 additions and 24 deletions

View file

@ -1,11 +1,11 @@
// # Asset helper // # 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 // Returns the path to the specified asset.
const proxy = require('./proxy'), const proxy = require('./proxy');
get = require('lodash/get'), const get = require('lodash/get');
getAssetUrl = proxy.metaData.getAssetUrl, const {SafeString} = proxy;
SafeString = proxy.SafeString; const {getAssetUrl} = proxy.metaData;
module.exports = function asset(path, options) { module.exports = function asset(path, options) {
const hasMinFile = get(options, 'hash.hasMinFile'); const hasMinFile = get(options, 'hash.hasMinFile');

View file

@ -6,27 +6,31 @@
// By default, authors are separated by commas. // By default, authors are separated by commas.
// //
// Note that the standard {{#each authors}} implementation is unaffected by this helper. // Note that the standard {{#each authors}} implementation is unaffected by this helper.
const proxy = require('./proxy'), const proxy = require('./proxy');
_ = require('lodash'), const _ = require('lodash');
urlService = require('../services/url'), const urlService = require('../services/url');
SafeString = proxy.SafeString, const {SafeString, templates, models} = proxy;
templates = proxy.templates,
models = proxy.models;
module.exports = function authors(options) { module.exports = function authors(options = {}) {
options = options || {};
options.hash = options.hash || {}; options.hash = options.hash || {};
const autolink = !(_.isString(options.hash.autolink) && options.hash.autolink === 'false'), let {
separator = _.isString(options.hash.separator) ? options.hash.separator : ', ', autolink,
prefix = _.isString(options.hash.prefix) ? options.hash.prefix : '', separator = ', ',
suffix = _.isString(options.hash.suffix) ? options.hash.suffix : '', prefix = '',
limit = options.hash.limit ? parseInt(options.hash.limit, 10) : undefined, suffix = '',
visibilityArr = models.Base.Model.parseVisibilityString(options.hash.visibility); limit,
visibility,
from = 1,
to
} = options.hash;
let output = '';
const visibilityArr = models.Base.Model.parseVisibilityString(visibility);
let output = '', autolink = !(_.isString(autolink) && autolink === 'false');
from = options.hash.from ? parseInt(options.hash.from, 10) : 1, limit = limit ? parseInt(limit, 10) : limit;
to = options.hash.to ? parseInt(options.hash.to, 10) : undefined; from = from ? parseInt(from, 10) : from;
to = to ? parseInt(to, 10) : to;
function createAuthorsList(authors) { function createAuthorsList(authors) {
function processAuthor(author) { function processAuthor(author) {
@ -36,7 +40,7 @@ module.exports = function authors(options) {
}) : _.escape(author.name); }) : _.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) { if (this.authors && this.authors.length) {