1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

More refactoring to better separate concerns

registerModuleTiddlers() references the wiki store and so really should
be a method of it
This commit is contained in:
Jeremy Ruston 2012-08-30 15:00:08 +01:00
parent b80332316b
commit 807f8b8aab

View File

@ -243,37 +243,6 @@ $tw.modules.registerModuleExports = function(name,moduleType,moduleExports) {
$tw.modules.types[moduleType].push(moduleExports);
};
/*
Register all the module tiddlers that have a module type
*/
$tw.modules.registerModuleTiddlers = function() {
var title, tiddler;
// Execute and register 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" && tiddler.fields["module-type"] !== undefined) {
// Execute the module
var source = [
"(function(module,exports,require) {",
tiddler.fields.text,
"})"
];
$tw.modules.define(tiddler.fields.text,tiddler.fields["module-type"],window.eval(source.join("")));
// Register the module
$tw.modules.registerModuleExports(title,tiddler.fields["module-type"],$tw.modules.execute(title));
}
}
}
// Register any modules in ordinary tiddlers
for(title in $tw.wiki.tiddlers) {
tiddler = $tw.wiki.getTiddler(title);
if(tiddler.fields.type === "application/javascript" && tiddler.fields["module-type"] !== undefined) {
$tw.modules.registerModuleExports(title,tiddler.fields["module-type"],$tw.modules.execute(title));
}
}
};
/*
Get all the modules of a particular type in a hashmap by their `name` field
*/
@ -420,6 +389,37 @@ $tw.Wiki.prototype.installPlugins = function() {
}
};
/*
Register all the module tiddlers that have a module type
*/
$tw.Wiki.prototype.registerModuleTiddlers = function() {
var title, tiddler;
// Execute and register 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" && tiddler.fields["module-type"] !== undefined) {
// Execute the module
var source = [
"(function(module,exports,require) {",
tiddler.fields.text,
"})"
];
$tw.modules.define(tiddler.fields.text,tiddler.fields["module-type"],window.eval(source.join("")));
// Register the module
$tw.modules.registerModuleExports(title,tiddler.fields["module-type"],$tw.modules.execute(title));
}
}
}
// Register any modules in ordinary tiddlers
for(title in $tw.wiki.tiddlers) {
tiddler = $tw.wiki.getTiddler(title);
if(tiddler.fields.type === "application/javascript" && tiddler.fields["module-type"] !== undefined) {
$tw.modules.registerModuleExports(title,tiddler.fields["module-type"],$tw.modules.execute(title));
}
}
};
$tw.Wiki.prototype.getTiddler = function(title) {
var t = this.tiddlers[title];
if(t instanceof $tw.Tiddler) {
@ -737,7 +737,7 @@ $tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiTiddler
$tw.wiki.installPlugins();
// Register typed modules from the tiddlers we've just loaded
$tw.modules.registerModuleTiddlers();
$tw.wiki.registerModuleTiddlers();
// Run any startup modules
var mainModules = $tw.modules.types.startup;