From 5c1091af10a6c605faf0bdabf9f38fa4c13150e6 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Fri, 29 Nov 2013 18:44:03 +0000 Subject: [PATCH] Fix excerpt/content helpers fixes #1591 - Convert quoted strings to numbers - Update code examples - Update helper tests --- core/server/helpers/index.js | 20 +++++++++++++------- core/test/unit/server_helpers_index_spec.js | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index 34f8bc71bd..9004710e6a 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -119,8 +119,8 @@ coreHelpers.url = function (options) { // ### Asset helper // // *Usage example:* -// `{{asset src="css/screen.css"}}` -// `{{asset src="css/screen.css" ghost="true"}}` +// `{{asset "css/screen.css"}}` +// `{{asset "css/screen.css" ghost="true"}}` // // Returns the path to the specified asset. The ghost // flag outputs the asset path for the Ghost admin @@ -187,8 +187,8 @@ coreHelpers.tags = function (options) { // // *Usage example:* // `{{content}}` -// `{{content words=20}}` -// `{{content characters=256}}` +// `{{content words="20"}}` +// `{{content characters="256"}}` // // Turns content html into a safestring so that the user doesn't have to // escape it or tell handlebars to leave it alone with a triple-brace. @@ -200,6 +200,9 @@ coreHelpers.tags = function (options) { coreHelpers.content = function (options) { var truncateOptions = (options || {}).hash || {}; truncateOptions = _.pick(truncateOptions, ['words', 'characters']); + _.keys(truncateOptions).map(function (key) { + truncateOptions[key] = parseInt(truncateOptions[key], 10); + }); if (truncateOptions.words || truncateOptions.characters) { return new hbs.handlebars.SafeString( @@ -214,12 +217,12 @@ coreHelpers.content = function (options) { // // *Usage example:* // `{{excerpt}}` -// `{{excerpt words=50}}` -// `{{excerpt characters=256}}` +// `{{excerpt words="50"}}` +// `{{excerpt characters="256"}}` // // Attempts to remove all HTML from the string, and then shortens the result according to the provided option. // -// Defaults to words=50 +// Defaults to words="50" // // **returns** SafeString truncated, HTML-free content. // @@ -228,6 +231,9 @@ coreHelpers.excerpt = function (options) { excerpt; truncateOptions = _.pick(truncateOptions, ['words', 'characters']); + _.keys(truncateOptions).map(function (key) { + truncateOptions[key] = parseInt(truncateOptions[key], 10); + }); /*jslint regexp:true */ excerpt = String(this.html).replace(/<\/?[^>]+>/gi, ''); diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js index 07506c0720..664ba10c3e 100644 --- a/core/test/unit/server_helpers_index_spec.js +++ b/core/test/unit/server_helpers_index_spec.js @@ -136,7 +136,7 @@ describe('Core Helpers', function () { rendered = ( helpers.excerpt.call( {html: html}, - {"hash": {"words": 2}} + {"hash": {"words": "2"}} ) ); @@ -150,7 +150,7 @@ describe('Core Helpers', function () { rendered = ( helpers.excerpt.call( {html: html}, - {"hash": {"characters": 8}} + {"hash": {"characters": "8"}} ) );