3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

Fixed web loading and hot refresh of pages [#131]

This commit is contained in:
reality 2013-01-15 13:58:13 +00:00
parent b733564cb2
commit 0a3d1b6f9e
3 changed files with 15 additions and 26 deletions

View File

@ -103,6 +103,6 @@ var pages = function(dbot) {
};
};
exports.getPages = function(dbot) {
exports.fetch = function(dbot) {
return pages(dbot);
};

View File

@ -3,6 +3,13 @@ var express = require('express'),
fs = require('fs');
var webInterface = function(dbot) {
this.name = 'web';
this.ignorable = false;
this.onDestroy = function() {
server.close();
}
var pub = 'public';
var app = express();
@ -15,7 +22,8 @@ var webInterface = function(dbot) {
var server = app.listen(dbot.config.web.webPort);
var reloadPages = function(pages) {
this.reloadPages = function() {
var pages = dbot.pages;
for(var p in pages) {
if(_.has(pages, p)) {
var func = pages[p];
@ -25,26 +33,16 @@ var webInterface = function(dbot) {
var shim = Object.create(resp);
shim.render = (function(view, one, two) {
// Render with express.js
resp.render(this.module.name + '/' + view, one, two);
resp.render(this.module + '/' + view, one, two);
}).bind(this);
shim.render_core = resp.render;
this.call(this.module, req, shim);
}).bind(func));
}
}
};
return {
'name': 'web',
'ignorable': false,
'reloadPages': reloadPages,
'onDestroy': function() {
server.close();
}
};
}.bind(this);
};
exports.fetch = function(dbot) {
return webInterface(dbot);
return new webInterface(dbot);
};

13
run.js
View File

@ -244,20 +244,11 @@ DBot.prototype.reloadModules = function() {
}
}.bind(this));
this.reloadPages();
if(_.has(this.modules, 'web')) this.modules.web.reloadPages();
this.save();
};
// I honestly don't know what the fuck this is meant to do. Why is it getting a
// reference to all the pages?
DBot.prototype.reloadPages = function() {
_.each(this.modules, function(module) {
if(_.isFunction(module.reloadPages)) {
module.reloadPages(this.pages);
}
}, this);
}
DBot.prototype.cleanNick = function(key) {
key = key.toLowerCase();
while(key.endsWith("_")) {