From cd0f8ebb52f8a7e06d8db376a2fa3dbf1d944f73 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 29 Mar 2012 13:44:45 +0100 Subject: [PATCH] Improving the handling of missing tiddlers On the way to being able to edit tiddlers --- js/macros/tiddler.js | 18 +++++--- js/macros/view.js | 102 +++++++++++++++++++++++++------------------ 2 files changed, 72 insertions(+), 48 deletions(-) diff --git a/js/macros/tiddler.js b/js/macros/tiddler.js index 7f264a2e6..4d25e03eb 100644 --- a/js/macros/tiddler.js +++ b/js/macros/tiddler.js @@ -53,20 +53,24 @@ exports.macro = { "with": {byName: true, type: "text", dependentAll: true} }, execute: function() { - var tiddler = this.store.getTiddler(this.tiddlerTitle), - renderTitle = this.params.target, + var renderTitle = this.params.target, renderTemplate = this.params.template, content, contentClone = [], t, parents = this.parents.slice(0); + // If there's no render title specified then use the current tiddler title if(typeof renderTitle !== "string") { - renderTitle = tiddler.title; + renderTitle = this.tiddlerTitle; } + // If there's no template specified then use the target tiddler title if(typeof renderTemplate !== "string") { renderTemplate = renderTitle; } - if(parents.indexOf(renderTemplate) === -1) { + // Check for recursion + if(parents.indexOf(renderTemplate) !== -1) { + content = [Renderer.ErrorNode("Tiddler recursion error in <> macro")]; + } else { if("with" in this.params) { // Parameterised transclusion var targetTiddler = this.store.getTiddler(renderTemplate), @@ -82,16 +86,18 @@ exports.macro = { var parseTree = this.store.parseTiddler(renderTemplate); content = parseTree ? parseTree.nodes : []; } - } else { - content = [Renderer.ErrorNode("Tiddler recursion error in <> macro")]; } + // Update the stack of tiddler titles for recursion detection parents.push(renderTemplate); + // Clone the content for(t=0; t> macro")]; - } - parents = parents.slice(0); - parents.push(tiddler.title); - } else { - content = this.store.parseText("text/x-tiddlywiki",v).nodes; - } - for(t=0; t> macro")]; + } else { + content = this.store.parseTiddler(tiddler.title).nodes; + } + parents = parents.slice(0); + parents.push(tiddler.title); + } else { + content = this.store.parseText("text/x-tiddlywiki",value).nodes; + } + for(t=0; t