2011-12-08 17:18:03 +00:00
|
|
|
/*
|
|
|
|
Wiki text macro implementation
|
|
|
|
*/
|
|
|
|
|
2011-12-09 16:34:02 +00:00
|
|
|
/*jslint node: true */
|
2011-12-08 17:18:03 +00:00
|
|
|
"use strict";
|
|
|
|
|
2011-12-08 18:05:21 +00:00
|
|
|
var ArgParser = require("./ArgParser.js").ArgParser,
|
2011-12-09 10:17:41 +00:00
|
|
|
WikiTextParserModule = require("./WikiTextParser.js"),
|
2011-12-08 18:05:21 +00:00
|
|
|
utils = require("./Utils.js"),
|
|
|
|
util = require("util");
|
2011-12-08 17:18:03 +00:00
|
|
|
|
|
|
|
var wikiTextMacros = exports;
|
|
|
|
|
2011-12-09 12:26:36 +00:00
|
|
|
wikiTextMacros.versionTiddlyWiki = "2.6.5";
|
|
|
|
|
|
|
|
wikiTextMacros.executeMacros = function(tree,store,title) {
|
2011-12-08 17:18:03 +00:00
|
|
|
for(var t=0; t<tree.length; t++) {
|
|
|
|
if(tree[t].type === "macro") {
|
2011-12-09 12:26:36 +00:00
|
|
|
wikiTextMacros.executeMacro(tree[t],store,title);
|
2011-12-08 17:18:03 +00:00
|
|
|
}
|
|
|
|
if(tree[t].children) {
|
2011-12-09 12:26:36 +00:00
|
|
|
wikiTextMacros.executeMacros(tree[t].children,store,title);
|
2011-12-08 17:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-09 12:26:36 +00:00
|
|
|
wikiTextMacros.executeMacro = function(macroNode,store,title) {
|
2011-12-08 17:18:03 +00:00
|
|
|
var macroInfo = wikiTextMacros.macros[macroNode.name];
|
|
|
|
macroNode.output = [];
|
|
|
|
if(macroInfo) {
|
2011-12-09 12:26:36 +00:00
|
|
|
macroInfo.handler(macroNode,store,title);
|
2011-12-08 17:18:03 +00:00
|
|
|
} else {
|
|
|
|
macroNode.output.push({type: "text", value: "Unknown macro " + macroNode.name});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
wikiTextMacros.macros = {
|
2011-12-08 18:05:21 +00:00
|
|
|
allTags: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
br: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
list: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
slider: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
tabs: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
tag: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
tagging: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
tags: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
tiddler: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-09 08:59:49 +00:00
|
|
|
var args = new ArgParser(macroNode.params,{defaultName:"name"}),
|
2011-12-09 10:17:41 +00:00
|
|
|
targetTitle = args.getValueByName("name",null),
|
|
|
|
withTokens = args.getValuesByName("with",[]),
|
2011-12-09 16:34:02 +00:00
|
|
|
text = store.getTiddlerText(targetTitle,""),
|
|
|
|
t;
|
2011-12-09 10:17:41 +00:00
|
|
|
for(t=0; t<withTokens.length; t++) {
|
|
|
|
var placeholderRegExp = new RegExp("\\$"+(t+1),"mg");
|
|
|
|
text = text.replace(placeholderRegExp,withTokens[t]);
|
2011-12-09 08:59:49 +00:00
|
|
|
}
|
2011-12-09 10:17:41 +00:00
|
|
|
var parseTree = new WikiTextParserModule.WikiTextParser(text);
|
2011-12-09 16:34:02 +00:00
|
|
|
for(t=0; t<parseTree.tree.length; t++) {
|
2011-12-09 10:17:41 +00:00
|
|
|
macroNode.output.push(parseTree.tree[t]);
|
|
|
|
}
|
|
|
|
// Execute any macros in the copy
|
2011-12-09 12:26:36 +00:00
|
|
|
wikiTextMacros.executeMacros(macroNode.output,store,title);
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
timeline: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
today: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
var now = new Date(),
|
2011-12-09 14:51:47 +00:00
|
|
|
args = new ArgParser(macroNode.params,{noNames:true,cascadeDefaults:true}),
|
2011-12-08 18:05:21 +00:00
|
|
|
value = args.byPos[0] ? utils.formatDateString(now,args.byPos[0].v) : now.toLocaleString();
|
|
|
|
macroNode.output.push({type: "text", value: value});
|
|
|
|
}
|
|
|
|
},
|
2011-12-08 17:18:03 +00:00
|
|
|
version: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
|
|
|
macroNode.output.push({type: "text", value: wikiTextMacros.versionTiddlyWiki});
|
2011-12-08 17:18:03 +00:00
|
|
|
}
|
2011-12-08 18:05:21 +00:00
|
|
|
},
|
|
|
|
view: {
|
2011-12-09 12:26:36 +00:00
|
|
|
handler: function(macroNode,store,title) {
|
2011-12-08 18:05:21 +00:00
|
|
|
}
|
2011-12-08 17:18:03 +00:00
|
|
|
}
|
|
|
|
};
|