Navigation Helper

- renamed helper from ghostNav to nav and file from ghostNav to navigation
- switched template to use current-menu-item as per the styles
- cleaned up several unused items from config, and removed default link to admin
- updated tests
This commit is contained in:
Hannah Wolfe 2013-06-25 22:44:34 +01:00
parent 289a40e031
commit 199d15133b
5 changed files with 23 additions and 41 deletions

View File

@ -33,27 +33,20 @@ config.forceI18n = true;
// Themes
config.themeDir = 'themes';
// Current active theme
/**
* @property {string} activeTheme
*/
config.activeTheme = 'casper';
// ## Homepage settings
// Default Navigation Items
/**
* @module homepage
* @type {Object}
* @property {Array} nav
*/
config.homepage = {};
/**
* @property {number} features
*/
config.homepage.features = 1;
/**
* @property {number} posts
*/
config.homepage.posts = 4;
config.nav = [{
title: 'Home',
url: '/'
}];
config.database = {
testing: {
@ -85,17 +78,6 @@ config.database = {
production: {}
};
/**
* @property {Array} nav
*/
config.nav = [{
title: 'Home',
url: '/'
}, {
title: 'Admin',
url: '/ghost'
}];
/**
* @property {Object} exports
*/

View File

@ -2,7 +2,7 @@ var _ = require('underscore'),
moment = require('moment'),
when = require('when'),
pagination = require('./paginate'),
navHelper = require('./ghostNav'),
navHelper = require('./navigation'),
hbs = require('express-hbs'),
coreHelpers;

View File

@ -3,9 +3,9 @@ var fs = require('fs'),
_ = require('underscore'),
handlebars = require('express-hbs').handlebars,
nodefn = require('when/node/function'),
GhostNavHelper;
NavHelper;
GhostNavHelper = function (navTemplate) {
NavHelper = function (navTemplate) {
// Bind the context for our methods.
_.bindAll(this, 'compileTemplate', 'renderNavItems');
@ -16,7 +16,7 @@ GhostNavHelper = function (navTemplate) {
}
};
GhostNavHelper.prototype.compileTemplate = function (templatePath) {
NavHelper.prototype.compileTemplate = function (templatePath) {
var self = this;
// Allow people to overwrite the navTemplatePath
@ -28,7 +28,7 @@ GhostNavHelper.prototype.compileTemplate = function (templatePath) {
});
};
GhostNavHelper.prototype.renderNavItems = function (navItems) {
NavHelper.prototype.renderNavItems = function (navItems) {
var output;
output = this.navTemplateFunc({links: navItems});
@ -37,13 +37,13 @@ GhostNavHelper.prototype.renderNavItems = function (navItems) {
};
// A static helper method for registering with ghost
GhostNavHelper.registerWithGhost = function (ghost) {
NavHelper.registerWithGhost = function (ghost) {
var templatePath = path.join(ghost.paths().frontendViews, 'nav.hbs'),
ghostNavHelper = new GhostNavHelper(templatePath);
ghostNavHelper = new NavHelper(templatePath);
return ghostNavHelper.compileTemplate().then(function () {
ghost.registerThemeHelper("ghostNav", ghostNavHelper.renderNavItems);
ghost.registerThemeHelper("nav", ghostNavHelper.renderNavItems);
});
};
module.exports = GhostNavHelper;
module.exports = NavHelper;

View File

@ -1,7 +1,7 @@
<nav id="site-navigation" role="navigation">
<ul>
{{#links}}
<li class="{{#active}}active{{/active}}"><a title="{{title}}" href="{{url}}">{{title}}</a></li>
<li class="{{#active}}current-menu-item{{/active}}"><a title="{{title}}" href="{{url}}">{{title}}</a></li>
{{/links}}
</ul>
</nav>

View File

@ -3,15 +3,15 @@ var should = require('should'),
sinon = require('sinon'),
_ = require('underscore'),
path = require('path'),
GhostNavHelper = require('../../frontend/helpers/ghostNav');
NavHelper = require('../../frontend/helpers/navigation');
describe('ghostNav Helper', function () {
describe('Navigation Helper', function () {
var navTemplatePath = path.join(process.cwd(), 'core/frontend/views/nav.hbs');
should.exist(GhostNavHelper, "GhostNavHelper exists");
should.exist(NavHelper, "Navigation helper exists");
it('can compile the nav template', function (done) {
var helper = new GhostNavHelper(navTemplatePath);
var helper = new NavHelper(navTemplatePath);
helper.compileTemplate().then(function () {
should.exist(helper.navTemplateFunc);
@ -22,7 +22,7 @@ describe('ghostNav Helper', function () {
});
it('can render nav items', function () {
var helper = new GhostNavHelper(function (data) { return "rendered " + data.links.length; }),
var helper = new NavHelper(function (data) { return "rendered " + data.links.length; }),
templateSpy = sinon.spy(helper, 'navTemplateFunc'),
fakeNavItems = [{
title: 'test1',
@ -56,7 +56,7 @@ describe('ghostNav Helper', function () {
},
registerStub = sinon.stub(fakeGhost, 'registerThemeHelper');
GhostNavHelper.registerWithGhost(fakeGhost).then(function () {
NavHelper.registerWithGhost(fakeGhost).then(function () {
registerStub.called.should.equal(true);
done();