Automatically look for modules with root indexes and show those on the index [Close #427]

This commit is contained in:
reality 2013-04-30 19:33:26 +00:00
parent 2afb1c6ba3
commit 3097683e1c
4 changed files with 28 additions and 10 deletions

View File

@ -30,12 +30,12 @@ var pages = function(dbot) {
}, },
// Lists all of the polls // Lists all of the polls
'/polls': function(req, res) { '/poll': function(req, res) {
res.render('polllist', { res.render('polllist', {
'name': dbot.config.name, 'name': dbot.config.name,
'polllist': Object.keys(dbot.db.polls) 'polllist': Object.keys(dbot.db.polls)
}); });
}, }
}; };
return pages; return pages;
}; };

View File

@ -3,7 +3,7 @@ var pages = function(dbot) {
var connections = dbot.instance.connections; var connections = dbot.instance.connections;
return { return {
'/connections': function(req, res) { '/users': function(req, res) {
var connections = Object.keys(dbot.instance.connections); var connections = Object.keys(dbot.instance.connections);
res.render('connections', { 'name': dbot.config.name, 'connections': connections }); res.render('connections', { 'name': dbot.config.name, 'connections': connections });
}, },

View File

@ -9,10 +9,6 @@ var webInterface = function(dbot) {
this.app.use(express.static(this.pub)); this.app.use(express.static(this.pub));
this.app.set('view engine', 'jade'); this.app.set('view engine', 'jade');
this.app.get('/', function(req, res) {
res.render('index', { 'name': dbot.config.name });
});
var server = this.app.listen(dbot.config.web.webPort); var server = this.app.listen(dbot.config.web.webPort);
this.reloadPages = function() { this.reloadPages = function() {
@ -35,6 +31,29 @@ var webInterface = function(dbot) {
} }
}.bind(this); }.bind(this);
this.onLoad = function() {
var routes = _.pluck(dbot.modules.web.app.routes.get, 'path');
var moduleNames = _.keys(dbot.modules);
var indexModules = [];
_.each(moduleNames, function(moduleName) {
var modulePath = '/' + moduleName;
if(_.include(routes, modulePath)) {
indexModules.push(moduleName);
}
});
console.log(indexModules);
// TODO: get list of loaded modules
this.app.get('/', function(req, res) {
res.render('index', {
'name': dbot.config.name,
'routes': indexModules
});
});
}.bind(this);
this.onDestroy = function() { this.onDestroy = function() {
server.close(); server.close();
}; };

View File

@ -2,6 +2,5 @@ extends layout
block content block content
#modulelinks #modulelinks
a.module(href='/quotes') Quotes - for(var i=0;i<routes.length;i++)
a.module(href='/polls') Polls a.module(href='/'+routes[i]) #{routes[i]}
a.module(href='/connections') Users