Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#25: admin navbar bits #88

Merged
merged 1 commit into from
May 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
I18n = require('./core/lang/i18n'),
helpers = require('./core/frontend/helpers'),



// ## Variables
auth,
authAPI,
Expand All @@ -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 }));
Expand All @@ -41,6 +44,10 @@
});
});





/**
* Setup login details
* p.s. love it.
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -114,5 +121,6 @@

ghost.app().listen(3333, function () {
console.log("Express server listening on port " + 3333);

});
}());
27 changes: 27 additions & 0 deletions content/plugins/exampleFilters.js
Original file line number Diff line number Diff line change
@@ -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;

}());
3 changes: 3 additions & 0 deletions content/plugins/fancyFirstChar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
return ghost;
};
};

FancyFirstChar.prototype.init = function () {
this.ghost().registerFilter('prePostsRender', function (posts) {
var post,
Expand Down Expand Up @@ -41,5 +42,7 @@
FancyFirstChar.prototype.activate = function () {};
FancyFirstChar.prototype.deactivate = function () {};



module.exports = FancyFirstChar;
}());
32 changes: 18 additions & 14 deletions core/admin/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')
});
Expand All @@ -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()
});
});
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion core/admin/views/partials/navbar.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<header id="global-header" class="navbar">
<a id="ghost" href="#" data-off-canvas="left"><span class="hidden">Ghost</span></a>
<nav id="global-nav" role="navigation">
Expand All @@ -22,4 +23,4 @@
</li>
</ul>
</nav>
</header>
</header>
34 changes: 24 additions & 10 deletions core/ghost.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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 + '/',
Expand All @@ -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
Expand Down Expand Up @@ -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);
};

/**
Expand All @@ -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);
}
}
}
Expand Down