Introduce new subfilter operator (#3508)

This commit is contained in:
Jeremy Ruston 2018-11-16 11:27:19 +00:00 committed by GitHub
parent db3f41db29
commit 33dd367a65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 0 deletions

View File

@ -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;
}
};
})();

View File

@ -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}]">>

View File

@ -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<myFilter>]">
...
```
<<.operator-examples "subfilter">>