mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-08 07:00:03 +00:00
Basic plugin support for browser and server
Currently only supports plugins packed as a single JSON tiddler
This commit is contained in:
parent
4cebcddeeb
commit
88e7a4fb67
26
core/boot.js
26
core/boot.js
@ -365,7 +365,7 @@ $tw.Wiki.prototype.addTiddlers = function(tiddlers,isShadow) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Install tiddlers contained in plugin tiddlers
|
Extract tiddlers stored in plugins so that we can easily access them in getTiddler()
|
||||||
*/
|
*/
|
||||||
$tw.Wiki.prototype.installPlugins = function() {
|
$tw.Wiki.prototype.installPlugins = function() {
|
||||||
this.plugins = {}; // Hashmap of plugin information by title
|
this.plugins = {}; // Hashmap of plugin information by title
|
||||||
@ -373,7 +373,7 @@ $tw.Wiki.prototype.installPlugins = function() {
|
|||||||
// Collect up all the plugin tiddlers
|
// Collect up all the plugin tiddlers
|
||||||
for(var title in this.tiddlers) {
|
for(var title in this.tiddlers) {
|
||||||
var tiddler = this.tiddlers[title];
|
var tiddler = this.tiddlers[title];
|
||||||
if(tiddler.fields.type === "application/x-tiddlywiki-plugin") {
|
if(tiddler.fields.type === "application/json" && "plugin" in tiddler.fields) {
|
||||||
// Save the plugin information
|
// Save the plugin information
|
||||||
var pluginInfo = this.plugins[title] = JSON.parse(tiddler.fields.text);
|
var pluginInfo = this.plugins[title] = JSON.parse(tiddler.fields.text);
|
||||||
// Extract the constituent tiddlers
|
// Extract the constituent tiddlers
|
||||||
@ -394,24 +394,34 @@ Register all the module tiddlers that have a module type
|
|||||||
*/
|
*/
|
||||||
$tw.Wiki.prototype.registerModuleTiddlers = function() {
|
$tw.Wiki.prototype.registerModuleTiddlers = function() {
|
||||||
var title, tiddler;
|
var title, tiddler;
|
||||||
// Execute and register any modules from plugins
|
// If in the browser, define any modules from plugins
|
||||||
|
if($tw.browser) {
|
||||||
for(title in $tw.wiki.pluginTiddlers) {
|
for(title in $tw.wiki.pluginTiddlers) {
|
||||||
tiddler = $tw.wiki.getTiddler(title);
|
tiddler = $tw.wiki.getTiddler(title);
|
||||||
if(!(title in $tw.wiki.tiddlers)) {
|
if(!(title in $tw.wiki.tiddlers)) {
|
||||||
if(tiddler.fields.type === "application/javascript" && tiddler.fields["module-type"] !== undefined) {
|
if(tiddler.fields.type === "application/javascript" && "module-type" in tiddler.fields) {
|
||||||
// Execute the module
|
// Define the module
|
||||||
var source = [
|
var source = [
|
||||||
"(function(module,exports,require) {",
|
"(function(module,exports,require) {",
|
||||||
tiddler.fields.text,
|
tiddler.fields.text,
|
||||||
"})"
|
"})"
|
||||||
];
|
];
|
||||||
$tw.modules.define(tiddler.fields.text,tiddler.fields["module-type"],window.eval(source.join("")));
|
$tw.modules.define(tiddler.fields.title,tiddler.fields["module-type"],window.eval(source.join("")));
|
||||||
// Register the module
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Register and execute any modules from plugins
|
||||||
|
for(title in $tw.wiki.pluginTiddlers) {
|
||||||
|
tiddler = $tw.wiki.getTiddler(title);
|
||||||
|
if(!(title in $tw.wiki.tiddlers)) {
|
||||||
|
if(tiddler.fields.type === "application/javascript" && "module-type" in tiddler.fields) {
|
||||||
|
// Execute and register the module
|
||||||
$tw.modules.registerModuleExports(title,tiddler.fields["module-type"],$tw.modules.execute(title));
|
$tw.modules.registerModuleExports(title,tiddler.fields["module-type"],$tw.modules.execute(title));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Register any modules in ordinary tiddlers
|
// Register and execute any modules in ordinary tiddlers
|
||||||
for(title in $tw.wiki.tiddlers) {
|
for(title in $tw.wiki.tiddlers) {
|
||||||
tiddler = $tw.wiki.getTiddler(title);
|
tiddler = $tw.wiki.getTiddler(title);
|
||||||
if(tiddler.fields.type === "application/javascript" && tiddler.fields["module-type"] !== undefined) {
|
if(tiddler.fields.type === "application/javascript" && tiddler.fields["module-type"] !== undefined) {
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
title: TemporaryTestPlugin
|
title: TemporaryTestPlugin
|
||||||
type: application/x-tiddlywiki-plugin
|
type: application/json
|
||||||
|
plugin: yes
|
||||||
|
|
||||||
{
|
{
|
||||||
"tiddlers": [
|
"tiddlers": [
|
||||||
{"title": "Test1", "text": "Some text"},
|
{"title": "Test1", "text": "Some text"},
|
||||||
{"title": "Test2", "type": "Some more text"}
|
{"title": "Test2", "text": "Some more text"},
|
||||||
|
{"title": "Test3", "text": "console.log(require('Test4').string);", "type": "application/javascript", "module-type": "custom"},
|
||||||
|
{"title": "Test4", "text": "exports.string = 'Plugin I am in You!';", "type": "application/javascript", "module-type": "custom"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user