From cd2bc88658fe8e66ad609ad2b1998ce7a4df5a7f Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 21 Feb 2017 15:17:47 +0000 Subject: [PATCH] Add "enlist" operator Fixes #2767 --- core/modules/filters/enlist.js | 33 +++++++++++++++++++ .../tiddlers/enlist Operator (Examples).tid | 8 +++++ editions/tw5.com/tiddlers/enlist Operator.tid | 24 ++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 core/modules/filters/enlist.js create mode 100644 editions/tw5.com/tiddlers/enlist Operator (Examples).tid create mode 100644 editions/tw5.com/tiddlers/enlist Operator.tid diff --git a/core/modules/filters/enlist.js b/core/modules/filters/enlist.js new file mode 100644 index 000000000..c5e67d54c --- /dev/null +++ b/core/modules/filters/enlist.js @@ -0,0 +1,33 @@ +/*\ +title: $:/core/modules/filters/enlist.js +type: application/javascript +module-type: filteroperator + +Filter operator returning its operand parsed as a list + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.enlist = function(source,operator,options) { + var list = $tw.utils.parseStringArray(operator.operand); + 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/enlist Operator (Examples).tid b/editions/tw5.com/tiddlers/enlist Operator (Examples).tid new file mode 100644 index 000000000..a3f9a289a --- /dev/null +++ b/editions/tw5.com/tiddlers/enlist Operator (Examples).tid @@ -0,0 +1,8 @@ +created: 20170221144328467 +modified: 20170221151620898 +tags: [[enlist Operator]] [[Operator Examples]] +title: enlist Operator (Examples) +type: text/vnd.tiddlywiki + +<<.operator-example 1 "[enlist[one two three]addsuffix[!]]">> +<<.operator-example 2 "[enlist{$:/StoryList!!list}]">> diff --git a/editions/tw5.com/tiddlers/enlist Operator.tid b/editions/tw5.com/tiddlers/enlist Operator.tid new file mode 100644 index 000000000..f148edde7 --- /dev/null +++ b/editions/tw5.com/tiddlers/enlist Operator.tid @@ -0,0 +1,24 @@ +caption: enlist +created: 20170221144241063 +modified: 20170221151340420 +op-input: ignored +op-neg-input: a [[selection of titles|Title Selection]] +op-neg-output: those input titles that are <<.em not>> listed in <<.place L>> +op-output: the titles stored as a [[title list|Title List]] at <<.place L>> +op-parameter: a [[title list|Title List]] +op-parameter-name: L +op-purpose: select titles from the operand interpreted as a [[title list|Title List]] +tags: [[Filter Operators]] [[Field Operators]] [[Selection Constructors]] [[Negatable Operators]] +title: enlist Operator +type: text/vnd.tiddlywiki + +<<.tip " Literal filter operands cannot contain square brackets but you can work around the issue by using a variable:">> + +``` +<$set name="myList" value="first [[second with a space]] third"> +<$list filter="[enlist]"> +... +``` + + +<<.operator-examples "enlist">>