From d96053192b8cdc378685d117e425edcf208b5ce1 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 14 Dec 2011 15:45:42 +0000 Subject: [PATCH] Added support for the view macro, and client side wikitext tiddler templates --- js/StoryNavigator.js | 2 +- js/WikiStore.js | 5 +++-- js/WikiTextRenderer.js | 37 ++++++++++++++++++++++++++++++++++++- js/WikiTextRules.js | 10 +++++----- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/js/StoryNavigator.js b/js/StoryNavigator.js index c8d229ff5..57c737316 100644 --- a/js/StoryNavigator.js +++ b/js/StoryNavigator.js @@ -14,7 +14,7 @@ var StoryNavigator = function(navigators) { }; StoryNavigator.prototype.navigateTo = function(title) { - var tiddlerHtml = this.navigators.store.renderTiddler("text/html",title); + var tiddlerHtml = this.navigators.store.renderTiddler("text/html","SimpleTemplate",title); if(tiddlerHtml) { $("
").html(tiddlerHtml).appendTo("body"); return false; diff --git a/js/WikiStore.js b/js/WikiStore.js index 8f74fe911..57908ea45 100755 --- a/js/WikiStore.js +++ b/js/WikiStore.js @@ -101,8 +101,9 @@ WikiStore.prototype.parseTiddler = function(title) { Render a tiddler to a particular MIME type. Optionally render it with a different tiddler as the context. This option is used to render a tiddler through a template as store.renderTiddler("text/html",tiddler,template) */ WikiStore.prototype.renderTiddler = function(type,title,asTitle) { - var parser = this.parseTiddler(title); - if(parser) { + var parser = this.parseTiddler(title), + asTitleExists = asTitle ? this.tiddlerExists(asTitle) : true; + if(parser && asTitleExists) { return parser.render(type,parser.children,this,asTitle ? asTitle : title); } else { return null; diff --git a/js/WikiTextRenderer.js b/js/WikiTextRenderer.js index 1cb616049..e47c1f159 100644 --- a/js/WikiTextRenderer.js +++ b/js/WikiTextRenderer.js @@ -193,7 +193,7 @@ WikiTextRenderer.macros = { today: { handler: function(macroNode) { var now = new Date(), - args = new ArgParser(macroNode.params,{noNames:true,cascadeDefaults:true}), + args = new ArgParser(macroNode.params,{noNames:true}), value = args.byPos[0] ? utils.formatDateString(now,args.byPos[0].v) : now.toLocaleString(); macroNode.output.push({type: "text", value: value}); } @@ -205,6 +205,41 @@ WikiTextRenderer.macros = { }, view: { handler: function(macroNode) { + var args = new ArgParser(macroNode.params,{noNames:true}), + field = args.byPos[0] ? args.byPos[0].v : null, + format = args.byPos[1] ? args.byPos[1].v : "text", + tiddler = this.store.getTiddler(this.title), + value = tiddler ? tiddler.fields[field] : null; + if(tiddler && field && value) { + switch(format) { + case "text": + macroNode.output.push({type: "text", value: value}); + break; + case "link": + macroNode.output.push({ + type: "a", + attributes: { + href: value + }, + children: [ + {type: "text", value: value} + ] + }); + break; + case "wikified": + var parseTree = this.parser.processor.textProcessors.parse("text/x-tiddlywiki",value); + for(var t=0; t