Paladox has uploaded a new change for review. https://gerrit.wikimedia.org/r/218273
Change subject: Update mustache.js from 0.8.2 to 1.2.0 ...................................................................... Update mustache.js from 0.8.2 to 1.2.0 Project link * https://github.com/janl/mustache.js File link * https://github.com/janl/mustache.js/blob/v1.2.0/mustache.js CHANGELOG link * https://github.com/janl/mustache.js/blob/v1.2.0/CHANGELOG.md 1.2.0 * Added -v option to CLI, by @phillipj. * Bugfix for rendering Number when it serves as the Context, by @phillipj. * Specified files in package.json for a cleaner install, by @phillipj. 1.1.0 * Refactor Writer.renderTokens() for better readability, by @phillipj. * Cleanup tests section in readme, by @phillipj. * Added JSHint to tests/CI, by @phillipj. * Added node v0.12 on travis, by @phillipj. * Created command line tool, by @phillipj. * Added *falsy* to Inverted Sections description in README, by * @kristijanmatic. 1.0.0 * Inline tag compilation, by @mjackson. * Fixed AMD registration, volo package.json entry, by @jrburke. * Added spm support, by @afc163. * Only access properties of objects on Context.lookup, by @cmbuckley. Upgrade from 0.8.2 to 1.2.0 Change-Id: If717bf0c40ff6426a6c09ce03f345cd7f1847636 --- M resources/lib/mustache/mustache.js 1 file changed, 79 insertions(+), 72 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/73/218273/1 diff --git a/resources/lib/mustache/mustache.js b/resources/lib/mustache/mustache.js index dbc9823..97394c4 100644 --- a/resources/lib/mustache/mustache.js +++ b/resources/lib/mustache/mustache.js @@ -444,88 +444,95 @@ Writer.prototype.renderTokens = function (tokens, context, partials, originalTemplate) { var buffer = ''; - // This function is used to render an arbitrary template - // in the current context by higher-order sections. - var self = this; - function subRender(template) { - return self.render(template, context, partials); - } - - var token, value; + var token, symbol, value; for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { + value = undefined; token = tokens[i]; + symbol = token[0]; - switch (token[0]) { - case '#': - value = context.lookup(token[1]); + if (symbol === '#') value = this._renderSection(token, context, partials, originalTemplate); + else if (symbol === '^') value = this._renderInverted(token, context, partials, originalTemplate); + else if (symbol === '>') value = this._renderPartial(token, context, partials, originalTemplate); + else if (symbol === '&') value = this._unescapedValue(token, context); + else if (symbol === 'name') value = this._escapedValue(token, context); + else if (symbol === 'text') value = this._rawValue(token); - if (!value) - continue; - - if (isArray(value)) { - for (var j = 0, valueLength = value.length; j < valueLength; ++j) { - buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate); - } - } else if (typeof value === 'object' || typeof value === 'string') { - buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate); - } else if (isFunction(value)) { - if (typeof originalTemplate !== 'string') - throw new Error('Cannot use higher-order sections without the original template'); - - // Extract the portion of the original template that the section contains. - value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender); - - if (value != null) - buffer += value; - } else { - buffer += this.renderTokens(token[4], context, partials, originalTemplate); - } - - break; - case '^': - value = context.lookup(token[1]); - - // Use JavaScript's definition of falsy. Include empty arrays. - // See https://github.com/janl/mustache.js/issues/186 - if (!value || (isArray(value) && value.length === 0)) - buffer += this.renderTokens(token[4], context, partials, originalTemplate); - - break; - case '>': - if (!partials) - continue; - - value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; - - if (value != null) - buffer += this.renderTokens(this.parse(value), context, partials, value); - - break; - case '&': - value = context.lookup(token[1]); - - if (value != null) - buffer += value; - - break; - case 'name': - value = context.lookup(token[1]); - - if (value != null) - buffer += mustache.escape(value); - - break; - case 'text': - buffer += token[1]; - break; - } + if (value !== undefined) + buffer += value; } return buffer; }; + Writer.prototype._renderSection = function (token, context, partials, originalTemplate) { + var self = this; + var buffer = ''; + var value = context.lookup(token[1]); + + // This function is used to render an arbitrary template + // in the current context by higher-order sections. + function subRender(template) { + return self.render(template, context, partials); + } + + if (!value) return; + + if (isArray(value)) { + for (var j = 0, valueLength = value.length; j < valueLength; ++j) { + buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate); + } + } else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') { + buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate); + } else if (isFunction(value)) { + if (typeof originalTemplate !== 'string') + throw new Error('Cannot use higher-order sections without the original template'); + + // Extract the portion of the original template that the section contains. + value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender); + + if (value != null) + buffer += value; + } else { + buffer += this.renderTokens(token[4], context, partials, originalTemplate); + } + return buffer; + }; + + Writer.prototype._renderInverted = function(token, context, partials, originalTemplate) { + var value = context.lookup(token[1]); + + // Use JavaScript's definition of falsy. Include empty arrays. + // See https://github.com/janl/mustache.js/issues/186 + if (!value || (isArray(value) && value.length === 0)) + return this.renderTokens(token[4], context, partials, originalTemplate); + }; + + Writer.prototype._renderPartial = function(token, context, partials) { + if (!partials) return; + + var value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; + if (value != null) + return this.renderTokens(this.parse(value), context, partials, value); + }; + + Writer.prototype._unescapedValue = function(token, context) { + var value = context.lookup(token[1]); + if (value != null) + return value; + }; + + Writer.prototype._escapedValue = function(token, context) { + var value = context.lookup(token[1]); + if (value != null) + return mustache.escape(value); + }; + + Writer.prototype._rawValue = function(token) { + return token[1]; + }; + mustache.name = "mustache.js"; - mustache.version = "0.8.2"; + mustache.version = "1.2.0"; mustache.tags = [ "{{", "}}" ]; // All high-level mustache.* functions use this writer. -- To view, visit https://gerrit.wikimedia.org/r/218273 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If717bf0c40ff6426a6c09ce03f345cd7f1847636 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Paladox <thomasmulhall...@yahoo.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits