mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
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:
parent
6b3f835cfb
commit
2b132f32b1
@ -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]
|
||||
*
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user