Added support for plugins in the wiki directory

print-window-tiddler
Jeremy Ruston 2012-05-04 18:24:54 +01:00
rodzic 6b39ce10d0
commit afc4824307
4 zmienionych plików z 35 dodań i 12 usunięć

Wyświetl plik

@ -51,7 +51,8 @@ $tw.config = $tw.config || {};
// Constants
$tw.config.root = $tw.config.root || "$:"; // Root for module titles (eg, "$:/kernel/boot.js")
$tw.config.moduleSubDir = $tw.config.moduleSubDir || "./modules";
$tw.config.bootModuleSubDir = $tw.config.bootModuleSubDir || "./modules";
$tw.config.wikiPluginsSubDir = $tw.config.wikiPluginsSubDir || "./plugins";
// File extensions
$tw.config.fileExtensions = {
@ -549,17 +550,19 @@ Load all the plugins from the plugins directory
$tw.plugins.loadPlugins = function(filepath,basetitle,excludeRegExp) {
basetitle = basetitle || "$:/plugins";
excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/;
var stat = fs.statSync(filepath);
if(stat.isDirectory()) {
var files = fs.readdirSync(filepath);
for(var f=0; f<files.length; f++) {
var file = files[f];
if(!excludeRegExp.test(file)) {
$tw.plugins.loadPlugins(filepath + "/" + file,basetitle + "/" + file,excludeRegExp);
if(path.existsSync(filepath)) {
var stat = fs.statSync(filepath);
if(stat.isDirectory()) {
var files = fs.readdirSync(filepath);
for(var f=0; f<files.length; f++) {
var file = files[f];
if(!excludeRegExp.test(file)) {
$tw.plugins.loadPlugins(filepath + "/" + file,basetitle + "/" + file,excludeRegExp);
}
}
} else if(stat.isFile()) {
$tw.plugins.loadTiddlersFromFile(filepath,basetitle);
}
} else if(stat.isFile()) {
$tw.plugins.loadTiddlersFromFile(filepath,basetitle);
}
}
@ -599,7 +602,10 @@ $tw.modules.execute = function(moduleName,moduleRoot) {
}
// Load plugins from the plugins directory
$tw.plugins.loadPlugins(path.resolve($tw.boot.bootPath,$tw.config.moduleSubDir));
$tw.plugins.loadPlugins(path.resolve($tw.boot.bootPath,$tw.config.bootModuleSubDir));
// Load any plugins in the wiki plugins directory
$tw.plugins.loadPlugins(require("path").resolve($tw.boot.wikiPath,$tw.config.wikiPluginsSubDir));
// End of if(!$tw.isBrowser)
}

Wyświetl plik

@ -13,7 +13,6 @@ This is the main application logic for both the client and server
exports.startup = function() {
var modules,n,m,f;
// Set up additional global objects
$tw.plugins.applyMethods("global",$tw);
// Wire up plugin modules

Wyświetl plik

@ -0,0 +1,15 @@
/*\
title: $:/tiddlywiki/plugins/demoplugin/demoplugin.js
type: application/javascript
module-type: demo
A demo plugin
\*/
(function(){
/*jslint node: true, browser: true */
"use strict";
})();

Wyświetl plik

@ -8,3 +8,6 @@ shadow: shadows/templates/*.tid
shadow: shadows/tiddlycss/*.tid
#jslib: lib/jquery.js
#jslib: lib/bootstrap/js/bootstrap.js
pluginmodule: plugins/*.js
pluginmodule: plugins/demoplugin/*.js