Introduced new Dependency() class to encapsulate dependency handling logic

Note that the format is now slightly different; see js/Dependencies.js
for details
This commit is contained in:
Jeremy Ruston
2012-02-17 14:11:25 +00:00
parent 8d4d168432
commit 103a9a4d7f
11 changed files with 87 additions and 80 deletions

View File

@@ -33,6 +33,7 @@ HTML nodes look like this:
var WikiTextRules = require("./WikiTextRules.js"),
WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
Dependencies = require("./Dependencies.js").Dependencies,
Renderer = require("./Renderer.js").Renderer,
utils = require("./Utils.js"),
util = require("util");
@@ -67,7 +68,7 @@ WikiTextParser.prototype.parse = function(type,text) {
this.source = text;
this.nextMatch = 0;
this.children = [];
this.dependencies = {};
this.dependencies = new Dependencies();
this.output = null;
this.subWikify(this.children);
var tree = new WikiTextParseTree(this.children,this.dependencies,this.store);
@@ -76,25 +77,6 @@ WikiTextParser.prototype.parse = function(type,text) {
return tree;
};
WikiTextParser.prototype.mergeDependencies = function(newDependencies) {
for(var rel in newDependencies) {
if(rel === "dependentAll") {
this.dependencies.dependentAll = newDependencies.dependentAll;
} else {
if(!(rel in this.dependencies)) {
this.dependencies[rel] = {};
}
for(var t in newDependencies[rel]) {
if(this.dependencies[rel][t]) {
this.dependencies[rel][t]++;
} else {
this.dependencies[rel][t] = 1;
}
}
}
}
};
WikiTextParser.prototype.outputText = function(place,startPos,endPos) {
if(startPos < endPos) {
place.push(Renderer.TextNode(this.source.substring(startPos,endPos)));