From 53fe5e3ba3e26b9320ffefa7b0b27f65abad1619 Mon Sep 17 00:00:00 2001 From: ErisDS Date: Tue, 9 Jul 2013 16:55:23 +0100 Subject: [PATCH] HTML helpers work with double taches - issue #246 item 1. - updated navigation and pagination helpers to use SafeString - nav and pagination don't need triple taches any more - nav tests updated, and renamed to match helper name --- core/frontend/helpers/navigation.js | 7 ++----- core/frontend/helpers/paginate.js | 8 +++----- ...ostNav_spec.js => frontend_helpers_navigation_spec.js} | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) rename core/test/ghost/{frontend_helpers_ghostNav_spec.js => frontend_helpers_navigation_spec.js} (97%) diff --git a/core/frontend/helpers/navigation.js b/core/frontend/helpers/navigation.js index f88573d440..0ed7a4a526 100644 --- a/core/frontend/helpers/navigation.js +++ b/core/frontend/helpers/navigation.js @@ -3,6 +3,7 @@ var fs = require('fs'), _ = require('underscore'), handlebars = require('express-hbs').handlebars, nodefn = require('when/node/function'), + NavHelper; NavHelper = function (navTemplate) { @@ -29,11 +30,7 @@ NavHelper.prototype.compileTemplate = function (templatePath) { }; NavHelper.prototype.renderNavItems = function (navItems) { - var output; - - output = this.navTemplateFunc({links: navItems}); - - return output; + return new handlebars.SafeString(this.navTemplateFunc({links: navItems})); }; // A static helper method for registering with ghost diff --git a/core/frontend/helpers/paginate.js b/core/frontend/helpers/paginate.js index 070d966be1..5ff4130df7 100644 --- a/core/frontend/helpers/paginate.js +++ b/core/frontend/helpers/paginate.js @@ -20,7 +20,7 @@ PaginationHelper = function (paginationTemplate) { PaginationHelper.prototype.compileTemplate = function (templatePath) { var self = this; - + // Allow people to overwrite the paginationTemplatePath templatePath = templatePath || this.paginationTemplatePath; return nodefn.call(fs.readFile, templatePath).then(function (paginationContents) { @@ -29,12 +29,10 @@ PaginationHelper.prototype.compileTemplate = function (templatePath) { }); }; -PaginationHelper.prototype.renderPagination = function (context, options) { - var output = this.paginationTemplateFunc(context); - return output; +PaginationHelper.prototype.renderPagination = function (context) { + return new handlebars.SafeString(this.paginationTemplateFunc(context)); }; - PaginationHelper.registerWithGhost = function (ghost) { var templatePath = path.join(ghost.paths().frontendViews, 'pagination.hbs'), paginationHelper = new PaginationHelper(templatePath); diff --git a/core/test/ghost/frontend_helpers_ghostNav_spec.js b/core/test/ghost/frontend_helpers_navigation_spec.js similarity index 97% rename from core/test/ghost/frontend_helpers_ghostNav_spec.js rename to core/test/ghost/frontend_helpers_navigation_spec.js index a044b0b78d..84aafad41e 100644 --- a/core/test/ghost/frontend_helpers_ghostNav_spec.js +++ b/core/test/ghost/frontend_helpers_navigation_spec.js @@ -37,7 +37,7 @@ describe('Navigation Helper', function () { // Returns a string returned from navTemplateFunc should.exist(rendered); - rendered.should.equal("rendered 2"); + rendered.string.should.equal("rendered 2"); templateSpy.calledWith({ links: fakeNavItems }).should.equal(true); });