From cd04fa22c6186a6a26616b77ef04535ee220bfac Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 18 Oct 2012 18:27:27 +0100 Subject: [PATCH] Introduce extensible viewer modules for the view macro --- core/modules/macros/view/view.js | 83 +++---------------- core/modules/macros/view/viewers/date.js | 26 ++++++ core/modules/macros/view/viewers/link.js | 32 +++++++ core/modules/macros/view/viewers/text.js | 30 +++++++ .../modules/macros/view/viewers/transclude.js | 31 +++++++ core/modules/macros/view/viewers/wikified.js | 42 ++++++++++ core/modules/startup.js | 1 + core/modules/wiki.js | 12 +++ 8 files changed, 186 insertions(+), 71 deletions(-) create mode 100644 core/modules/macros/view/viewers/date.js create mode 100644 core/modules/macros/view/viewers/link.js create mode 100644 core/modules/macros/view/viewers/text.js create mode 100644 core/modules/macros/view/viewers/transclude.js create mode 100644 core/modules/macros/view/viewers/wikified.js diff --git a/core/modules/macros/view/view.js b/core/modules/macros/view/view.js index 31b4e9282..b4e7362a9 100644 --- a/core/modules/macros/view/view.js +++ b/core/modules/macros/view/view.js @@ -25,14 +25,11 @@ exports.info = { exports.executeMacro = function() { var tiddler = this.wiki.getTiddler(this.tiddlerTitle), field = this.hasParameter("field") ? this.params.field : "title", - value, - children, - t, - childrenClone = [], - parents = this.parents; + value; + // Get the value to display if(tiddler) { value = tiddler.fields[field]; - } else { + } else { // Use a special value if the tiddler is missing switch(field) { case "text": value = ""; @@ -49,72 +46,16 @@ exports.executeMacro = function() { break; } } - switch(this.params.format) { - case "link": - if(value === undefined) { - return $tw.Tree.Text(""); - } else { - var link = $tw.Tree.Macro("link",{ - srcParams: {to: value}, - content: [$tw.Tree.Text(value)], - isBlock: this.isBlock, - wiki: this.wiki - }); - link.execute(parents,this.tiddlerTitle); - return link; - } - break; - case "transclude": - if(tiddler && this.params.field && (this.params.field in tiddler.fields)) { - children = this.wiki.parseTiddler(tiddler.fields[this.params.field]).tree; - for(t=0; t> macro")]; - } else { - children = this.wiki.parseTiddler(tiddler.fields.title).tree; - } - parents = parents.slice(0); - parents.push(tiddler.fields.title); - } else { - children = this.wiki.parseText("text/x-tiddlywiki",value).tree; - } - for(t=0; t> macro")]; + } else { + children = viewMacro.wiki.parseTiddler(tiddler.fields.title).tree; + } + parents = parents.slice(0); + parents.push(tiddler.fields.title); + } else { + children = viewMacro.wiki.parseText("text/x-tiddlywiki",value).tree; + } + // Clone and execute the parsed wikitext + for(t=0; t