From daff9c10f30b4d212e22d8e1c0cbd5d38697776a Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 3 Aug 2012 15:09:48 +0100 Subject: [PATCH] Tighten terminology for plugins vs. modules "Plugins" are bundles of tiddlers managed as one, "modules" are JavaScript tiddlers with a module type identifying when and how they should be executed. --- core/boot.js | 111 +++++++++--------- core/modules/commander.js | 2 +- core/modules/commands/dump.js | 12 +- core/modules/deserializers.js | 2 +- core/modules/macros/edit/edit.js | 2 +- .../macros/edit/editors/bitmapeditor.js | 2 +- .../modules/macros/edit/editors/texteditor.js | 2 +- core/modules/macros/story/story.js | 4 +- .../newwikitextparser/newwikitextparser.js | 2 +- core/modules/recipe.js | 2 +- core/modules/serializers.js | 2 +- core/modules/startup.js | 24 ++-- core/modules/tiddler.js | 8 +- core/modules/utils/dom/popup.js | 2 +- core/modules/utils/dom/scroller.js | 2 +- core/modules/wiki.js | 22 ++-- core/templates/tiddlywiki5.template.html.tid | 2 +- 17 files changed, 100 insertions(+), 103 deletions(-) diff --git a/core/boot.js b/core/boot.js index 5f389d309..d7085b390 100644 --- a/core/boot.js +++ b/core/boot.js @@ -3,7 +3,7 @@ title: $:/core/boot.js type: application/javascript The main boot kernel for TiddlyWiki. This single file creates a barebones TW environment that is just -sufficient to bootstrap the plugins containing the main logic of the applicaiton. +sufficient to bootstrap the modules containing the main logic of the applicaiton. On the server this file is executed directly to boot TiddlyWiki. In the browser, this file is packed into a single HTML file along with other elements: @@ -63,10 +63,7 @@ if(!$tw.browser) { // Modules store registers all the modules the system has seen $tw.modules = $tw.modules || {}; $tw.modules.titles = $tw.modules.titles || {}; // hashmap by module title of {fn:, exports:, moduleType:} - -// Plugins store organises module exports by module type -$tw.plugins = $tw.plugins || {}; -$tw.plugins.moduleTypes = $tw.plugins.moduleTypes || {}; // hashmap by module type of array of exports +$tw.modules.types = $tw.modules.types || {}; // hashmap by module type of array of exports // Config object $tw.config = $tw.config || {}; @@ -228,50 +225,50 @@ $tw.utils.resolvePath = function(sourcepath,rootpath) { } }; -/////////////////////////// Plugin mechanism +/////////////////////////// Module mechanism /* -Register a single plugin module in the $tw.plugins.moduleTypes hashmap +Register a single module in the $tw.modules.types hashmap */ -$tw.plugins.registerPlugin = function(name,moduleType,moduleExports) { - if(!(moduleType in $tw.plugins.moduleTypes)) { - $tw.plugins.moduleTypes[moduleType] = []; +$tw.modules.registerTypedModule = function(name,moduleType,moduleExports) { + if(!(moduleType in $tw.modules.types)) { + $tw.modules.types[moduleType] = []; } - $tw.plugins.moduleTypes[moduleType].push(moduleExports); + $tw.modules.types[moduleType].push(moduleExports); }; /* -Register all plugin module tiddlers +Register all the module tiddlers that have a module type */ -$tw.plugins.registerPluginModules = function() { +$tw.modules.registerTypedModules = function() { for(var title in $tw.wiki.tiddlers) { var tiddler = $tw.wiki.getTiddler(title); if(tiddler.fields.type === "application/javascript" && tiddler.fields["module-type"] !== undefined) { - $tw.plugins.registerPlugin(title,tiddler.fields["module-type"],$tw.modules.execute(title)); + $tw.modules.registerTypedModule(title,tiddler.fields["module-type"],$tw.modules.execute(title)); } } }; /* -Get all the plugins of a particular type in a hashmap by their `name` field +Get all the modules of a particular type in a hashmap by their `name` field */ -$tw.plugins.getPluginsByTypeAsHashmap = function(moduleType,nameField) { +$tw.modules.getModulesByTypeAsHashmap = function(moduleType,nameField) { nameField = nameField || "name"; - var plugins = $tw.plugins.moduleTypes[moduleType], + var modules = $tw.modules.types[moduleType], results = {}; - if(plugins) { - for(var t=0; t 1) { @@ -441,14 +438,14 @@ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/tid"," return [fields]; } }); -$tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/txt","tiddlerdeserializer",{ +$tw.modules.registerTypedModule($tw.config.root + "/kernel/tiddlerdeserializer/txt","tiddlerdeserializer",{ "text/plain": function(text,fields) { fields.text = text; fields.type = "text/plain"; return [fields]; } }); -$tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/html","tiddlerdeserializer",{ +$tw.modules.registerTypedModule($tw.config.root + "/kernel/tiddlerdeserializer/html","tiddlerdeserializer",{ "text/html": function(text,fields) { fields.text = text; fields.type = "text/html"; @@ -456,8 +453,8 @@ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/html", } }); -// Install the tiddler deserializer plugins so they are immediately available -$tw.plugins.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerPlugins); +// Install the tiddler deserializer modules so they are immediately available +$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules); /////////////////////////// Intermediate initialisation @@ -495,7 +492,7 @@ $tw.modules.execute = function(moduleName,moduleRoot) { /* Register a deserializer that can extract tiddlers from the DOM */ -$tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/dom","tiddlerdeserializer",{ +$tw.modules.registerTypedModule($tw.config.root + "/kernel/tiddlerdeserializer/dom","tiddlerdeserializer",{ "(DOM)": function(node) { var extractTextTiddler = function(node) { var e = node.firstChild; @@ -549,12 +546,12 @@ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/dom"," return tiddlers; } }); -// Install the tiddler deserializer plugin -$tw.plugins.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerPlugins); +// Install the tiddler deserializer modules +$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules); // Load the JavaScript system tiddlers from the DOM $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("libraryModules")),true); -$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("pluginModules")),true); +$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("modules")),true); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernelPrefix")),true); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernel")),true); // Load the stylesheet tiddlers from the DOM @@ -591,7 +588,7 @@ $tw.loadTiddlersFromFile = function(file,fields,isShadow) { }; /* -Load all the plugins from the plugins directory +Load all the tiddlers from a directory */ $tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp,isShadow) { basetitle = basetitle || "$:/plugins"; @@ -664,7 +661,7 @@ $tw.modules.execute = function(moduleName,moduleRoot) { return module.exports; }; -// Load plugins from the plugins directory +// Load modules from the modules directory $tw.loadTiddlersFromFolder(path.resolve($tw.boot.bootPath,$tw.config.bootModuleSubDir),null,null,true); // Load up the shadow tiddlers in the root of the core directory @@ -684,11 +681,11 @@ $tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiTiddler /////////////////////////// Final initialisation -// Register plugins from the tiddlers we've just loaded -$tw.plugins.registerPluginModules(); +// Register typed modules from the tiddlers we've just loaded +$tw.modules.registerTypedModules(); -// Run any startup plugin modules -var mainModules = $tw.plugins.moduleTypes.startup; +// Run any startup modules +var mainModules = $tw.modules.types.startup; for(var m=0; m> -