mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-17 03:20:02 +00:00
Fixed problem with plugin precedence
We were unpacking plugin tiddlers in arbitrary order, and ensuring that later plugins didn't overwrite shadow tiddlers from earlier plugins. Now we'll allow plugins to specify a "pluginPriority" that determines the load ordering. We also explicitly allow shadow tiddlers from later plugins to overwrite shadow tiddlers from earlier plugins. We're setting a base priority on the core plugin, since many plugins will want to control their loading relative to it.
This commit is contained in:
parent
6d4768acad
commit
df59269b0d
68
boot/boot.js
68
boot/boot.js
@ -547,25 +547,43 @@ $tw.Wiki.prototype.addTiddlers = function(tiddlers) {
|
||||
Extract constituent tiddlers from plugin tiddlers so that we can easily access them in getTiddler()
|
||||
*/
|
||||
$tw.Wiki.prototype.unpackPluginTiddlers = function() {
|
||||
// Collect up all the plugin tiddlers
|
||||
var self = this;
|
||||
// Collect up the titles of all the plugin tiddlers
|
||||
var self = this,
|
||||
pluginInfoList = [];
|
||||
$tw.utils.each(this.tiddlers,function(tiddler,title,object) {
|
||||
if(tiddler.fields.type === "application/json" && tiddler.hasField("plugin")) {
|
||||
// Save the plugin information
|
||||
var pluginInfo = self.plugins[title] = JSON.parse(tiddler.fields.text);
|
||||
// Extract the constituent tiddlers
|
||||
$tw.utils.each(pluginInfo.tiddlers,function(constituentTiddler,constituentTitle) {
|
||||
// Don't overwrite tiddlers that already exist
|
||||
if(!$tw.utils.hop(self.shadowTiddlers,constituentTitle)) {
|
||||
// Save the tiddler object
|
||||
self.shadowTiddlers[constituentTitle] = {
|
||||
source: title,
|
||||
tiddler: new $tw.Tiddler(constituentTiddler,{title: constituentTitle})
|
||||
};
|
||||
}
|
||||
});
|
||||
pluginInfoList.push(tiddler);
|
||||
}
|
||||
});
|
||||
// Sort the titles by the `pluginPriority` field
|
||||
pluginInfoList.sort(function(a,b) {
|
||||
if("pluginPriority" in a.fields && "pluginPriority" in b.fields) {
|
||||
return a.fields.pluginPriority - b.fields.pluginPriority;
|
||||
} else if("pluginPriority" in a.fields) {
|
||||
return -1;
|
||||
} else if("pluginPriority" in b.fields) {
|
||||
return +1;
|
||||
} else if(a.fields.title < b.fields.title) {
|
||||
return -1;
|
||||
} else if(a.fields.title === b.fields.title) {
|
||||
return 0;
|
||||
} else {
|
||||
return +1;
|
||||
}
|
||||
});
|
||||
// Now go through the plugins in ascending order
|
||||
$tw.utils.each(pluginInfoList,function(tiddler) {
|
||||
// Save the plugin information
|
||||
var pluginInfo = self.plugins[tiddler.fields.title] = JSON.parse(tiddler.fields.text);
|
||||
// Extract the constituent tiddlers
|
||||
$tw.utils.each(pluginInfo.tiddlers,function(constituentTiddler,constituentTitle) {
|
||||
// Save the tiddler object
|
||||
self.shadowTiddlers[constituentTitle] = {
|
||||
source: tiddler.fields.title,
|
||||
tiddler: new $tw.Tiddler(constituentTiddler,{title: constituentTitle})
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
@ -993,12 +1011,20 @@ $tw.loadPluginFolder = function(filepath,excludeRegExp) {
|
||||
}
|
||||
}
|
||||
// Save the plugin tiddler
|
||||
return pluginInfo ? {
|
||||
title: pluginInfo.title,
|
||||
type: "application/json",
|
||||
plugin: "yes",
|
||||
text: JSON.stringify(pluginInfo,null,4)
|
||||
} : null;
|
||||
if(pluginInfo) {
|
||||
var fields = {
|
||||
title: pluginInfo.title,
|
||||
type: "application/json",
|
||||
plugin: "yes",
|
||||
text: JSON.stringify(pluginInfo,null,4)
|
||||
}
|
||||
if("pluginPriority" in pluginInfo) {
|
||||
fields.pluginPriority = pluginInfo.pluginPriority;
|
||||
}
|
||||
return fields;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -3,5 +3,6 @@
|
||||
"description": "TiddlyWiki5 core plugin",
|
||||
"author": "JeremyRuston",
|
||||
"version": "0.0.0",
|
||||
"coreVersion": ">=5.0.0"
|
||||
"coreVersion": ">=5.0.0",
|
||||
"pluginPriority": "0"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user