mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-01 16:13:00 +00:00
Extends :map filter run prefix to provide missing variables (#6149)
* Extends :map filter run prefix to provide the variables index, revIndex and length to bring it into line with :reduce * update :maps examples * docs: fix formatting issue with documentation
This commit is contained in:
@@ -15,7 +15,8 @@ Export our filter prefix function
|
||||
exports.map = function(operationSubFunction,options) {
|
||||
return function(results,source,widget) {
|
||||
if(results.length > 0) {
|
||||
var inputTitles = results.toArray();
|
||||
var inputTitles = results.toArray(),
|
||||
index = 0;
|
||||
results.clear();
|
||||
$tw.utils.each(inputTitles,function(title) {
|
||||
var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{
|
||||
@@ -25,12 +26,19 @@ exports.map = function(operationSubFunction,options) {
|
||||
return "" + title;
|
||||
case "..currentTiddler":
|
||||
return widget.getVariable("currentTiddler");
|
||||
case "index":
|
||||
return "" + index;
|
||||
case "revIndex":
|
||||
return "" + (inputTitles.length - 1 - index);
|
||||
case "length":
|
||||
return "" + inputTitles.length;
|
||||
default:
|
||||
return widget.getVariable(name);
|
||||
}
|
||||
}
|
||||
});
|
||||
results.push(filtered[0] || "");
|
||||
++index;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user