mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
commit
add7136bd6
5 changed files with 5 additions and 106 deletions
12
config.js
12
config.js
|
@ -3,18 +3,6 @@
|
||||||
var path = require('path'),
|
var path = require('path'),
|
||||||
config = {};
|
config = {};
|
||||||
|
|
||||||
// ## Default Navigation Items
|
|
||||||
// Add new objects here to extend the menu output by {{nav}}
|
|
||||||
config.nav = [
|
|
||||||
{
|
|
||||||
// Title is the text shown for this nav item
|
|
||||||
title: 'Home',
|
|
||||||
// Url can be a relative path, or external URL
|
|
||||||
url: '/'
|
|
||||||
}
|
|
||||||
// new items go here
|
|
||||||
];
|
|
||||||
|
|
||||||
// ## Environment
|
// ## Environment
|
||||||
// **Warning:** Only change the settings below here if you are sure of what you are doing!
|
// **Warning:** Only change the settings below here if you are sure of what you are doing!
|
||||||
config.env = {
|
config.env = {
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
var _ = require('underscore'),
|
|
||||||
defaultCoreFilterPriority = 4,
|
|
||||||
coreFilters;
|
|
||||||
|
|
||||||
coreFilters = function (ghost) {
|
|
||||||
ghost.registerFilter('ghostNavItems', defaultCoreFilterPriority, function (args) {
|
|
||||||
var selectedItem;
|
|
||||||
|
|
||||||
// we want to clone the config so the config remains unchanged
|
|
||||||
// we will need to make this recursive if we start supporting
|
|
||||||
// hierarchical menus
|
|
||||||
args.navItems = _.map(ghost.config().nav, function (value) {
|
|
||||||
return Object.create(value);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mark the current selected Item
|
|
||||||
selectedItem = _.find(args.navItems, function (item) {
|
|
||||||
// TODO: Better selection determination?
|
|
||||||
return item.url === args.path;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (selectedItem) {
|
|
||||||
selectedItem.active = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return args;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.loadCoreFilters = coreFilters;
|
|
|
@ -9,8 +9,7 @@ var _ = require('underscore'),
|
||||||
|
|
||||||
|
|
||||||
coreHelpers = function (ghost) {
|
coreHelpers = function (ghost) {
|
||||||
var navHelper,
|
var paginationHelper;
|
||||||
paginationHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [ description]
|
* [ description]
|
||||||
|
@ -309,19 +308,6 @@ coreHelpers = function (ghost) {
|
||||||
// ## Template driven helpers
|
// ## Template driven helpers
|
||||||
// Template driven helpers require that their template is loaded before they can be registered.
|
// Template driven helpers require that their template is loaded before they can be registered.
|
||||||
|
|
||||||
// ###Nav Helper
|
|
||||||
// `{{nav}}`
|
|
||||||
// Outputs a navigation menu built from items in config.js
|
|
||||||
navHelper = ghost.loadTemplate('nav').then(function (templateFn) {
|
|
||||||
ghost.registerThemeHelper('nav', function (options) {
|
|
||||||
if (!_.isObject(this.navItems) || _.isFunction(this.navItems)) {
|
|
||||||
errors.logAndThrowError('navItems data is not an object or is a function');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return new hbs.handlebars.SafeString(templateFn({links: this.navItems}));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// ### Pagination Helper
|
// ### Pagination Helper
|
||||||
// `{{pagination}}`
|
// `{{pagination}}`
|
||||||
// Outputs previous and next buttons, along with info about the current page
|
// Outputs previous and next buttons, along with info about the current page
|
||||||
|
@ -358,7 +344,6 @@ coreHelpers = function (ghost) {
|
||||||
});
|
});
|
||||||
// Return once the template-driven helpers have loaded
|
// Return once the template-driven helpers have loaded
|
||||||
return when.join(
|
return when.join(
|
||||||
navHelper,
|
|
||||||
paginationHelper
|
paginationHelper
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -245,43 +245,6 @@ describe('Core Helpers', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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)),
|
|
||||||
fakeNavItems = [{
|
|
||||||
title: 'test1',
|
|
||||||
url: '/test1'
|
|
||||||
}, {
|
|
||||||
title: 'test2',
|
|
||||||
url: '/test2'
|
|
||||||
}],
|
|
||||||
rendered;
|
|
||||||
|
|
||||||
helpers.loadCoreHelpers(ghost).then(function () {
|
|
||||||
rendered = handlebars.helpers.nav.call({navItems: fakeNavItems});
|
|
||||||
|
|
||||||
// Returns a string returned from navTemplateFunc
|
|
||||||
should.exist(rendered);
|
|
||||||
rendered.string.should.equal("rendered 2");
|
|
||||||
|
|
||||||
compileSpy.called.should.equal(true);
|
|
||||||
templateSpy.called.should.equal(true);
|
|
||||||
templateSpy.calledWith({ links: fakeNavItems }).should.equal(true);
|
|
||||||
|
|
||||||
|
|
||||||
compileSpy.restore();
|
|
||||||
|
|
||||||
done();
|
|
||||||
}).then(null, done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Pagination helper", function () {
|
describe("Pagination helper", function () {
|
||||||
var paginationRegex = /class="pagination"/,
|
var paginationRegex = /class="pagination"/,
|
||||||
newerRegex = /class="newer-posts"/,
|
newerRegex = /class="newer-posts"/,
|
||||||
|
|
15
index.js
15
index.js
|
@ -16,7 +16,6 @@ var express = require('express'),
|
||||||
api = require('./core/server/api'),
|
api = require('./core/server/api'),
|
||||||
Ghost = require('./core/ghost'),
|
Ghost = require('./core/ghost'),
|
||||||
I18n = require('./core/shared/lang/i18n'),
|
I18n = require('./core/shared/lang/i18n'),
|
||||||
filters = require('./core/server/filters'),
|
|
||||||
helpers = require('./core/server/helpers'),
|
helpers = require('./core/server/helpers'),
|
||||||
packageInfo = require('./package.json'),
|
packageInfo = require('./package.json'),
|
||||||
|
|
||||||
|
@ -105,15 +104,7 @@ function ghostLocals(req, res, next) {
|
||||||
res.locals = res.locals || {};
|
res.locals = res.locals || {};
|
||||||
res.locals.version = packageInfo.version;
|
res.locals.version = packageInfo.version;
|
||||||
|
|
||||||
if (!res.isAdmin) {
|
if (res.isAdmin) {
|
||||||
// filter the navigation items
|
|
||||||
ghost.doFilter('ghostNavItems', {path: req.path, navItems: []}, function (navData) {
|
|
||||||
// pass the theme navigation items, settings get configured as globals
|
|
||||||
_.extend(res.locals, navData);
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
api.users.read({id: req.session.user}).then(function (currentUser) {
|
api.users.read({id: req.session.user}).then(function (currentUser) {
|
||||||
_.extend(res.locals, {
|
_.extend(res.locals, {
|
||||||
// pass the admin flash messages, settings and paths
|
// pass the admin flash messages, settings and paths
|
||||||
|
@ -137,6 +128,8 @@ function ghostLocals(req, res, next) {
|
||||||
});
|
});
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +147,7 @@ function disableCachedResult(req, res, next) {
|
||||||
// Expose the promise we will resolve after our pre-loading
|
// Expose the promise we will resolve after our pre-loading
|
||||||
ghost.loaded = loading.promise;
|
ghost.loaded = loading.promise;
|
||||||
|
|
||||||
when.all([ghost.init(), filters.loadCoreFilters(ghost), helpers.loadCoreHelpers(ghost)]).then(function () {
|
when.all([ghost.init(), helpers.loadCoreHelpers(ghost)]).then(function () {
|
||||||
|
|
||||||
// ##Configuration
|
// ##Configuration
|
||||||
ghost.app().configure(function () {
|
ghost.app().configure(function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue