diff options
author | portix <none@none> | 2012-05-02 20:06:51 +0200 |
---|---|---|
committer | portix <none@none> | 2012-05-02 20:06:51 +0200 |
commit | f82e11efaa6f0177e8d31d878448ec8afd302330 (patch) | |
tree | 666869699a5892bc8d125e7611e4374713fd47b9 /scripts | |
parent | 4a83cf45d08284896b9dc96eb383226a6669552c (diff) | |
download | dwb-f82e11efaa6f0177e8d31d878448ec8afd302330.zip |
Make extension.config private
--HG--
branch : scripts
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/extensions.js | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/scripts/lib/extensions.js b/scripts/lib/extensions.js index e96ab7bd..b713c45f 100644 --- a/scripts/lib/extensions.js +++ b/scripts/lib/extensions.js @@ -1,7 +1,4 @@ Object.defineProperties(extensions, { - "config" : { - value : undefined - }, "warning" : { value : function (name, message) { io.print("\033[1mDWB EXTENSION WARNING: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr"); @@ -18,51 +15,52 @@ Object.defineProperties(extensions, { } }, "load" : { - value : function (name) { - var boldname = "\033[1m" + name + "\033[0m"; + value : (function () { + var _config = undefined; + return function(name) { + var boldname = "\033[1m" + name + "\033[0m"; - var config, dataBase, pluginPath, plugin; - var extConfig = null; + var config, dataBase, pluginPath, plugin; + var extConfig = null; - /* Get default config if the config hasn't been read yet */ - if (extensions._config === undefined) { - try { - config = include(data.configDir + "/extensionrc"); - } - catch (e) { - extensions.error(name, "loading config failed : " + e); + /* Get default config if the config hasn't been read yet */ + if (_config === undefined) { + try { + config = include(data.configDir + "/extensionrc"); + } + catch (e) { + extensions.error(name, "loading config failed : " + e); + } + if (config === null) { + extensions.warning(name, "Could not load config."); + } + else { + _config = config; + } } - if (config === null) { - extensions.warning(name, "Could not load config."); + if (_config) { + extConfig = _config[name] || null; } - else { - Object.defineProperty(extensions, "_config", { - value : config - }); - } - } - if (extensions._config) { - extConfig = extensions._config[name] || null; - } - /* Load extension */ - plugin = include(data.userDataDir + "/extensions/" + name); - if (plugin === null) { - plugin = include(data.systemDataDir + "/extensions/" + name); + /* Load extension */ + plugin = include(data.userDataDir + "/extensions/" + name); if (plugin === null) { - extensions.error(name, "Couldn't find extension."); + plugin = include(data.systemDataDir + "/extensions/" + name); + if (plugin === null) { + extensions.error(name, "Couldn't find extension."); + return false; + } + + } + if (plugin.init(extConfig)) { + extensions.message(name, "Successfully loaded and initialized."); + return true; + } + else { + extensions.error(name, "Initialization failed."); return false; } - - } - if (plugin.init(extConfig)) { - extensions.message(name, "Successfully loaded and initialized."); - return true; - } - else { - extensions.error(name, "Initialization failed."); - return false; - } - } + }; + })() } }); |