1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Stop using the term "bundle" to describe plugins

This commit is contained in:
Jeremy Ruston 2013-03-23 16:34:12 +00:00
parent c5bdf5f28e
commit 25e56c2ade
8 changed files with 47 additions and 47 deletions

View File

@ -518,8 +518,8 @@ Construct a wiki store object
*/ */
$tw.Wiki = function() { $tw.Wiki = function() {
this.tiddlers = {}; this.tiddlers = {};
this.bundles = {}; // Hashmap of plugin information by title this.plugins = {}; // Hashmap of plugin information by title
this.bundledTiddlers = {}; // Hashmap of constituent tiddlers from plugins by title this.pluginTiddlers = {}; // Hashmap of constituent tiddlers from plugins by title
}; };
$tw.Wiki.prototype.addTiddler = function(tiddler) { $tw.Wiki.prototype.addTiddler = function(tiddler) {
@ -536,23 +536,23 @@ $tw.Wiki.prototype.addTiddlers = function(tiddlers) {
}; };
/* /*
Extract constituent tiddlers from bundle tiddlers so that we can easily access them in getTiddler() Extract constituent tiddlers from plugin tiddlers so that we can easily access them in getTiddler()
*/ */
$tw.Wiki.prototype.unpackBundleTiddlers = function() { $tw.Wiki.prototype.unpackPluginTiddlers = function() {
// Collect up all the plugin tiddlers // Collect up all the plugin tiddlers
var self = this; var self = this;
$tw.utils.each(this.tiddlers,function(tiddler,title,object) { $tw.utils.each(this.tiddlers,function(tiddler,title,object) {
if(tiddler.fields.type === "application/json" && tiddler.hasField("bundle")) { if(tiddler.fields.type === "application/json" && tiddler.hasField("plugin")) {
// Save the bundle information // Save the plugin information
var bundleInfo = self.bundles[title] = JSON.parse(tiddler.fields.text); var pluginInfo = self.plugins[title] = JSON.parse(tiddler.fields.text);
// Extract the constituent tiddlers // Extract the constituent tiddlers
for(var t in bundleInfo.tiddlers) { for(var t in pluginInfo.tiddlers) {
var constituentTiddler = bundleInfo.tiddlers[t], var constituentTiddler = pluginInfo.tiddlers[t],
constituentTitle = bundleInfo.title + "/" + t; constituentTitle = pluginInfo.title + "/" + t;
// Don't overwrite tiddlers that already exist // Don't overwrite tiddlers that already exist
if(!$tw.utils.hop(self.bundledTiddlers,constituentTitle)) { if(!$tw.utils.hop(self.pluginTiddlers,constituentTitle)) {
// Save the tiddler object // Save the tiddler object
self.bundledTiddlers[constituentTitle] = new $tw.Tiddler(constituentTiddler,{title: constituentTitle}); self.pluginTiddlers[constituentTitle] = new $tw.Tiddler(constituentTiddler,{title: constituentTitle});
} }
} }
} }
@ -586,9 +586,9 @@ $tw.Wiki.prototype.defineTiddlerModules = function() {
/* /*
Register all the module tiddlers that have a module type Register all the module tiddlers that have a module type
*/ */
$tw.Wiki.prototype.defineBundledModules = function() { $tw.Wiki.prototype.definePluginModules = function() {
var self = this; var self = this;
$tw.utils.each(this.bundledTiddlers,function(element,title,object) { $tw.utils.each(this.pluginTiddlers,function(element,title,object) {
var tiddler = self.getTiddler(title); var tiddler = self.getTiddler(title);
if(!$tw.utils.hop(self.tiddlers,title)) { // Don't define the module if it is overidden by an ordinary tiddler if(!$tw.utils.hop(self.tiddlers,title)) { // Don't define the module if it is overidden by an ordinary tiddler
if(tiddler.fields.type === "application/javascript" && tiddler.hasField("module-type")) { if(tiddler.fields.type === "application/javascript" && tiddler.hasField("module-type")) {
@ -603,8 +603,8 @@ $tw.Wiki.prototype.getTiddler = function(title) {
var t = this.tiddlers[title]; var t = this.tiddlers[title];
if(t instanceof $tw.Tiddler) { if(t instanceof $tw.Tiddler) {
return t; return t;
} else if($tw.utils.hop(this.bundledTiddlers,title)) { } else if($tw.utils.hop(this.pluginTiddlers,title)) {
return this.bundledTiddlers[title]; return this.pluginTiddlers[title];
} else { } else {
return undefined; return undefined;
} }
@ -951,43 +951,43 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) {
}; };
/* /*
Load the tiddlers from a bundle folder, and package them up into a proper JSON bundle tiddler Load the tiddlers from a plugin folder, and package them up into a proper JSON plugin tiddler
*/ */
$tw.loadBundleFolder = function(filepath,excludeRegExp) { $tw.loadPluginFolder = function(filepath,excludeRegExp) {
excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/; excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/;
var stat, files, bundleInfo, bundleTiddlers = [], f, file, titlePrefix, t; var stat, files, pluginInfo, pluginTiddlers = [], f, file, titlePrefix, t;
if(fs.existsSync(filepath)) { if(fs.existsSync(filepath)) {
stat = fs.statSync(filepath); stat = fs.statSync(filepath);
if(stat.isDirectory()) { if(stat.isDirectory()) {
files = fs.readdirSync(filepath); files = fs.readdirSync(filepath);
// Read the plugin information // Read the plugin information
bundleInfo = JSON.parse(fs.readFileSync(filepath + "/plugin.bundle","utf8")); pluginInfo = JSON.parse(fs.readFileSync(filepath + "/plugin.info","utf8"));
// Read the bundle files // Read the plugin files
for(f=0; f<files.length; f++) { for(f=0; f<files.length; f++) {
file = files[f]; file = files[f];
if(!excludeRegExp.test(file) && file !== "plugin.bundle" && file !== "tiddlywiki.files") { if(!excludeRegExp.test(file) && file !== "plugin.info" && file !== "tiddlywiki.files") {
bundleTiddlers.push.apply(bundleTiddlers,$tw.loadTiddlersFromPath(filepath + "/" + file,excludeRegExp)); pluginTiddlers.push.apply(pluginTiddlers,$tw.loadTiddlersFromPath(filepath + "/" + file,excludeRegExp));
} }
} }
// Save the bundle tiddlers into the bundle // Save the plugin tiddlers into the plugin info
bundleInfo.tiddlers = bundleInfo.tiddlers || {}; pluginInfo.tiddlers = pluginInfo.tiddlers || {};
titlePrefix = bundleInfo.title + "/"; titlePrefix = pluginInfo.title + "/";
for(t=0; t<bundleTiddlers.length; t++) { for(t=0; t<pluginTiddlers.length; t++) {
// Check that the constituent tiddler has the bundle title as a prefix // Check that the constituent tiddler has the plugin title as a prefix
if(bundleTiddlers[t].title.indexOf(titlePrefix) === 0 && bundleTiddlers[t].title.length > titlePrefix.length) { if(pluginTiddlers[t].title.indexOf(titlePrefix) === 0 && pluginTiddlers[t].title.length > titlePrefix.length) {
bundleInfo.tiddlers[bundleTiddlers[t].title.substr(titlePrefix.length)] = bundleTiddlers[t]; pluginInfo.tiddlers[pluginTiddlers[t].title.substr(titlePrefix.length)] = pluginTiddlers[t];
} else { } else {
console.log("Error extracting plugin bundle: The bundle '" + bundleInfo.title + "' cannot contain a tiddler titled '" + bundleTiddlers[t].title + "'"); console.log("Error extracting plugin: The plugin '" + pluginInfo.title + "' cannot contain a tiddler titled '" + pluginTiddlers[t].title + "'");
} }
} }
} }
} }
// Save the bundle tiddler // Save the plugin tiddler
return bundleInfo ? { return pluginInfo ? {
title: bundleInfo.title, title: pluginInfo.title,
type: "application/json", type: "application/json",
bundle: "yes", plugin: "yes",
text: JSON.stringify(bundleInfo,null,4) text: JSON.stringify(pluginInfo,null,4)
} : null; } : null;
}; };
@ -1002,14 +1002,14 @@ $tw.loadTiddlers = function() {
} }
// Load any plugins listed in the wiki info file // Load any plugins listed in the wiki info file
var wikiInfoPath = path.resolve($tw.boot.wikiPath,$tw.config.wikiInfo), var wikiInfoPath = path.resolve($tw.boot.wikiPath,$tw.config.wikiInfo),
bundle; pluginFields;
if(fs.existsSync(wikiInfoPath)) { if(fs.existsSync(wikiInfoPath)) {
var wikiInfo = JSON.parse(fs.readFileSync(wikiInfoPath,"utf8")), var wikiInfo = JSON.parse(fs.readFileSync(wikiInfoPath,"utf8")),
pluginBasePath = path.resolve($tw.boot.bootPath,$tw.config.pluginsPath); pluginBasePath = path.resolve($tw.boot.bootPath,$tw.config.pluginsPath);
for(t=0; t<wikiInfo.plugins.length; t++) { for(t=0; t<wikiInfo.plugins.length; t++) {
bundle = $tw.loadBundleFolder(path.resolve(pluginBasePath,"./" + wikiInfo.plugins[t])); pluginFields = $tw.loadPluginFolder(path.resolve(pluginBasePath,"./" + wikiInfo.plugins[t]));
if(bundle) { if(pluginFields) {
$tw.wiki.addTiddler(bundle); $tw.wiki.addTiddler(pluginFields);
} }
} }
} }
@ -1018,9 +1018,9 @@ $tw.loadTiddlers = function() {
if(fs.existsSync(wikiPluginsPath)) { if(fs.existsSync(wikiPluginsPath)) {
var pluginFolders = fs.readdirSync(wikiPluginsPath); var pluginFolders = fs.readdirSync(wikiPluginsPath);
for(t=0; t<pluginFolders.length; t++) { for(t=0; t<pluginFolders.length; t++) {
bundle = $tw.loadBundleFolder(path.resolve(wikiPluginsPath,"./" + pluginFolders[t])); pluginFields = $tw.loadPluginFolder(path.resolve(wikiPluginsPath,"./" + pluginFolders[t]));
if(bundle) { if(pluginFields) {
$tw.wiki.addTiddler(bundle); $tw.wiki.addTiddler(pluginFields);
} }
} }
} }
@ -1092,12 +1092,12 @@ $tw.boot.startup = function() {
$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules); $tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules);
// Load tiddlers // Load tiddlers
$tw.loadTiddlers(); $tw.loadTiddlers();
// Unpack bundle tiddlers // Unpack plugin tiddlers
$tw.wiki.unpackBundleTiddlers(); $tw.wiki.unpackPluginTiddlers();
// Register typed modules from the tiddlers we've just loaded // Register typed modules from the tiddlers we've just loaded
$tw.wiki.defineTiddlerModules(); $tw.wiki.defineTiddlerModules();
// And any modules within bundles // And any modules within plugins
$tw.wiki.defineBundledModules(); $tw.wiki.definePluginModules();
// Make sure the crypto state tiddler is up to date // Make sure the crypto state tiddler is up to date
$tw.crypto.updateCryptoStateTiddler(); $tw.crypto.updateCryptoStateTiddler();
// Run any startup modules // Run any startup modules