From a9a9a745d4e587121043ab8ca35a2d885c091484 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 11 Mar 2025 12:47:01 +0000 Subject: [PATCH] Switch to triple brace syntax for assigning filtered lists --- core/modules/widgets/letlist.js | 4 +-- core/modules/widgets/widget.js | 33 ++++++++++++++++--- .../data/letlist-widget/SelfReference.tid | 4 +-- .../tests/data/letlist-widget/Simple.tid | 2 +- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/core/modules/widgets/letlist.js b/core/modules/widgets/letlist.js index 38d4b6be2..bcc2b6dbf 100644 --- a/core/modules/widgets/letlist.js +++ b/core/modules/widgets/letlist.js @@ -42,12 +42,12 @@ LetListWidget.prototype.computeAttributes = function() { self = this; this.currentValueFor = Object.create(null); $tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(this.parseTreeNode),function(attribute) { - var value = self.computeAttribute(attribute), + var value = self.computeAttribute(attribute,{asList: true}), name = attribute.name; // Now that it's prepped, we're allowed to look this variable up // when defining later variables if(value !== undefined) { - self.currentValueFor[name] = self.wiki.filterTiddlers(value,self); + self.currentValueFor[name] = value; } }); // Run through again, setting variables and looking for differences diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 844f1a35d..ad2ab4c2c 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -388,20 +388,43 @@ Widget.prototype.computeAttributes = function(options) { return changedAttributes; }; -Widget.prototype.computeAttribute = function(attribute) { +/* +Compute the value of a single attribute. Options include: +asList: boolean if true returns results as an array instead of a single value +*/ +Widget.prototype.computeAttribute = function(attribute,options) { + options = options || {}; var self = this, value; if(attribute.type === "filtered") { - value = this.wiki.filterTiddlers(attribute.filter,this)[0] || ""; + value = this.wiki.filterTiddlers(attribute.filter,this); + if(!options.asList) { + value = value[0] || ""; + } } else if(attribute.type === "indirect") { - value = this.wiki.getTextReference(attribute.textReference,"",this.getVariable("currentTiddler")) || ""; + value = this.wiki.getTextReference(attribute.textReference,"",this.getVariable("currentTiddler")); + if(value && options.asList) { + value = [value]; + } } else if(attribute.type === "macro") { var variableInfo = this.getVariableInfo(attribute.value.name,{params: attribute.value.params}); - value = variableInfo.text; + if(variableInfo) { + if(options.asList) { + value = variableInfo.resultList; + } else { + value = variableInfo.text || ""; + } + } } else if(attribute.type === "substituted") { value = this.wiki.getSubstitutedText(attribute.rawValue,this) || ""; + if(options.asList) { + value = [value]; + } } else { // String attribute - value = attribute.value; + value = attribute.value || ""; + if(options.asList) { + value = [value]; + } } return value; }; diff --git a/editions/test/tiddlers/tests/data/letlist-widget/SelfReference.tid b/editions/test/tiddlers/tests/data/letlist-widget/SelfReference.tid index 275e1cbbf..3ad4026b6 100644 --- a/editions/test/tiddlers/tests/data/letlist-widget/SelfReference.tid +++ b/editions/test/tiddlers/tests/data/letlist-widget/SelfReference.tid @@ -6,8 +6,8 @@ tags: [[$:/tags/wiki-test-spec]] title: Output <$letlist - original="[all[tiddlers]sort[]]" - varname="[varlist[original]]" + original={{{ [all[tiddlers]sort[]] }}} + varname={{{ [varlist[original]] }}} > <$text text={{{ [varlist[varname]] +[join[-]] }}}/> diff --git a/editions/test/tiddlers/tests/data/letlist-widget/Simple.tid b/editions/test/tiddlers/tests/data/letlist-widget/Simple.tid index d4cf11cd4..6a31d2189 100644 --- a/editions/test/tiddlers/tests/data/letlist-widget/Simple.tid +++ b/editions/test/tiddlers/tests/data/letlist-widget/Simple.tid @@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]] title: Output -<$letlist varname="[all[tiddlers]sort[]]"> +<$letlist varname={{{ [all[tiddlers]sort[]] }}}> <$text text={{{ [varlist[varname]] +[join[-]] }}}/> +