From 33dd367a6548824567995bb48e87eece755681e8 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 16 Nov 2018 11:27:19 +0000 Subject: [PATCH] Introduce new subfilter operator (#3508) --- core/modules/filters/subfilter.js | 33 +++++++++++++++++++ .../subfilter Operator (Examples).tid | 8 +++++ .../tiddlers/filters/subfilter Operator.tid | 25 ++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 core/modules/filters/subfilter.js create mode 100644 editions/tw5.com/tiddlers/filters/examples/subfilter Operator (Examples).tid create mode 100644 editions/tw5.com/tiddlers/filters/subfilter Operator.tid diff --git a/core/modules/filters/subfilter.js b/core/modules/filters/subfilter.js new file mode 100644 index 000000000..79ae82777 --- /dev/null +++ b/core/modules/filters/subfilter.js @@ -0,0 +1,33 @@ +/*\ +title: $:/core/modules/filters/subfilter.js +type: application/javascript +module-type: filteroperator + +Filter operator returning its operand evaluated as a filter + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.subfilter = function(source,operator,options) { + var list = options.wiki.filterTiddlers(operator.operand,options.widget,source); + if(operator.prefix === "!") { + var results = []; + source(function(tiddler,title) { + if(list.indexOf(title) === -1) { + results.push(title); + } + }); + return results; + } else { + return list; + } +}; + +})(); diff --git a/editions/tw5.com/tiddlers/filters/examples/subfilter Operator (Examples).tid b/editions/tw5.com/tiddlers/filters/examples/subfilter Operator (Examples).tid new file mode 100644 index 000000000..af63b42d2 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/subfilter Operator (Examples).tid @@ -0,0 +1,8 @@ +created: 20181031175129475 +modified: 20181031175129475 +tags: [[subfilter Operator]] [[Operator Examples]] +title: subfilter Operator (Examples) +type: text/vnd.tiddlywiki + +<<.operator-example 1 "[subfilter[one two three]addsuffix[!]]">> +<<.operator-example 2 "[subfilter{$:/StoryList!!list}]">> diff --git a/editions/tw5.com/tiddlers/filters/subfilter Operator.tid b/editions/tw5.com/tiddlers/filters/subfilter Operator.tid new file mode 100644 index 000000000..ec201fc85 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/subfilter Operator.tid @@ -0,0 +1,25 @@ +caption: subfilter +created: 20181031175129475 +modified: 20181031175129475 +op-input: a [[selection of titles|Title Selection]] passed as input to the subfilter +op-neg-input: a [[selection of titles|Title Selection]] passed as input to the subfilter +op-neg-output: those input titles that are <<.em not>> returned from the subfilter <<.place S>> +op-output: the [[selection of titles|Title Selection]] returned from the subfilter <<.place S>> +op-parameter: a [[filter expression|Filter Expression]] +op-parameter-name: S +op-purpose: select titles from the operand interpreted as a [[filter expression|Filter Expression]] +tags: [[Filter Operators]] [[Field Operators]] [[Selection Constructors]] [[Negatable Operators]] +title: subfilter Operator +type: text/vnd.tiddlywiki + +<<.from-version "5.1.18">> Note that the subfilter operator was introduced in version 5.1.18 and is not available in earlier versions. + +<<.tip " Literal filter operands cannot contain square brackets but you can work around the issue by using a variable:">> + +``` +<$set name="myFilter" value="[tag[one]]"> +<$list filter="[all[tiddlers]subfilter]"> +... +``` + +<<.operator-examples "subfilter">>