mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-05 21:33:52 +00:00
Get rid of the wikivocabulary object
This commit is contained in:
parent
cbc08fcc1c
commit
c703fb1267
19
core/boot.js
19
core/boot.js
@ -444,6 +444,25 @@ $tw.modules.applyMethods = function(moduleType,targetObject) {
|
|||||||
return targetObject;
|
return targetObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
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.createClassesFromModules = function(moduleType,subType,baseClass) {
|
||||||
|
var classes = {};
|
||||||
|
$tw.modules.forEachModuleOfType(moduleType,function(title,moduleExports) {
|
||||||
|
if(!subType || moduleExports.types[subType]) {
|
||||||
|
var newClass = function() {};
|
||||||
|
if(baseClass) {
|
||||||
|
newClass.prototype = new baseClass();
|
||||||
|
newClass.prototype.constructor = baseClass;
|
||||||
|
}
|
||||||
|
$tw.utils.extend(newClass.prototype,moduleExports);
|
||||||
|
classes[moduleExports.name] = newClass;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return classes;
|
||||||
|
};
|
||||||
|
|
||||||
/////////////////////////// Barebones tiddler object
|
/////////////////////////// Barebones tiddler object
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -27,13 +27,6 @@ Command.prototype.execute = function() {
|
|||||||
if(this.params.length < 2) {
|
if(this.params.length < 2) {
|
||||||
return "Missing filename";
|
return "Missing filename";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.commander.wiki.vocabulary) {
|
|
||||||
this.commander.wiki.new_initParsers();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var self = this,
|
var self = this,
|
||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
path = require("path"),
|
path = require("path"),
|
||||||
|
@ -26,9 +26,18 @@ Attributes are stored as hashmaps of the following objects:
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var WikiParser = function(vocabulary,type,text,options) {
|
var WikiParser = function(type,text,options) {
|
||||||
this.wiki = options.wiki;
|
this.wiki = options.wiki;
|
||||||
this.vocabulary = vocabulary;
|
// Initialise the classes if we don't have them already
|
||||||
|
if(!this.pragmaRuleClasses) {
|
||||||
|
WikiParser.prototype.pragmaRuleClasses = $tw.modules.createClassesFromModules("wikirule","pragma",$tw.WikiRuleBase);
|
||||||
|
}
|
||||||
|
if(!this.blockRuleClasses) {
|
||||||
|
WikiParser.prototype.blockRuleClasses = $tw.modules.createClassesFromModules("wikirule","block",$tw.WikiRuleBase);
|
||||||
|
}
|
||||||
|
if(!this.inlineRuleClasses) {
|
||||||
|
WikiParser.prototype.inlineRuleClasses = $tw.modules.createClassesFromModules("wikirule","inline",$tw.WikiRuleBase);
|
||||||
|
}
|
||||||
// Save the parse text
|
// Save the parse text
|
||||||
this.type = type || "text/vnd.tiddlywiki";
|
this.type = type || "text/vnd.tiddlywiki";
|
||||||
this.source = text || "";
|
this.source = text || "";
|
||||||
@ -38,10 +47,10 @@ var WikiParser = function(vocabulary,type,text,options) {
|
|||||||
// Initialise the things that pragma rules can change
|
// Initialise the things that pragma rules can change
|
||||||
this.macroDefinitions = {}; // Hash map of macro definitions
|
this.macroDefinitions = {}; // Hash map of macro definitions
|
||||||
// Instantiate the pragma parse rules
|
// Instantiate the pragma parse rules
|
||||||
this.pragmaRules = this.instantiateRules(this.vocabulary.pragmaRuleClasses,"pragma",0);
|
this.pragmaRules = this.instantiateRules(this.pragmaRuleClasses,"pragma",0);
|
||||||
// Instantiate the parser block and inline rules
|
// Instantiate the parser block and inline rules
|
||||||
this.blockRules = this.instantiateRules(this.vocabulary.blockRuleClasses,"block",0);
|
this.blockRules = this.instantiateRules(this.blockRuleClasses,"block",0);
|
||||||
this.inlineRules = this.instantiateRules(this.vocabulary.inlineRuleClasses,"inline",0);
|
this.inlineRules = this.instantiateRules(this.inlineRuleClasses,"inline",0);
|
||||||
// Parse any pragmas
|
// Parse any pragmas
|
||||||
this.parsePragmas();
|
this.parsePragmas();
|
||||||
// Parse the text into inline runs or blocks
|
// Parse the text into inline runs or blocks
|
||||||
|
@ -20,11 +20,15 @@ var WidgetRenderer = function(renderTree,renderContext,parseTreeNode) {
|
|||||||
this.renderTree = renderTree;
|
this.renderTree = renderTree;
|
||||||
this.renderContext = renderContext;
|
this.renderContext = renderContext;
|
||||||
this.parseTreeNode = parseTreeNode;
|
this.parseTreeNode = parseTreeNode;
|
||||||
|
// Widget classes
|
||||||
|
if(!this.widgetClasses) {
|
||||||
|
WidgetRenderer.prototype.widgetClasses = $tw.modules.createClassesFromModules("widget",null,$tw.WidgetBase);
|
||||||
|
}
|
||||||
// Compute our attributes
|
// Compute our attributes
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
this.computeAttributes();
|
this.computeAttributes();
|
||||||
// Create the widget object
|
// Create the widget object
|
||||||
var WidgetClass = this.renderTree.parser.vocabulary.widgetClasses[this.parseTreeNode.tag];
|
var WidgetClass = this.widgetClasses[this.parseTreeNode.tag];
|
||||||
if(WidgetClass) {
|
if(WidgetClass) {
|
||||||
this.widget = new WidgetClass();
|
this.widget = new WidgetClass();
|
||||||
this.widget.init(this);
|
this.widget.init(this);
|
||||||
|
@ -18,6 +18,11 @@ Create a render tree object for a parse tree
|
|||||||
var WikiRenderTree = function(parser,options) {
|
var WikiRenderTree = function(parser,options) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
this.wiki = options.wiki;
|
this.wiki = options.wiki;
|
||||||
|
// Hashmap of the renderer classes
|
||||||
|
if(!this.rendererClasses) {
|
||||||
|
WikiRenderTree.prototype.rendererClasses = $tw.modules.applyMethods("wikirenderer");
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -48,7 +53,7 @@ WikiRenderTree.prototype.createRenderers = function(renderContext,parseTreeNodes
|
|||||||
Create a renderer node for a parse tree node
|
Create a renderer node for a parse tree node
|
||||||
*/
|
*/
|
||||||
WikiRenderTree.prototype.createRenderer = function(renderContext,parseTreeNode) {
|
WikiRenderTree.prototype.createRenderer = function(renderContext,parseTreeNode) {
|
||||||
var RenderNodeClass = this.parser.vocabulary.rendererClasses[parseTreeNode.type];
|
var RenderNodeClass = this.rendererClasses[parseTreeNode.type];
|
||||||
return new RenderNodeClass(this,renderContext,parseTreeNode);
|
return new RenderNodeClass(this,renderContext,parseTreeNode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ Test the new parser
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var testNewParser = function() {
|
var testNewParser = function() {
|
||||||
$tw.wiki.new_initParsers();
|
|
||||||
var templateTitle = "$:/templates/NewPageTemplate";
|
var templateTitle = "$:/templates/NewPageTemplate";
|
||||||
var parser = $tw.wiki.new_parseTiddler(templateTitle);
|
var parser = $tw.wiki.new_parseTiddler(templateTitle);
|
||||||
console.log("parsetree after execution",parser);
|
console.log("parsetree after execution",parser);
|
||||||
|
@ -356,11 +356,6 @@ exports.clearCache = function(title) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.new_initParsers = function() {
|
|
||||||
// Create a default vocabulary
|
|
||||||
this.vocabulary = new $tw.WikiVocabulary({wiki: this});
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Parse a block of text of a specified MIME type
|
Parse a block of text of a specified MIME type
|
||||||
type: content type of text to be parsed
|
type: content type of text to be parsed
|
||||||
@ -370,7 +365,11 @@ Options include:
|
|||||||
parseAsInline: if true, the text of the tiddler will be parsed as an inline run
|
parseAsInline: if true, the text of the tiddler will be parsed as an inline run
|
||||||
*/
|
*/
|
||||||
exports.new_parseText = function(type,text,options) {
|
exports.new_parseText = function(type,text,options) {
|
||||||
return this.vocabulary.parseText(type,text,options);
|
options = options || {};
|
||||||
|
return new $tw.WikiParser(type,text,{
|
||||||
|
parseAsInline: options.parseAsInline,
|
||||||
|
wiki: this.wiki
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
/*\
|
|
||||||
title: $:/core/modules/parsers/wikiparser/wikivocabulary.js
|
|
||||||
type: application/javascript
|
|
||||||
module-type: global
|
|
||||||
|
|
||||||
\*/
|
|
||||||
(function(){
|
|
||||||
|
|
||||||
/*jslint node: true, browser: true */
|
|
||||||
/*global $tw: false */
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var WikiVocabulary = function(options) {
|
|
||||||
this.wiki = options.wiki;
|
|
||||||
// Hashmaps of the various parse rule classes
|
|
||||||
this.pragmaRuleClasses = this.createClassesFromModules("wikirule","pragma",$tw.WikiRuleBase);
|
|
||||||
this.blockRuleClasses = this.createClassesFromModules("wikirule","block",$tw.WikiRuleBase);
|
|
||||||
this.inlineRuleClasses = this.createClassesFromModules("wikirule","inline",$tw.WikiRuleBase);
|
|
||||||
// Hashmap of the various renderer classes
|
|
||||||
this.rendererClasses = $tw.modules.applyMethods("wikirenderer");
|
|
||||||
// Hashmap of the available widgets
|
|
||||||
this.widgetClasses = this.createClassesFromModules("widget",null,$tw.WidgetBase);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
WikiVocabulary.prototype.createClassesFromModules = function(moduleType,subType,baseClass) {
|
|
||||||
var classes = {};
|
|
||||||
$tw.modules.forEachModuleOfType(moduleType,function(title,moduleExports) {
|
|
||||||
if(!subType || moduleExports.types[subType]) {
|
|
||||||
var newClass = function() {};
|
|
||||||
if(baseClass) {
|
|
||||||
newClass.prototype = new baseClass();
|
|
||||||
newClass.prototype.constructor = baseClass;
|
|
||||||
}
|
|
||||||
$tw.utils.extend(newClass.prototype,moduleExports);
|
|
||||||
classes[moduleExports.name] = newClass;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return classes;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Parse a block of text of a specified MIME type
|
|
||||||
type: content type of text to be parsed
|
|
||||||
text: text
|
|
||||||
options: see below
|
|
||||||
Options include:
|
|
||||||
parseAsInline: if true, the text of the tiddler will be parsed as an inline run
|
|
||||||
*/
|
|
||||||
WikiVocabulary.prototype.parseText = function(type,text,options) {
|
|
||||||
options = options || {};
|
|
||||||
return new $tw.WikiParser(this,type,text,{
|
|
||||||
parseAsInline: options.parseAsInline,
|
|
||||||
wiki: this.wiki
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.WikiVocabulary = WikiVocabulary;
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user