From ca0c3522785826e6a638e90340677b51dead7b9b Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 12 Feb 2014 21:38:37 +0000 Subject: [PATCH] Extend the transclude widget to fallback to displaying it's child nodes if the target isn't defined --- core/modules/widgets/transclude.js | 2 +- core/modules/wiki.js | 9 ++++++--- editions/tw5.com/tiddlers/widgets/TranscludeWidget.tid | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index e367fd07b..2494f3b63 100755 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -62,7 +62,7 @@ TranscludeWidget.prototype.execute = function() { this.transcludeField, this.transcludeIndex, {parseAsInline: parseAsInline}), - parseTreeNodes = parser ? parser.tree : []; + parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children; // Construct the child widgets this.makeChildWidgets(parseTreeNodes); }; diff --git a/core/modules/wiki.js b/core/modules/wiki.js index a4c9fbb38..1f55d61f5 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -789,13 +789,16 @@ exports.parseTextReference = function(title,field,index,options) { var tiddler,text; if(field) { tiddler = this.getTiddler(title); - text = tiddler ? tiddler.fields[field] : ""; - if(text === undefined) { - text = ""; + if(!tiddler || !tiddler.hasField(field)) { + return null; } + text = tiddler.fields[field]; return this.parseText("text/vnd.tiddlywiki",text.toString(),options); } else if(index) { text = this.extractTiddlerDataItem(title,index,""); + if(text === undefined) { + return null; + } return this.parseText("text/vnd.tiddlywiki",text,options); } } diff --git a/editions/tw5.com/tiddlers/widgets/TranscludeWidget.tid b/editions/tw5.com/tiddlers/widgets/TranscludeWidget.tid index 24fc2d0aa..28209cc28 100644 --- a/editions/tw5.com/tiddlers/widgets/TranscludeWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/TranscludeWidget.tid @@ -19,7 +19,7 @@ The TranscludeWidget dynamically imports content from another tiddler. |tooltip |Tooltip to be added to the generated elements | |mode |Override the default parsing mode for the transcluded text to "block" or "inline" | -The TranscludeWidget ignores any contained content. +The TranscludeWidget treats any contained content as a fallback if the target of the transclusion is not defined (ie a missing tiddler or a missing field). ! Parsing modes