From 1da0a15be2ed14d94459f934d0edf75a4eeb7961 Mon Sep 17 00:00:00 2001 From: Sebastian Gierlinger Date: Mon, 9 Sep 2013 13:00:03 +0200 Subject: [PATCH] Remove {{nav}} helper closes #626 - removed nav from config.js - removed navHelper - removed navHelper tests - removed core/server/filters --- config.js | 12 ------- core/server/filters/index.js | 30 ----------------- core/server/helpers/index.js | 17 +--------- core/test/unit/server_helpers_index_spec.js | 37 --------------------- index.js | 15 +++------ 5 files changed, 5 insertions(+), 106 deletions(-) delete mode 100644 core/server/filters/index.js diff --git a/config.js b/config.js index c0206dc662..b6ec04cc86 100644 --- a/config.js +++ b/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 = { diff --git a/core/server/filters/index.js b/core/server/filters/index.js deleted file mode 100644 index 3252d78d80..0000000000 --- a/core/server/filters/index.js +++ /dev/null @@ -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; \ No newline at end of file diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index d6b4475540..656b5de49e 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -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 ); }; diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js index 81e1a4a2af..1c021bfd5e 100644 --- a/core/test/unit/server_helpers_index_spec.js +++ b/core/test/unit/server_helpers_index_spec.js @@ -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"/, diff --git a/index.js b/index.js index 3a51f79384..3e843fe6fb 100644 --- a/index.js +++ b/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 () {