mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-06-22 08:24:06 +00:00
Switch to triple brace syntax for assigning filtered lists
This commit is contained in:
parent
4cfa758d51
commit
a9a9a745d4
@ -42,12 +42,12 @@ LetListWidget.prototype.computeAttributes = function() {
|
|||||||
self = this;
|
self = this;
|
||||||
this.currentValueFor = Object.create(null);
|
this.currentValueFor = Object.create(null);
|
||||||
$tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(this.parseTreeNode),function(attribute) {
|
$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;
|
name = attribute.name;
|
||||||
// Now that it's prepped, we're allowed to look this variable up
|
// Now that it's prepped, we're allowed to look this variable up
|
||||||
// when defining later variables
|
// when defining later variables
|
||||||
if(value !== undefined) {
|
if(value !== undefined) {
|
||||||
self.currentValueFor[name] = self.wiki.filterTiddlers(value,self);
|
self.currentValueFor[name] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Run through again, setting variables and looking for differences
|
// Run through again, setting variables and looking for differences
|
||||||
|
@ -388,20 +388,43 @@ Widget.prototype.computeAttributes = function(options) {
|
|||||||
return changedAttributes;
|
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,
|
var self = this,
|
||||||
value;
|
value;
|
||||||
if(attribute.type === "filtered") {
|
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") {
|
} 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") {
|
} else if(attribute.type === "macro") {
|
||||||
var variableInfo = this.getVariableInfo(attribute.value.name,{params: attribute.value.params});
|
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") {
|
} else if(attribute.type === "substituted") {
|
||||||
value = this.wiki.getSubstitutedText(attribute.rawValue,this) || "";
|
value = this.wiki.getSubstitutedText(attribute.rawValue,this) || "";
|
||||||
|
if(options.asList) {
|
||||||
|
value = [value];
|
||||||
|
}
|
||||||
} else { // String attribute
|
} else { // String attribute
|
||||||
value = attribute.value;
|
value = attribute.value || "";
|
||||||
|
if(options.asList) {
|
||||||
|
value = [value];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
@ -6,8 +6,8 @@ tags: [[$:/tags/wiki-test-spec]]
|
|||||||
title: Output
|
title: Output
|
||||||
|
|
||||||
<$letlist
|
<$letlist
|
||||||
original="[all[tiddlers]sort[]]"
|
original={{{ [all[tiddlers]sort[]] }}}
|
||||||
varname="[varlist[original]]"
|
varname={{{ [varlist[original]] }}}
|
||||||
>
|
>
|
||||||
<$text text={{{ [varlist[varname]] +[join[-]] }}}/>
|
<$text text={{{ [varlist[varname]] +[join[-]] }}}/>
|
||||||
</$letlist>
|
</$letlist>
|
||||||
|
@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]]
|
|||||||
|
|
||||||
title: Output
|
title: Output
|
||||||
|
|
||||||
<$letlist varname="[all[tiddlers]sort[]]">
|
<$letlist varname={{{ [all[tiddlers]sort[]] }}}>
|
||||||
<$text text={{{ [varlist[varname]] +[join[-]] }}}/>
|
<$text text={{{ [varlist[varname]] +[join[-]] }}}/>
|
||||||
</$letlist>
|
</$letlist>
|
||||||
+
|
+
|
||||||
|
Loading…
x
Reference in New Issue
Block a user