From 392e717497545353d7a89d887763db1115008e15 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 29 Mar 2012 14:30:22 +0100 Subject: [PATCH] Refactored handling of context tiddler Now the title is passed around, rather than a reference to the tiddler. This lets the context be a missing tiddler, enabling us to correctly render missing tiddlers --- js/Renderer.js | 18 ++++++++++-------- js/WikiStore.js | 4 ++-- js/macros/chooser.js | 2 +- js/macros/link.js | 2 +- js/macros/list.js | 2 +- js/macros/slider.js | 4 ++-- js/macros/story.js | 4 ++-- js/macros/tiddler.js | 2 +- js/macros/view.js | 20 +++++++++++++------- js/macros/zoomer.js | 8 ++++---- 10 files changed, 37 insertions(+), 29 deletions(-) diff --git a/js/Renderer.js b/js/Renderer.js index d5378facf..32674c7ce 100644 --- a/js/Renderer.js +++ b/js/Renderer.js @@ -207,9 +207,13 @@ MacroNode.prototype.cloneChildren = function() { return childClones; }; -MacroNode.prototype.execute = function(parents,tiddler) { +MacroNode.prototype.execute = function(parents,tiddlerTitle) { // Evaluate macro parameters to get their values this.params = {}; + var tiddler = this.store.getTiddler(tiddlerTitle); + if(!tiddler) { + tiddler = {title: tiddlerTitle}; + } for(var p in this.srcParams) { if(typeof this.srcParams[p] === "function") { this.params[p] = this.srcParams[p](tiddler,this.store,utils); @@ -218,7 +222,7 @@ MacroNode.prototype.execute = function(parents,tiddler) { } } // Save the context tiddler - this.tiddlerTitle = tiddler ? tiddler.title : null; + this.tiddlerTitle = tiddlerTitle; // Save a reference to the array of parents this.parents = parents || []; // Render the macro to get its content @@ -261,8 +265,7 @@ MacroNode.prototype.refresh = function(changes) { // Check if any of the dependencies of this macro node have changed if(this.dependencies.hasChanged(changes)) { // Re-execute the macro if so - var tiddler = this.store.getTiddler(this.tiddlerTitle); - this.execute(this.parents,tiddler); + this.execute(this.parents,this.tiddlerTitle); } else { // Refresh any children for(t=0; t