From 5ea6c9a273405833b6c7911504da876cf5e10986 Mon Sep 17 00:00:00 2001 From: Matt Lauber Date: Thu, 12 Apr 2018 08:21:49 -0400 Subject: [PATCH] Modify the is operator to allow multiple types to be specified. (#2982) * Modify the is operator to allow multiple types to be specified. * Fixed indentation. * Fixed indentation. * Rewritten to maintain input order when multiple filters provided. * Updated documentation. * Update is.tid --- core/modules/filters/is.js | 38 ++++++++++++++----- .../tw5.com/tiddlers/filters/examples/is.tid | 1 + editions/tw5.com/tiddlers/filters/is.tid | 6 ++- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/core/modules/filters/is.js b/core/modules/filters/is.js index 514443a62..99d86597f 100644 --- a/core/modules/filters/is.js +++ b/core/modules/filters/is.js @@ -26,16 +26,9 @@ function getIsFilterOperators() { Export our filter function */ exports.is = function(source,operator,options) { - // Dispatch to the correct isfilteroperator - var isFilterOperators = getIsFilterOperators(); - if(operator.operand) { - var isFilterOperator = isFilterOperators[operator.operand]; - if(isFilterOperator) { - return isFilterOperator(source,operator.prefix,options); - } else { - return [$tw.language.getString("Error/IsFilterOperator")]; - } - } else { + + + if( !operator.operand) { // Return all tiddlers if the operand is missing var results = []; source(function(tiddler,title) { @@ -43,6 +36,31 @@ exports.is = function(source,operator,options) { }); return results; } + + // Get our isfilteroperators + var isFilterOperators = getIsFilterOperators(), + subops = operator.operand.split("+"), + filteredResults = {}, + results = []; + for (var t=0; t> <<.operator-example 6 "[is[shadow]]" "overridden shadow tiddlers">> <<.operator-example 7 "[is[missing]]" "empty because its input contains only tiddlers that exist">> +<<.operator-example 8 "[all[tiddlers+shadows]is[tiddler+shadow]]" "contains the entire input list">> diff --git a/editions/tw5.com/tiddlers/filters/is.tid b/editions/tw5.com/tiddlers/filters/is.tid index fb7f6a26c..214661839 100644 --- a/editions/tw5.com/tiddlers/filters/is.tid +++ b/editions/tw5.com/tiddlers/filters/is.tid @@ -11,7 +11,11 @@ op-parameter-name: C op-output: those input tiddlers that belong to category <<.place C>> op-neg-output: those input tiddlers that do <<.em not>> belong to category <<.place C>> -The parameter <<.place C>> is one of the following fundamental categories: +The parameter <<.place C>> specifies zero or more fundamental categories using the following syntax: + +<$railroad text=""" +[{: ("current" | "missing" |: "orphans" | "shadows" | "tags" | "tiddlers" ) +"+" }] +"""/> |!Category |!Matches any tiddler that... | |^`current` |is the [[current tiddler|Current Tiddler]] |