Fixed problem with tiddler context within macros

This commit is contained in:
Jeremy Ruston 2011-12-09 12:26:36 +00:00
parent 341c7143ed
commit 318381a21b
4 changed files with 30 additions and 27 deletions

View File

@ -282,13 +282,13 @@ Recipe.prototype.cookRss = function()
numRssItems = 20,
s = [],
d = new Date(),
u = this.store.getTiddler("SiteUrl").getParseTree().render("text/plain"),
u = this.store.getTiddler("SiteUrl").getParseTree().render("text/plain",me.store,"SiteUrl"),
encodeTiddlyLink = function(title) {
return title.indexOf(" ") == -1 ? title : "[[" + title + "]]";
},
tiddlerToRssItem = function(tiddler,uri) {
var s = "<title" + ">" + utils.htmlEncode(tiddler.fields.title) + "</title" + ">\n";
s += "<description>" + utils.htmlEncode(tiddler.getParseTree().render("text/html")) + "</description>\n";
s += "<description>" + utils.htmlEncode(tiddler.getParseTree().render("text/html",me.store,tiddler.fields.title)) + "</description>\n";
var i;
if(tiddler.fields.tags) {
for(i=0; i<tiddler.fields.tags.length; i++) {
@ -327,10 +327,10 @@ Recipe.prototype.cookRss = function()
s.push("<" + "?xml version=\"1.0\"?" + ">");
s.push("<rss version=\"2.0\">");
s.push("<channel>");
s.push("<title" + ">" + utils.htmlEncode(this.store.getTiddler("SiteTitle").getParseTree().render("text/plain")) + "</title" + ">");
s.push("<title" + ">" + utils.htmlEncode(this.store.getTiddler("SiteTitle").getParseTree().render("text/plain",me.store,"SiteTitle")) + "</title" + ">");
if(u)
s.push("<link>" + utils.htmlEncode(u) + "</link>");
s.push("<description>" + utils.htmlEncode(this.store.getTiddler("SiteSubtitle").getParseTree().render("text/plain")) + "</description>");
s.push("<description>" + utils.htmlEncode(this.store.getTiddler("SiteSubtitle").getParseTree().render("text/plain",me.store,"SiteSubtitle")) + "</description>");
//s.push("<language>" + config.locale + "</language>");
s.push("<pubDate>" + d.toUTCString() + "</pubDate>");
s.push("<lastBuildDate>" + d.toUTCString() + "</lastBuildDate>");

View File

@ -13,22 +13,25 @@ var ArgParser = require("./ArgParser.js").ArgParser,
var wikiTextMacros = exports;
wikiTextMacros.executeMacros = function(tree,store,tiddler) {
wikiTextMacros.versionTiddlyWiki = "2.6.5";
wikiTextMacros.executeMacros = function(tree,store,title) {
for(var t=0; t<tree.length; t++) {
if(tree[t].type === "macro") {
wikiTextMacros.executeMacro(tree[t],store,tiddler);
wikiTextMacros.executeMacro(tree[t],store,title);
}
if(tree[t].children) {
wikiTextMacros.executeMacros(tree[t].children,store,tiddler);
wikiTextMacros.executeMacros(tree[t].children,store,title);
}
}
};
wikiTextMacros.executeMacro = function(macroNode,store,tiddler) {
wikiTextMacros.executeMacro = function(macroNode,store,title) {
var macroInfo = wikiTextMacros.macros[macroNode.name];
console.error("Executing macro %s with params %s in tiddler %s",macroNode.name,0,title);
macroNode.output = [];
if(macroInfo) {
macroInfo.handler(macroNode,store,tiddler);
macroInfo.handler(macroNode,store,title);
} else {
macroNode.output.push({type: "text", value: "Unknown macro " + macroNode.name});
}
@ -36,39 +39,39 @@ wikiTextMacros.executeMacro = function(macroNode,store,tiddler) {
wikiTextMacros.macros = {
allTags: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
},
br: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
},
list: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
},
slider: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
},
tabs: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
},
tag: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
},
tagging: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
},
tags: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
},
tiddler: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
var args = new ArgParser(macroNode.params,{defaultName:"name"}),
targetTitle = args.getValueByName("name",null),
withTokens = args.getValuesByName("with",[]),
@ -82,15 +85,15 @@ wikiTextMacros.macros = {
macroNode.output.push(parseTree.tree[t]);
}
// Execute any macros in the copy
wikiTextMacros.executeMacros(macroNode.output,store,tiddler);
wikiTextMacros.executeMacros(macroNode.output,store,title);
}
},
timeline: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
},
today: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
var now = new Date(),
args = new ArgParser(macroNode.params,{noNames:true}),
value = args.byPos[0] ? utils.formatDateString(now,args.byPos[0].v) : now.toLocaleString();
@ -98,12 +101,12 @@ wikiTextMacros.macros = {
}
},
version: {
handler: function(macroNode,store,tiddler) {
macroNode.output.push({type: "text", value: "0.0.0"});
handler: function(macroNode,store,title) {
macroNode.output.push({type: "text", value: wikiTextMacros.versionTiddlyWiki});
}
},
view: {
handler: function(macroNode,store,tiddler) {
handler: function(macroNode,store,title) {
}
}
};

View File

@ -101,7 +101,7 @@ WikiTextParser.prototype.renderAsHtml = function(store,title) {
}
}
};
wikiTextMacros.executeMacros(this.tree,store);
wikiTextMacros.executeMacros(this.tree,store,title);
renderSubTree(this.tree);
return output.join("");
};
@ -131,7 +131,7 @@ WikiTextParser.prototype.renderAsText = function(store,title) {
}
}
};
wikiTextMacros.executeMacros(this.tree,store);
wikiTextMacros.executeMacros(this.tree,store,title);
renderSubTree(this.tree);
return output.join("");
};

View File

@ -148,7 +148,7 @@ WikiTextRules.rules = [
// Move the caption to the first row if it isn't already
if(table.children.length !== 1) {
table.children.pop(); // Take rowContainer out of the children array
table.splice(0,0,rowContainer); // Insert it at the bottom
table.children.splice(0,0,rowContainer); // Insert it at the bottom
}
rowContainer.attributes.align = rowCount === 0 ? "top" : "bottom";
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);