mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 18:52:14 +03:00
commit
add7136bd6
12
config.js
12
config.js
@ -3,18 +3,6 @@
|
||||
var path = require('path'),
|
||||
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
|
||||
// **Warning:** Only change the settings below here if you are sure of what you are doing!
|
||||
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) {
|
||||
var navHelper,
|
||||
paginationHelper;
|
||||
var paginationHelper;
|
||||
|
||||
/**
|
||||
* [ description]
|
||||
@ -309,19 +308,6 @@ coreHelpers = function (ghost) {
|
||||
// ## Template driven helpers
|
||||
// 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}}`
|
||||
// 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 when.join(
|
||||
navHelper,
|
||||
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 () {
|
||||
var paginationRegex = /class="pagination"/,
|
||||
newerRegex = /class="newer-posts"/,
|
||||
|
15
index.js
15
index.js
@ -16,7 +16,6 @@ var express = require('express'),
|
||||
api = require('./core/server/api'),
|
||||
Ghost = require('./core/ghost'),
|
||||
I18n = require('./core/shared/lang/i18n'),
|
||||
filters = require('./core/server/filters'),
|
||||
helpers = require('./core/server/helpers'),
|
||||
packageInfo = require('./package.json'),
|
||||
|
||||
@ -105,15 +104,7 @@ function ghostLocals(req, res, next) {
|
||||
res.locals = res.locals || {};
|
||||
res.locals.version = packageInfo.version;
|
||||
|
||||
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 {
|
||||
if (res.isAdmin) {
|
||||
api.users.read({id: req.session.user}).then(function (currentUser) {
|
||||
_.extend(res.locals, {
|
||||
// pass the admin flash messages, settings and paths
|
||||
@ -137,6 +128,8 @@ function ghostLocals(req, res, next) {
|
||||
});
|
||||
next();
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +147,7 @@ function disableCachedResult(req, res, next) {
|
||||
// Expose the promise we will resolve after our pre-loading
|
||||
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
|
||||
ghost.app().configure(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user