mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-09-06 12:58:03 +00:00
Improve TiddlyWiki as a library
1. Make it possible to disable specific boot tasks 2. Extend the startup mechanism to allow startup tasks to be disabled Again, see Jermolene/TiddlyWiki5NodeWebkit to see how these features fit together.
This commit is contained in:
24
boot/boot.js
24
boot/boot.js
@@ -33,7 +33,6 @@ if(!$tw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tw.utils = $tw.utils || Object.create(null);
|
$tw.utils = $tw.utils || Object.create(null);
|
||||||
$tw.boot = $tw.boot || Object.create(null);
|
|
||||||
|
|
||||||
/////////////////////////// Standard node.js libraries
|
/////////////////////////// Standard node.js libraries
|
||||||
|
|
||||||
@@ -155,7 +154,7 @@ $tw.utils.error = function(err) {
|
|||||||
/*
|
/*
|
||||||
Use our custom error handler if we're in the browser
|
Use our custom error handler if we're in the browser
|
||||||
*/
|
*/
|
||||||
if($tw.browser && !$tw.node) {
|
if($tw.boot.tasks.trapErrors) {
|
||||||
window.onerror = function(errorMsg,url,lineNumber) {
|
window.onerror = function(errorMsg,url,lineNumber) {
|
||||||
$tw.utils.error(errorMsg);
|
$tw.utils.error(errorMsg);
|
||||||
return false;
|
return false;
|
||||||
@@ -309,7 +308,6 @@ name `.` refers to the current directory
|
|||||||
*/
|
*/
|
||||||
$tw.utils.resolvePath = function(sourcepath,rootpath) {
|
$tw.utils.resolvePath = function(sourcepath,rootpath) {
|
||||||
// If the source path starts with ./ or ../ then it is relative to the root
|
// If the source path starts with ./ or ../ then it is relative to the root
|
||||||
|
|
||||||
if(sourcepath.substr(0,2) === "./" || sourcepath.substr(0,3) === "../" ) {
|
if(sourcepath.substr(0,2) === "./" || sourcepath.substr(0,3) === "../" ) {
|
||||||
var src = sourcepath.split("/"),
|
var src = sourcepath.split("/"),
|
||||||
root = rootpath.split("/");
|
root = rootpath.split("/");
|
||||||
@@ -1621,8 +1619,7 @@ $tw.loadTiddlersNode = function() {
|
|||||||
/////////////////////////// Main startup function called once tiddlers have been decrypted
|
/////////////////////////// Main startup function called once tiddlers have been decrypted
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Startup TiddlyWiki. Options are:
|
Startup TiddlyWiki
|
||||||
readBrowserTiddlers: whether to read tiddlers from the HTML file we're executing within; if not, tiddlers are read from the file system with Node.js APIs
|
|
||||||
*/
|
*/
|
||||||
$tw.boot.startup = function(options) {
|
$tw.boot.startup = function(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@@ -1657,7 +1654,7 @@ $tw.boot.startup = function(options) {
|
|||||||
contentTypeInfo: Object.create(null) // Map type to {encoding:,extension:}
|
contentTypeInfo: Object.create(null) // Map type to {encoding:,extension:}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!options.readBrowserTiddlers) {
|
if(!$tw.boot.tasks.readBrowserTiddlers) {
|
||||||
// For writable tiddler files, a hashmap of title to {filepath:,type:,hasMetaFile:}
|
// For writable tiddler files, a hashmap of title to {filepath:,type:,hasMetaFile:}
|
||||||
$tw.boot.files = Object.create(null);
|
$tw.boot.files = Object.create(null);
|
||||||
// System paths and filenames
|
// System paths and filenames
|
||||||
@@ -1710,7 +1707,7 @@ $tw.boot.startup = function(options) {
|
|||||||
$tw.Wiki.tiddlerDeserializerModules = Object.create(null);
|
$tw.Wiki.tiddlerDeserializerModules = Object.create(null);
|
||||||
$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules);
|
$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules);
|
||||||
// Load tiddlers
|
// Load tiddlers
|
||||||
if(options.readBrowserTiddlers) {
|
if($tw.boot.tasks.readBrowserTiddlers) {
|
||||||
$tw.loadTiddlersBrowser();
|
$tw.loadTiddlersBrowser();
|
||||||
} else {
|
} else {
|
||||||
$tw.loadTiddlersNode();
|
$tw.loadTiddlersNode();
|
||||||
@@ -1740,6 +1737,7 @@ $tw.boot.startup = function(options) {
|
|||||||
});
|
});
|
||||||
// Keep track of the startup tasks that have been executed
|
// Keep track of the startup tasks that have been executed
|
||||||
$tw.boot.executedStartupModules = Object.create(null);
|
$tw.boot.executedStartupModules = Object.create(null);
|
||||||
|
$tw.boot.disabledStartupModules = $tw.boot.disabledStartupModules || [];
|
||||||
// Repeatedly execute the next eligible task
|
// Repeatedly execute the next eligible task
|
||||||
$tw.boot.executeNextStartupTask();
|
$tw.boot.executeNextStartupTask();
|
||||||
};
|
};
|
||||||
@@ -1809,14 +1807,18 @@ $tw.boot.isStartupTaskEligible = function(taskModule) {
|
|||||||
if(!$tw.boot.doesTaskMatchPlatform(taskModule)) {
|
if(!$tw.boot.doesTaskMatchPlatform(taskModule)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check that no other outstanding tasks must be executed before this one
|
|
||||||
var name = taskModule.name,
|
var name = taskModule.name,
|
||||||
remaining = $tw.boot.remainingStartupModules;
|
remaining = $tw.boot.remainingStartupModules;
|
||||||
if(name) {
|
if(name) {
|
||||||
|
// Fail if this module is disabled
|
||||||
|
if($tw.boot.disabledStartupModules.indexOf(name) !== -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Check that no other outstanding tasks must be executed before this one
|
||||||
for(t=0; t<remaining.length; t++) {
|
for(t=0; t<remaining.length; t++) {
|
||||||
var task = remaining[t];
|
var task = remaining[t];
|
||||||
if(task.before && task.before.indexOf(name) !== -1) {
|
if(task.before && task.before.indexOf(name) !== -1) {
|
||||||
if($tw.boot.doesTaskMatchPlatform(task)) {
|
if($tw.boot.doesTaskMatchPlatform(task) || (task.name && $tw.boot.disabledStartupModules.indexOf(name) !== -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1846,9 +1848,7 @@ $tw.boot.boot = function() {
|
|||||||
// Preload any encrypted tiddlers
|
// Preload any encrypted tiddlers
|
||||||
$tw.boot.decryptEncryptedTiddlers(function() {
|
$tw.boot.decryptEncryptedTiddlers(function() {
|
||||||
// Startup
|
// Startup
|
||||||
$tw.boot.startup({
|
$tw.boot.startup();
|
||||||
readBrowserTiddlers: !!($tw.browser && !$tw.node)
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -16,13 +16,20 @@ var _bootprefix = (function($tw) {
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
$tw = $tw || {};
|
$tw = $tw || Object.create(null);
|
||||||
|
$tw.boot = $tw.boot || Object.create(null);
|
||||||
|
|
||||||
// Detect platforms
|
// Detect platforms
|
||||||
$tw.browser = typeof(window) !== "undefined" ? {} : null;
|
$tw.browser = typeof(window) !== "undefined" ? {} : null;
|
||||||
$tw.node = typeof(process) === "object" ? {} : null;
|
$tw.node = typeof(process) === "object" ? {} : null;
|
||||||
$tw.nodeWebKit = $tw.node && global.window && global.window.nwDispatcher ? {} : null;
|
$tw.nodeWebKit = $tw.node && global.window && global.window.nwDispatcher ? {} : null;
|
||||||
|
|
||||||
|
// Set default boot tasks
|
||||||
|
$tw.boot.tasks = {
|
||||||
|
trapErrors: !!($tw.browser && !$tw.node),
|
||||||
|
readBrowserTiddlers: !!($tw.browser && !$tw.node)
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Information about each module is kept in an object with these members:
|
Information about each module is kept in an object with these members:
|
||||||
moduleType: type of module
|
moduleType: type of module
|
||||||
|
Reference in New Issue
Block a user