Added tracking of dependencies between tiddlers

This commit is contained in:
Jeremy Ruston 2012-01-06 19:41:42 +00:00
parent 3d507c3bab
commit 82a83bd714
3 changed files with 20 additions and 7 deletions

View File

@ -13,8 +13,9 @@ var ArgParser = require("./ArgParser.js").ArgParser,
utils = require("./Utils.js");
// Intialise the parse tree object
var WikiTextParseTree = function(tree,store) {
var WikiTextParseTree = function(tree,dependencies,store) {
this.tree = tree;
this.dependencies = dependencies; // An array of tiddler names, or null if this tiddler depends on too many to track
this.store = store;
};

View File

@ -44,9 +44,10 @@ WikiTextParser.prototype.parse = function(text) {
this.source = text;
this.nextMatch = 0;
this.children = [];
this.dependencies = [];
this.output = null;
this.subWikify(this.children);
return new WikiTextParseTree(this.children,this.store);
return new WikiTextParseTree(this.children,this.dependencies,this.store);
};
WikiTextParser.prototype.outputText = function(place,startPos,endPos) {

View File

@ -113,20 +113,31 @@ var parseMacroCall = function(w,name,paramString) {
params = {};
if(macro) {
var args = new ArgParser(paramString,{defaultName: "anon"}),
insertParam = function(name,arg) {
insertParam = function(param,name,arg) {
if(param.type === "tiddler") {
if(arg.evaluated) {
w.dependencies = null;
} else {
if(w.dependencies) {
w.dependencies.push(arg.string);
}
}
}
params[name] = {type: arg.evaluated ? "eval" : "string", value: arg.string};
};
for(var m in macro.params) {
var param = macro.params[m];
var param = macro.params[m],
arg;
if("byPos" in param && args.byPos[param.byPos]) {
insertParam(m,args.byPos[param.byPos].v);
arg = args.byPos[param.byPos].v;
insertParam(param,m,arg);
} else if("byName" in param) {
var arg = args.getValueByName(m);
arg = args.getValueByName(m);
if(!arg && param.byName === "default") {
arg = args.getValueByName("anon");
}
if(arg) {
insertParam(m,arg);
insertParam(param,m,arg);
}
}
}