From 9a7e153549daff688adfbdd8d6a83dfdbba09cbe Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Wed, 29 May 2013 01:10:39 +0100 Subject: [PATCH] #25: admin navbar and filter --- app.js | 12 ++++++-- content/plugins/exampleFilters.js | 27 +++++++++++++++++ content/plugins/fancyFirstChar.js | 3 ++ core/admin/controllers/index.js | 32 +++++++++++--------- core/admin/views/{blog.hbs => content.hbs} | 0 core/admin/views/partials/navbar.hbs | 3 +- core/ghost.js | 34 +++++++++++++++------- 7 files changed, 84 insertions(+), 27 deletions(-) create mode 100644 content/plugins/exampleFilters.js rename core/admin/views/{blog.hbs => content.hbs} (100%) diff --git a/app.js b/app.js index f800a84777a..75432714d05 100755 --- a/app.js +++ b/app.js @@ -14,6 +14,8 @@ I18n = require('./core/lang/i18n'), helpers = require('./core/frontend/helpers'), + + // ## Variables auth, authAPI, @@ -24,6 +26,7 @@ */ ghost = new Ghost(); + ghost.app().configure('development', function () { ghost.app().use(express.favicon(__dirname + '/content/images/favicon.ico')); ghost.app().use(express.errorHandler({ dumpExceptions: true, showStack: true })); @@ -41,6 +44,10 @@ }); }); + + + + /** * Setup login details * p.s. love it. @@ -94,7 +101,7 @@ ghost.app().post('/ghost/register/', admin.doRegister); ghost.app().get('/ghost/editor/:id', auth, admin.editor); ghost.app().get('/ghost/editor', auth, admin.editor); - ghost.app().get('/ghost/blog', auth, admin.blog); + ghost.app().get('/ghost/content', auth, admin.content); ghost.app().get('/ghost/settings', auth, admin.settings); ghost.app().get('/ghost/debug', auth, admin.debug.index); ghost.app().get('/ghost/debug/db/delete/', auth, admin.debug.dbdelete); @@ -105,7 +112,7 @@ ghost.app().get('/ghost/', auth, admin.index); /** - * Frontend routes.. + * Frontend routes * @todo dynamic routing, homepage generator, filters ETC ETC */ ghost.app().get('/:slug', frontend.single); @@ -114,5 +121,6 @@ ghost.app().listen(3333, function () { console.log("Express server listening on port " + 3333); + }); }()); \ No newline at end of file diff --git a/content/plugins/exampleFilters.js b/content/plugins/exampleFilters.js new file mode 100644 index 00000000000..712525d583d --- /dev/null +++ b/content/plugins/exampleFilters.js @@ -0,0 +1,27 @@ +(function(){ + "use strict"; + + /** + * Because I didn't want to write over FancyFirstChar + */ + var ExampleFilter; + + var ExampleFilter = function(ghost){ + this.ghost = function() { + return ghost; + } + } + + ExampleFilter.prototype.init = function() { + + this.ghost().registerFilter('messWithAdmin', function(adminNavbar){ + console.log('adminnavbar settings run'); + delete adminNavbar.add; + return adminNavbar; + }); + + }; + + module.exports = ExampleFilter; + +}()); \ No newline at end of file diff --git a/content/plugins/fancyFirstChar.js b/content/plugins/fancyFirstChar.js index f133346be91..b3652f11f89 100644 --- a/content/plugins/fancyFirstChar.js +++ b/content/plugins/fancyFirstChar.js @@ -9,6 +9,7 @@ return ghost; }; }; + FancyFirstChar.prototype.init = function () { this.ghost().registerFilter('prePostsRender', function (posts) { var post, @@ -41,5 +42,7 @@ FancyFirstChar.prototype.activate = function () {}; FancyFirstChar.prototype.deactivate = function () {}; + + module.exports = FancyFirstChar; }()); diff --git a/core/admin/controllers/index.js b/core/admin/controllers/index.js index 67510658c86..c9b888f1230 100755 --- a/core/admin/controllers/index.js +++ b/core/admin/controllers/index.js @@ -17,32 +17,36 @@ name: 'Dashboard', navClass: 'dashboard', key: 'admin.navbar.dashboard', - defaultString: 'dashboard', - path: '' + // defaultString: 'dashboard', + path: '/' }, - blog: { + content: { name: 'Content', navClass: 'content', - key: 'admin.navbar.blog', - defaultString: 'blog', - path: '/blog' + key: 'admin.navbar.content', + // defaultString: 'content', + path: '/content/' }, add: { name: 'New Post', navClass: 'editor', key: 'admin.navbar.editor', - defaultString: 'editor', - path: '/editor' + // defaultString: 'editor', + path: '/editor/' }, settings: { name: 'Settings', navClass: 'settings', key: 'admin.navbar.settings', - defaultString: 'settings', - path: '/settings' + // defaultString: 'settings', + path: '/settings/' } }; + ghost.doFilter('messWithAdmin', adminNavbar, function() { + console.log('the dofilter hook called in /core/admin/controllers/index.js'); + }); + // TODO - make this a util or helper function setSelected(list, name) { _.each(list, function (item, key) { @@ -114,7 +118,7 @@ .then(function (post) { res.render('editor', { bodyClass: 'editor', - adminNav: setSelected(adminNavbar, 'blog'), + adminNav: setSelected(adminNavbar, 'content'), title: post.get('title'), content: post.get('content') }); @@ -126,12 +130,12 @@ }); } }, - 'blog': function (req, res) { + 'content': function (req, res) { api.posts.browse() .then(function (posts) { - res.render('blog', { + res.render('content', { bodyClass: 'manage', - adminNav: setSelected(adminNavbar, 'blog'), + adminNav: setSelected(adminNavbar, 'content'), posts: posts.toJSON() }); }); diff --git a/core/admin/views/blog.hbs b/core/admin/views/content.hbs similarity index 100% rename from core/admin/views/blog.hbs rename to core/admin/views/content.hbs diff --git a/core/admin/views/partials/navbar.hbs b/core/admin/views/partials/navbar.hbs index c22b5043e61..a4de3e92395 100644 --- a/core/admin/views/partials/navbar.hbs +++ b/core/admin/views/partials/navbar.hbs @@ -1,3 +1,4 @@ + \ No newline at end of file + diff --git a/core/ghost.js b/core/ghost.js index a38c99f0610..8de76d9381c 100644 --- a/core/ghost.js +++ b/core/ghost.js @@ -17,10 +17,10 @@ jsonDataProvider = new JsonDataProvider(), BookshelfDataProvider = require('./shared/models/dataProvider.bookshelf'), bookshelfDataProvider = new BookshelfDataProvider(), + ExampleFilter = require('../content/plugins/exampleFilters'), Ghost, - instance, - filterCallbacks = {}, + instance, statuses; // ## Article Statuses @@ -45,10 +45,12 @@ Ghost = function () { var app, globals, + plugin, polyglot; if (!instance) { instance = this; + plugin = new ExampleFilter(instance).init(); // Temporary loading of settings jsonDataProvider.globals.findAll(function (error, data) { @@ -70,6 +72,7 @@ dataProvider: function () { return bookshelfDataProvider; }, statuses: function () { return statuses; }, polyglot: function () { return polyglot; }, + plugin: function() { return plugin; }, paths: function () { return { 'activeTheme': __dirname + '/../content/' + config.themeDir + '/' + config.activeTheme + '/', @@ -79,10 +82,21 @@ } }); } - return instance; }; + /** + * Holds the filters + * @type {Array} + */ + Ghost.prototype.filterCallbacks = []; + + /** + * Holds the filter hooks (that are built in to Ghost Core) + * @type {Array} + */ + Ghost.prototype.filters = []; + /** * @param {string} name * @param {Function} fn @@ -115,11 +129,11 @@ * @param {Function} fn */ Ghost.prototype.registerFilter = function (name, fn) { - if (!filterCallbacks.hasOwnProperty(name)) { - filterCallbacks[name] = []; + if (!this.filterCallbacks.hasOwnProperty(name)) { + this.filterCallbacks[name] = []; } console.log('registering filter for ', name); - filterCallbacks[name].push(fn); + this.filterCallbacks[name].push(fn); }; /** @@ -131,11 +145,11 @@ Ghost.prototype.doFilter = function (name, args, callback) { var fn; - if (filterCallbacks.hasOwnProperty(name)) { - for (fn in filterCallbacks[name]) { - if (filterCallbacks[name].hasOwnProperty(fn)) { + if (this.filterCallbacks.hasOwnProperty(name)) { + for (fn in this.filterCallbacks[name]) { + if (this.filterCallbacks[name].hasOwnProperty(fn)) { console.log('doing filter for ', name); - args = filterCallbacks[name][fn](args); + args = this.filterCallbacks[name][fn](args); } } }