mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-27 06:38:19 +00:00
76cdc17f3b
* Support macro params in filter run prefixes and support substitution for variables set by filter run prefixes * feat: add support macro parameters and variable substitution for all filter run prefixes * fix: rename options argument to opts for disambiguation * feat: add support for macro params to cascade filterrun prefix
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
/*\
|
|
title: $:/core/modules/filterrunprefixes/reduce.js
|
|
type: application/javascript
|
|
module-type: filterrunprefix
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
/*
|
|
Export our filter prefix function
|
|
*/
|
|
exports.reduce = function(operationSubFunction,options) {
|
|
return function(results,source,widget) {
|
|
if(results.length > 0) {
|
|
var accumulator = "",
|
|
index = 0;
|
|
results.each(function(title) {
|
|
var list = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{
|
|
getVariable: function(name,opts) {
|
|
opts = opts || {};
|
|
opts.variables = {
|
|
"currentTiddler": "" + title,
|
|
"..currentTiddler": widget.getVariable("currentTiddler"),
|
|
"index": "" + index,
|
|
"revIndex": "" + (results.length - 1 - index),
|
|
"length": "" + results.length,
|
|
"accumulator": "" + accumulator
|
|
};
|
|
if(name in opts.variables) {
|
|
return opts.variables[name];
|
|
} else {
|
|
return widget.getVariable(name,opts);
|
|
}
|
|
}
|
|
});
|
|
if(list.length > 0) {
|
|
accumulator = "" + list[0];
|
|
}
|
|
++index;
|
|
});
|
|
results.clear();
|
|
results.push(accumulator);
|
|
}
|
|
}
|
|
};
|
|
|
|
})();
|