mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-08 06:43:49 +00:00
Add apply filter run prefix
The map filter run prefix is often used as a way to move a computed value in the input list into a variable so that it can be used as a parameter of a filter operator. The apply filter run prefix extends this idea to make the input list available as variables $1, $2 etc. Unlike the map prefix, the apply filter run is only evaluated once.
This commit is contained in:
parent
28935a5856
commit
611adadaed
29
core/modules/filterrunprefixes/apply.js
Normal file
29
core/modules/filterrunprefixes/apply.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/filterrunprefixes/apply.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: filterrunprefix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.apply = function(operationSubFunction) {
|
||||||
|
return function(results,source,widget) {
|
||||||
|
source = widget.wiki.makeTiddlerIterator([]);
|
||||||
|
var variables = {},
|
||||||
|
counter = 1;
|
||||||
|
results.each(function(title) {
|
||||||
|
variables["$" + counter] = title;
|
||||||
|
counter++;
|
||||||
|
});
|
||||||
|
results.clear();
|
||||||
|
results.pushTop(operationSubFunction(source,widget.makeFakeWidgetWithVariables(variables)));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -0,0 +1,13 @@
|
|||||||
|
title: Filters/FilterRunPrefixes/Applu
|
||||||
|
description: Applu filter run prefix
|
||||||
|
type: text/vnd.tiddlywiki-multiple
|
||||||
|
tags: [[$:/tags/wiki-test-spec]]
|
||||||
|
|
||||||
|
title: Output
|
||||||
|
|
||||||
|
\whitespace trim
|
||||||
|
<$text text={{{ a b c :apply[<$1>addsuffix<$2>addsuffix<$3>] }}}/>
|
||||||
|
+
|
||||||
|
title: ExpectedResult
|
||||||
|
|
||||||
|
<p>abc</p>
|
Loading…
x
Reference in New Issue
Block a user