mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Merge pull request #541 from cobbspur/helpers3
added url handlebars helper
This commit is contained in:
commit
02a8482447
@ -4,8 +4,10 @@ var _ = require('underscore'),
|
|||||||
when = require('when'),
|
when = require('when'),
|
||||||
hbs = require('express-hbs'),
|
hbs = require('express-hbs'),
|
||||||
errors = require('../errorHandling'),
|
errors = require('../errorHandling'),
|
||||||
|
models = require('../models'),
|
||||||
coreHelpers;
|
coreHelpers;
|
||||||
|
|
||||||
|
|
||||||
coreHelpers = function (ghost) {
|
coreHelpers = function (ghost) {
|
||||||
var navHelper,
|
var navHelper,
|
||||||
paginationHelper;
|
paginationHelper;
|
||||||
@ -29,6 +31,12 @@ coreHelpers = function (ghost) {
|
|||||||
return date;
|
return date;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ghost.registerThemeHelper('url', function (context, options) {
|
||||||
|
if (models.isPost(this)) {
|
||||||
|
return "/" + this.slug;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
// ### Author Helper
|
// ### Author Helper
|
||||||
//
|
//
|
||||||
|
@ -13,5 +13,9 @@ module.exports = {
|
|||||||
return migrations.reset().then(function () {
|
return migrations.reset().then(function () {
|
||||||
return migrations.init();
|
return migrations.init();
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
isPost: function (jsonData) {
|
||||||
|
return jsonData.hasOwnProperty("content") && jsonData.hasOwnProperty("content_raw")
|
||||||
|
&& jsonData.hasOwnProperty("title") && jsonData.hasOwnProperty("slug");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -201,6 +201,25 @@ describe('Core Helpers', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('url Helper', function () {
|
||||||
|
it('has loaded url helper', function () {
|
||||||
|
should.exist(handlebars.helpers.url);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('if context is post, returns a the slug with a prefix slash', function () {
|
||||||
|
var rendered = handlebars.helpers.url.call({content: 'content', content_raw: "ff", title: "title", slug: "slug"});
|
||||||
|
should.exist(rendered);
|
||||||
|
rendered.should.equal('/slug');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('it should return empty string if not a post', function () {
|
||||||
|
handlebars.helpers.url.call({content_raw: "ff", title: "title", slug: "slug"}).should.equal('');
|
||||||
|
handlebars.helpers.url.call({content: 'content', title: "title", slug: "slug"}).should.equal('');
|
||||||
|
handlebars.helpers.url.call({content: 'content', content_raw: "ff", slug: "slug"}).should.equal('');
|
||||||
|
handlebars.helpers.url.call({content: 'content', content_raw: "ff", title: "title"}).should.equal('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Navigation Helper', function () {
|
describe('Navigation Helper', function () {
|
||||||
|
|
||||||
it('has loaded nav helper', function () {
|
it('has loaded nav helper', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user