New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate asset and authors helpers to es6 #10611
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 || {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't use nested destructuring here because the input can be considered untrusted |
||
|
||
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) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not fully sure if we can get rid of this logic, but it seems like we should be able to 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔Thinking if losing the
isString
check in the destructuring default value here has any downsides. Seems it differs only when non-string value is passed toseparator
, which should be wrong usage so can be ignored as case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the only possible case I can think of is if the theme author passes in a variable (e.g. number of posts) 😟
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vikaspotluri123 Ah yeah, but passing number of posts in as a separator is still wrong usage in a way right? 😄I mean previously we would have just ignored it and set
,
as separator, so I think the changes are still ok ;) Wdyt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree 😄