From a95c83628df2f453465c6a9b23a8340f82b9676c Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 31 Aug 2012 17:25:18 +0100 Subject: [PATCH] Now got exploded plugins working on the server --- core/boot.js | 32 +++++++++++++++++++---- core/plugins/zoomigator/tiddlywiki.plugin | 8 +----- core/plugins/zoomigator/zoomigator.js | 2 +- core/templates/PageTemplate.tid | 2 -- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/core/boot.js b/core/boot.js index 48a8a1073..5ae1e1528 100644 --- a/core/boot.js +++ b/core/boot.js @@ -651,7 +651,7 @@ $tw.extractTiddlersFromFile = function(filepath,fields) { /* Load all the tiddlers from a directory */ -$tw.extractTiddlersFromFolder = function(filepath,basetitle,excludeRegExp) { +$tw.extractTiddlersFromPath = function(filepath,basetitle,excludeRegExp) { basetitle = basetitle || "$:/plugins"; excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/; var tiddlers = []; @@ -661,8 +661,29 @@ $tw.extractTiddlersFromFolder = function(filepath,basetitle,excludeRegExp) { var files = fs.readdirSync(filepath); // Look for a tiddlywiki.plugin file if(files.indexOf("tiddlywiki.plugin") !== -1) { + // Read the plugin information var pluginInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.plugin").toString("utf8")); - tiddlers.push(new $tw.Tiddler({title: pluginInfo.title, type: "application/json", plugin: "yes", text: JSON.stringify(pluginInfo)})); + // Read the plugin files + var pluginTiddlers = []; + for(var f=0; f titlePrefix.length) { + pluginInfo.tiddlers[pluginTiddlers[t].title.substr(titlePrefix.length)] = pluginTiddlers[t]; + } else { + throw "The plugin '" + pluginInfo.title + "' cannot contain a tiddler titled '" + pluginTiddlers[t].title + "'"; + } + } + // Save the plugin tiddler + tiddlers.push({title: pluginInfo.title, type: "application/json", plugin: "yes", text: JSON.stringify(pluginInfo)}); // Look for a tiddlywiki.files file } else if(files.indexOf("tiddlywiki.files") !== -1) { // If so, process the files it describes @@ -671,14 +692,15 @@ $tw.extractTiddlersFromFolder = function(filepath,basetitle,excludeRegExp) { var tidInfo = filesInfo.tiddlers[p], typeInfo = $tw.config.contentTypeInfo[tidInfo.fields.type || "text/plain"], text = fs.readFileSync(path.resolve(filepath,tidInfo.file)).toString(typeInfo ? typeInfo.encoding : "utf8"); - tiddlers.push(new $tw.Tiddler({text: text},tidInfo.fields)); + tidInfo.fields.text = text; + tiddlers.push(tidInfo.fields); } } else { // If not, read all the files in the directory for(var f=0; f=5.0.0", - "source": "http://tiddlywiki.com/core/plugins/zoomigator", - "tiddlers": { - "Test1": {"text": "Some text"}, - "Test2": {"text": "Some more text"}, - "Test3": {"text": "console.log(require('$:/plugins/tiddlywiki/zoomigator/Test4').string);", "type": "application/javascript", "module-type": "custom"}, - "Test4": {"text": "exports.string = 'Plugin I am still in You!';", "type": "application/javascript", "module-type": "custom"} - } + "source": "http://tiddlywiki.com/core/plugins/zoomigator" } diff --git a/core/plugins/zoomigator/zoomigator.js b/core/plugins/zoomigator/zoomigator.js index a8fae4355..e0dab981c 100644 --- a/core/plugins/zoomigator/zoomigator.js +++ b/core/plugins/zoomigator/zoomigator.js @@ -1,5 +1,5 @@ /*\ -title: $:/core/plugins/zoomigator/zoomigator.js +title: $:/plugins/tiddlywiki/zoomigator/zoomigator.js type: application/javascript module-type: macro diff --git a/core/templates/PageTemplate.tid b/core/templates/PageTemplate.tid index 4b8041971..3adc2d491 100644 --- a/core/templates/PageTemplate.tid +++ b/core/templates/PageTemplate.tid @@ -11,9 +11,7 @@ title: $:/templates/PageTemplate }}} -