From f0e9c4e7fffa58437c128852471261fa48d9b2ba Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 16 Dec 2011 17:45:33 +0000 Subject: [PATCH] Added support for the timeline macro --- js/Main.js | 2 +- js/WikiTextRenderer.js | 68 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/js/Main.js b/js/Main.js index bf8a81c1c..d0d20f615 100644 --- a/js/Main.js +++ b/js/Main.js @@ -90,6 +90,6 @@ navigators.install("a","StoryNavigator"); // Navigate to HelloThere navigators.navigateTo("HelloThere","StoryNavigator"); -navigators.navigateTo("TabAll","StoryNavigator"); +navigators.navigateTo("TabTimeline","StoryNavigator"); })(); diff --git a/js/WikiTextRenderer.js b/js/WikiTextRenderer.js index 111325776..c4a34332d 100644 --- a/js/WikiTextRenderer.js +++ b/js/WikiTextRenderer.js @@ -147,6 +147,70 @@ WikiTextRenderer.macros = { macroNode.output.push({type: "br"}); } }, + timeline: { + handler: function(macroNode,title) { + var args = new ArgParser(macroNode.params,{defaultName:"anon"}), + anonByPos = args.getValuesByName("anon",[]), + field = anonByPos[0] || "modified", + limit = anonByPos[1] || null, + dateformat = anonByPos[2] || "DD MMM YYYY", + template = args.getValueByName("template",null), + templateType = "text/x-tiddlywiki", + templateText = "<>", + groupTemplate = args.getValueByName("groupTemplate",null), + groupTemplateType = "text/x-tiddlywiki", + groupTemplateText = "<>", + filter = args.getValueByName("filter",null), + tiddlers, + lastGroup = "", + ul, + last = 0, + t; + limit = limit ? parseInt(limit,10) : null; + template = template ? this.store.getTiddler(template) : null; + if(template) { + templateType = template.fields.type; + templateText = template.fields.text; + } + groupTemplate = groupTemplate ? this.store.getTiddler(groupTemplate) : null; + if(groupTemplate) { + groupTemplateType = groupTemplate.fields.type; + groupTemplateText = groupTemplate.fields.text; + } + if(filter) { + // Filtering not implemented yet + tiddlers = this.store.getTitles(field,"excludeLists"); + } else { + tiddlers = this.store.getTitles(field,"excludeLists"); + } + if(limit !== null) { + last = tiddlers.length - Math.min(tiddlers.length,limit); + } + for(t=tiddlers.length-1; t>=last; t--) { + var tiddler = tiddlers[t], + theGroupParseTree = this.parser.processor.textProcessors.parse(groupTemplateType,groupTemplateText), + theGroup = theGroupParseTree.render("text/plain",theGroupParseTree.children,this.store,tiddler); + + if(ul === undefined || theGroup != lastGroup) { + ul = {type: "ul", attributes: {"class": "timeline"}, children: []}; + macroNode.output.push(ul); + ul.children.push({type: "li", attributes: {"class": "listTitle"}, children: [{type: "text", value: theGroup}]}); + lastGroup = theGroup; + } + var item = {type: "li", attributes: {"class": "listLink"}, children: [ { + type: "context", + tiddler: tiddler, + children: [] + }]}; + ul.children.push(item); + var itemParseTree = this.parser.processor.textProcessors.parse(templateType,templateText); + for(var c=0; c