From 0a3d1b6f9e9914e23aebe3e2248fdfd0330a003a Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 15 Jan 2013 13:58:13 +0000 Subject: [PATCH] Fixed web loading and hot refresh of pages [#131] --- modules/users/{web.js => pages.js} | 2 +- modules/web/web.js | 26 ++++++++++++-------------- run.js | 13 ++----------- 3 files changed, 15 insertions(+), 26 deletions(-) rename modules/users/{web.js => pages.js} (99%) diff --git a/modules/users/web.js b/modules/users/pages.js similarity index 99% rename from modules/users/web.js rename to modules/users/pages.js index 4ea2e8a..015d7ba 100644 --- a/modules/users/web.js +++ b/modules/users/pages.js @@ -103,6 +103,6 @@ var pages = function(dbot) { }; }; -exports.getPages = function(dbot) { +exports.fetch = function(dbot) { return pages(dbot); }; diff --git a/modules/web/web.js b/modules/web/web.js index b3e632b..2bc7b28 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -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); }; diff --git a/run.js b/run.js index df3279e..156ba3b 100644 --- a/run.js +++ b/run.js @@ -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("_")) {