Skip to content

Commit

Permalink
added ghost_head and ghost_foot helpers
Browse files Browse the repository at this point in the history
closes TryGhost#382, closes TryGhost#383

 - added helper called ghost_head to insert meta data with current version of ghost
 - added helper called ghost_foot to insert script tag for jquery
 - added unit test for both helpers
 - removed trailing slash from ghost.js for 'shared' path and removed from outside of loop as it is shared on front and backend
  • Loading branch information
cobbspur committed Aug 25, 2013
1 parent b9f43ae commit 00d36e9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
3 changes: 1 addition & 2 deletions core/ghost.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,9 @@ Ghost.prototype.initTheme = function (app) {
app.set('views', self.paths().adminViews);
app.use('/public', express['static'](path.join(__dirname, '/client/assets')));
app.use('/public', express['static'](path.join(__dirname, '/client')));
app.use('/shared', express['static'](path.join(__dirname, '/shared/')));

}
app.use(express['static'](self.paths().activeTheme));
app.use('/shared', express['static'](path.join(__dirname, '/shared')));
app.use('/content/images', express['static'](path.join(__dirname, '/../content/images')));
next();
};
Expand Down
18 changes: 18 additions & 0 deletions core/server/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,25 @@ coreHelpers = function (ghost) {
});
});

ghost.registerThemeHelper('ghost_head', function (options) {
var head = [];
head.push('<meta name="generator" content="Ghost ' + this.version + '" />');

return ghost.doFilter('ghost_head', head, function (head) {
var headString = _.reduce(head, function (memo, item) { return memo + ' ' + item; }, '');
return new hbs.handlebars.SafeString(headString.trim());
});
});

ghost.registerThemeHelper('ghost_foot', function (options) {
var foot = [];
foot.push('<script src="/shared/vendor/jquery/jquery.js"></script>');

return ghost.doFilter('ghost_foot', foot, function (foot) {
var footString = _.reduce(foot, function (memo, item) { return memo + ' ' + item; }, '');
return new hbs.handlebars.SafeString(footString.trim());
});
});
/**
* [ description]
*
Expand Down
24 changes: 24 additions & 0 deletions core/test/unit/frontend_helpers_index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ describe('Core Helpers', function () {
});
});

describe('ghost_head Helper', function () {
it('has loaded ghost_head helper', function () {
should.exist(handlebars.helpers.ghost_head);
});

it('returns meta tag string', function () {
var rendered = handlebars.helpers.ghost_head.call({version: "0.3"});
should.exist(rendered);
rendered.string.should.equal('<meta name="generator" content="Ghost 0.3" />');
});
});

describe('ghost_foot Helper', function () {
it('has loaded ghost_foot helper', function () {
should.exist(handlebars.helpers.ghost_foot);
});

it('returns meta tag string', function () {
var rendered = handlebars.helpers.ghost_foot.call();
should.exist(rendered);
rendered.string.should.equal('<script src="/shared/vendor/jquery/jquery.js"></script>');
});
});

describe('Navigation Helper', function () {

it('has loaded nav helper', function () {
Expand Down

0 comments on commit 00d36e9

Please sign in to comment.