Content helper - closes #254

- return content as a safe string so triple taches are not required
- test for content helper
This commit is contained in:
Hannah Wolfe 2013-07-11 17:21:42 +01:00
parent 6b3f835cfb
commit 2b132f32b1
2 changed files with 32 additions and 8 deletions

View File

@ -13,12 +13,12 @@ coreHelpers = function (ghost) {
* [ description]
* @todo ghost core helpers + a way for themes to register them
* @param {Object} context date object
* @param {*} block
* @param {*} options
* @return {Object} A Moment time / date object
*/
ghost.registerThemeHelper('dateFormat', function (context, block) {
var f = block.hash.format || "MMM Do, YYYY",
timeago = block.hash.timeago,
ghost.registerThemeHelper('dateFormat', function (context, options) {
var f = options.hash.format || "MMM Do, YYYY",
timeago = options.hash.timeago,
date;
if (timeago) {
date = moment(context).fromNow();
@ -28,6 +28,13 @@ coreHelpers = function (ghost) {
return date;
});
// ### Content Helper
// Turns content html into a safestring so that the user doesn't have to escape it
ghost.registerThemeHelper('content', function (options) {
return new hbs.handlebars.SafeString(this.content);
});
/**
* [ description]
*

View File

@ -12,13 +12,33 @@ describe('Core Helpers', function () {
var ghost;
beforeEach(function () {
beforeEach(function (done) {
ghost = new Ghost();
helpers.loadCoreHelpers(ghost).then(function () {
done();
}, done);
});
describe('Content Helper', function () {
it('has loaded content helper', function () {
should.exist(handlebars.helpers.content);
});
it('can render content', function () {
var content = "Hello World",
rendered = handlebars.helpers.content.call({content: content});
should.exist(rendered);
rendered.string.should.equal(content);
});
});
describe('Navigation Helper', function () {
it('has loaded nav helper', function () {
should.exist(handlebars.helpers.nav);
});
it('can render nav items', function (done) {
var templateSpy = sinon.spy(function (data) { return "rendered " + data.links.length; }),
compileSpy = sinon.stub(ghost, 'compileTemplate').returns(when.resolve(templateSpy)),
@ -32,9 +52,6 @@ describe('Core Helpers', function () {
rendered;
helpers.loadCoreHelpers(ghost).then(function () {
should.exist(handlebars.helpers.nav);
rendered = handlebars.helpers.nav.call({navItems: fakeNavItems});
// Returns a string returned from navTemplateFunc