From 32935dc09ba185eaedf331d51fb508e5ff09de50 Mon Sep 17 00:00:00 2001 From: Phillip Johnsen Date: Tue, 17 Feb 2015 20:35:48 +0100 Subject: [PATCH] Bugfix for number rendered as [object Object] + minor fix for better error message when running specific render test Fixes #415 --- .gitignore | 1 + mustache.js | 2 +- test/_files/implicit_iterator.js | 8 ++++++++ test/_files/implicit_iterator.mustache | 7 +++++++ test/_files/implicit_iterator.txt | 3 +++ test/render-test.js | 6 +++++- 6 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/_files/implicit_iterator.js create mode 100644 test/_files/implicit_iterator.mustache create mode 100644 test/_files/implicit_iterator.txt diff --git a/.gitignore b/.gitignore index a4c0df6..9dcf445 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dojox yui3 qooxdoo.mustache.js +npm-debug.log diff --git a/mustache.js b/mustache.js index 47a396d..825b0c9 100644 --- a/mustache.js +++ b/mustache.js @@ -481,7 +481,7 @@ 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') { + } 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') diff --git a/test/_files/implicit_iterator.js b/test/_files/implicit_iterator.js new file mode 100644 index 0000000..2be2997 --- /dev/null +++ b/test/_files/implicit_iterator.js @@ -0,0 +1,8 @@ +({ + data: { + author: { + twitter_id: 819606, + name: 'janl' + } + } +}) diff --git a/test/_files/implicit_iterator.mustache b/test/_files/implicit_iterator.mustache new file mode 100644 index 0000000..ae31f34 --- /dev/null +++ b/test/_files/implicit_iterator.mustache @@ -0,0 +1,7 @@ +{{# data.author.twitter_id }} + +{{/ data.author.twitter_id }} + +{{# data.author.name }} + +{{/ data.author.name }} diff --git a/test/_files/implicit_iterator.txt b/test/_files/implicit_iterator.txt new file mode 100644 index 0000000..0fccefd --- /dev/null +++ b/test/_files/implicit_iterator.txt @@ -0,0 +1,3 @@ + + + diff --git a/test/render-test.js b/test/render-test.js index a011678..6aec0cf 100644 --- a/test/render-test.js +++ b/test/render-test.js @@ -5,7 +5,11 @@ var path = require('path'); var _files = path.join(__dirname, '_files'); function getContents(testName, ext) { - return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8'); + try { + return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8'); + } catch (ex) { + return null; + } } function getView(testName) {