1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Further refactoring of createSubclassesFromModules

This commit is contained in:
Jeremy Ruston 2012-12-14 15:51:23 +00:00
parent 2bef7c2c5c
commit ac4b3ecef9
2 changed files with 9 additions and 7 deletions

View File

@ -445,14 +445,16 @@ $tw.modules.applyMethods = function(moduleType,targetObject) {
};
/*
Return an array of subclasses created from the modules of a specified type
Return an array of classes created from the modules of a specified type. Each module should export the properties to be added to those of the optional base class
*/
$tw.modules.createSubclassesFromModules = function(moduleType,baseClass) {
$tw.modules.createClassesFromModules = function(moduleType,baseClass) {
var classes = {};
$tw.modules.forEachModuleOfType(moduleType,function(title,moduleExports) {
var newClass = function() {};
newClass.prototype = new baseClass();
newClass.prototype.constructor = baseClass;
if(baseClass) {
newClass.prototype = new baseClass();
newClass.prototype.constructor = baseClass;
}
$tw.utils.extend(newClass.prototype,moduleExports);
classes[moduleExports.name] = newClass;
});

View File

@ -13,9 +13,9 @@ module-type: global
var WikiVocabulary = function(options) {
this.wiki = options.wiki;
// Hashmaps of the various parse rule classes
this.pragmaRuleClasses = $tw.modules.createSubclassesFromModules("wikipragmarule",$tw.WikiRule);
this.blockRuleClasses = $tw.modules.createSubclassesFromModules("wikiblockrule",$tw.WikiRule);
this.runRuleClasses = $tw.modules.createSubclassesFromModules("wikirunrule",$tw.WikiRule);
this.pragmaRuleClasses = $tw.modules.createClassesFromModules("wikipragmarule",$tw.WikiRule);
this.blockRuleClasses = $tw.modules.createClassesFromModules("wikiblockrule",$tw.WikiRule);
this.runRuleClasses = $tw.modules.createClassesFromModules("wikirunrule",$tw.WikiRule);
// Hashmap of the various renderer classes
this.rendererClasses = $tw.modules.applyMethods("wikirenderer");
// Hashmap of the available widgets