aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranekos2008-11-07 11:35:01 +0000
committeranekos2008-11-07 11:35:01 +0000
commit5b829e24b4aae22f34799e7ce359952aac60b93a (patch)
tree1d0d76c96e81225faf7a0cfd003d326c85360cda
parentd5805a16329e7477e5605cdbf957d5086a53b86e (diff)
downloadvimperator-plugins-5b829e24b4aae22f34799e7ce359952aac60b93a.tar.bz2
added
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/branches/1.2@22946 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r--plugin_loader.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/plugin_loader.js b/plugin_loader.js
new file mode 100644
index 0000000..0350332
--- /dev/null
+++ b/plugin_loader.js
@@ -0,0 +1,49 @@
+// ==VimperatorPlugin==
+// @name Plugin Loader
+// @description to load plugins from specified directory at starting up Vimperator.
+// @description-ja 指定(ディレクトリ|プラグイン)を起動時にロードする
+// @license Creative Commons 2.1 (Attribution + Share Alike)
+// @version 2.3
+// @minVersion 1.2
+// @maxVersion 2.0Pre
+// @author anekos
+// ==/VimperatorPlugin==
+//
+// Usage:
+// let g:plugin_loader_roots = "<PLUGIN_DIRECTORIES>"
+// let g:plugin_loader_plugins = "<PLUGIN_NAMES>"
+//
+// Example:
+// let g:plugin_loader_roots = "/home/anekos/coderepos/vimp-plugins/ /home/anekos/my-vimp-plugins/"
+// let g:plugin_loader_plugins = "lo,migemized_find,nico_related_videos"
+//
+// Link:
+// http://d.hatena.ne.jp/nokturnalmortum/20081008#1223397705
+
+{
+ function toArray (obj) {
+ return obj instanceof Array ? obj
+ : obj.toString().split(/[,| \t\r\n]+/);
+ }
+
+ let roots = toArray(liberator.globalVariables.plugin_loader_roots);
+ let plugins = toArray(liberator.globalVariables.plugin_loader_plugins);
+ let filter = new RegExp('[\\\\/](?:' +
+ plugins.map(function (plugin) plugin.replace(/(?=[\\^$.+*?|(){}\[\]])/g, '\\'))
+ .join('|') +
+ ')\\.(?:js|vimp)$');
+
+ liberator.log('plugin_loader: loading');
+
+ roots.forEach(function (root) {
+ let files = io.readDirectory(io.getFile(root), true);
+ files.forEach(function (file) {
+ if (filter.test(file.path)) {
+ liberator.log("Sourcing: " + file.path);
+ io.source(file.path, false);
+ }
+ });
+ });
+
+ liberator.log('plugin_loader: loaded');
+}