From f0103348955a6e282ad608228b310035d5a868e9 Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Sat, 13 Mar 2010 11:21:00 +0100 Subject: Made it possible to split out parts of a plugin into separate files --- trunk/etherpad/src/etherpad/admin/plugins.js | 4 +++- trunk/etherpad/src/plugins/testplugin/hooks.js | 15 +++++++++++++++ trunk/etherpad/src/plugins/testplugin/main.js | 26 ++++++++++---------------- 3 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 trunk/etherpad/src/plugins/testplugin/hooks.js (limited to 'trunk/etherpad') diff --git a/trunk/etherpad/src/etherpad/admin/plugins.js b/trunk/etherpad/src/etherpad/admin/plugins.js index 8500acb..3df1ad1 100644 --- a/trunk/etherpad/src/etherpad/admin/plugins.js +++ b/trunk/etherpad/src/etherpad/admin/plugins.js @@ -55,7 +55,9 @@ function loadAvailablePlugin(pluginName) { var pluginModulePath = pluginFile.getPath().replace(new RegExp("src/\(.*\)\.js"), "$1").replace("/", ".", "g"); var importStmt = "import('" + pluginModulePath + "')"; try { - return execution.fancyAssEval(importStmt, "main;"); + var res = execution.fancyAssEval(importStmt, "main;"); + res = new res.init(); + return res; } catch (e) { log.info({errorLoadingPlugin:exceptionutils.getStackTracePlain(e)}); } diff --git a/trunk/etherpad/src/plugins/testplugin/hooks.js b/trunk/etherpad/src/plugins/testplugin/hooks.js new file mode 100644 index 0000000..493a2c2 --- /dev/null +++ b/trunk/etherpad/src/plugins/testplugin/hooks.js @@ -0,0 +1,15 @@ +import("etherpad.log"); +import("dispatch.{Dispatcher,PrefixMatcher,forward}"); +import("plugins.testplugin.controllers.testplugin"); + +function serverStartup() { + log.info("Server startup for testplugin"); +} + +function serverShutdown() { + log.info("Server shutdown for testplugin"); +} + +function handlePath() { + return [[PrefixMatcher('/ep/testplugin/'), forward(testplugin)]]; +} diff --git a/trunk/etherpad/src/plugins/testplugin/main.js b/trunk/etherpad/src/plugins/testplugin/main.js index f5d736b..74a6cfe 100644 --- a/trunk/etherpad/src/plugins/testplugin/main.js +++ b/trunk/etherpad/src/plugins/testplugin/main.js @@ -1,10 +1,15 @@ import("etherpad.log"); -import("etherpad.admin.plugins"); -import("dispatch.{Dispatcher,PrefixMatcher,forward}"); -import("plugins.testplugin.controllers.testplugin"); +import("plugins.testplugin.hooks"); -hooks = ['serverStartup', 'serverShutdown', 'handlePath']; -description = 'Test Plugin'; +function init() { + this.hooks = ['serverStartup', 'serverShutdown', 'handlePath']; + this.description = 'Test Plugin'; + this.serverStartup = hooks.serverStartup; + this.serverShutdown = hooks.serverShutdown; + this.handlePath = hooks.handlePath; + this.install = install; + this.uninstall = uninstall; +} function install() { log.info("Installing testplugin"); @@ -14,14 +19,3 @@ function uninstall() { log.info("Uninstalling testplugin"); } -function serverStartup() { - log.info("Server startup for testplugin"); -} - -function serverShutdown() { - log.info("Server shutdown for testplugin"); -} - -function handlePath() { - return [[PrefixMatcher('/ep/testplugin/'), forward(testplugin)]]; -} \ No newline at end of file -- cgit v1.2.3-1-g7c22