1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +00:00

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
This commit is contained in:
Matt Lauber 2018-04-12 08:21:49 -04:00 committed by Jeremy Ruston
parent 2163302190
commit 5ea6c9a273
3 changed files with 34 additions and 11 deletions

View File

@ -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<subops.length; t++) {
var subop = isFilterOperators[subops[t]];
if(subop) {
filteredResults[subops[t]] = subop(source,operator.prefix,options);
} else {
return [$tw.language.getString("Error/IsFilterOperator")];
}
}
source(function(tiddler,title) {
for (var t=0; t<subops.length; t++) {
if (filteredResults[subops[t]].indexOf(title) != -1){
results.push(title);
break;
}
}
});
return results;
};
})();

View File

@ -11,3 +11,4 @@ type: text/vnd.tiddlywiki
<<.operator-example 5 "[all[shadows]is[system]tag[$:/tags/Stylesheet]]" "shadow system stylesheets">>
<<.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">>

View File

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