1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-18 11:29:55 +00:00

Added support for plugins in the wiki directory

This commit is contained in:
Jeremy Ruston 2012-05-04 18:24:54 +01:00
parent 6b39ce10d0
commit afc4824307
4 changed files with 35 additions and 12 deletions

View File

@ -51,7 +51,8 @@ $tw.config = $tw.config || {};
// Constants // Constants
$tw.config.root = $tw.config.root || "$:"; // Root for module titles (eg, "$:/kernel/boot.js") $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 // File extensions
$tw.config.fileExtensions = { $tw.config.fileExtensions = {
@ -549,17 +550,19 @@ Load all the plugins from the plugins directory
$tw.plugins.loadPlugins = function(filepath,basetitle,excludeRegExp) { $tw.plugins.loadPlugins = function(filepath,basetitle,excludeRegExp) {
basetitle = basetitle || "$:/plugins"; basetitle = basetitle || "$:/plugins";
excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/; excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/;
var stat = fs.statSync(filepath); if(path.existsSync(filepath)) {
if(stat.isDirectory()) { var stat = fs.statSync(filepath);
var files = fs.readdirSync(filepath); if(stat.isDirectory()) {
for(var f=0; f<files.length; f++) { var files = fs.readdirSync(filepath);
var file = files[f]; for(var f=0; f<files.length; f++) {
if(!excludeRegExp.test(file)) { var file = files[f];
$tw.plugins.loadPlugins(filepath + "/" + file,basetitle + "/" + file,excludeRegExp); 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 // 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) // End of if(!$tw.isBrowser)
} }

View File

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

View File

@ -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";
})();

View File

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