Fixed bug in Story.getAbstract() causing erroneous rendering of custom content

This commit is contained in:
Tobi Schäfer 2015-02-06 11:11:08 +01:00
parent 7b836a2e63
commit 2b01579d39

View file

@ -423,28 +423,29 @@ Story.prototype.getMacroHandler = function(name) {
return null; return null;
} }
Story.prototype.getAbstract = function (param, titleTextRatio) { Story.prototype.getAbstract = function (param) {
param || (param = {}); param || (param = {});
titleTextRatio || (titleTextRatio = 0.5);
var limit = param.limit || 10; var limit = param.limit || 10;
var ratio = 0.5; // Use title and text equivalently
var result = [], raw = []; var result = [], raw = [];
raw.push(this.title, this.text); raw.push(this.title, this.text);
var titleLimit = Math[titleTextRatio >= 0.5 ? 'ceil' : 'floor'](limit * titleTextRatio); var titleLimit = Math[ratio >= 0.5 ? 'ceil' : 'floor'](limit * ratio);
var title = this.title && stripTags(this.title).clip(titleLimit, null, '\\s'); var title = this.title && stripTags(this.title).clip(titleLimit, null, '\\s');
var titleLength = title ? title.split(/\s/).length : 0; var titleLength = title ? title.split(/\s/).length : 0;
if (titleLength < titleLimit) { if (titleLength < titleLimit) {
titleTextRatio = titleLength / limit; ratio = titleLength / limit;
} }
var textLimit = Math[titleTextRatio < 0.5 ? 'ceil' : 'floor'](limit * (1 - titleTextRatio)); var textLimit = Math[ratio < 0.5 ? 'ceil' : 'floor'](limit * (1 - ratio));
var text = this.text && stripTags(this.text).clip(textLimit, null, '\\s'); var text = this.text && stripTags(this.text).clip(textLimit, null, '\\s');
title && result.push('<b>' + title + '</b> '); title && result.push('<b>' + title + '</b> ');
text && result.push(text); text && result.push(text);
if (result.length < 1 && arguments.length > 1) { var contentArgs = Array.prototype.slice.call(arguments, 1); // Remove first argument (param)
var buffer; if (result.length < 1 && contentArgs.length) {
for (var i = 1; i < arguments.length; i += 1) { ratio = 1 / contentArgs.length;
if (buffer = this.getMetadata(arguments[i])) { for (var i = 0, buffer, key = contentArgs[i]; i < contentArgs.length; i += 1) {
if (key && (buffer = this.getMetadata(key))) {
raw.push(buffer); raw.push(buffer);
buffer = stripTags(buffer).clip(limit, null, '\\s'); buffer = stripTags(buffer).clip(limit * ratio, null, '\\s');
buffer && result.push(buffer); buffer && result.push(buffer);
} }
} }
@ -459,8 +460,8 @@ Story.prototype.getAbstract = function (param, titleTextRatio) {
* *
* @param {Object} param * @param {Object} param
*/ */
Story.prototype.abstract_macro = function(param, titleTextRatio) { Story.prototype.abstract_macro = function(param) {
return res.write(this.getAbstract(param, titleTextRatio)); return res.write(this.getAbstract.call(this, param));
} }
/** /**