From 9a386421414aacd23e21bc9cb1a116b905fb39ff Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 28 Nov 2016 19:16:08 +0000 Subject: [PATCH] Add new "order" filter operator --- core/modules/filters/listops.js | 17 +++++++++++++++++ .../tw5.com/tiddlers/filters/order_Operator.tid | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 editions/tw5.com/tiddlers/filters/order_Operator.tid diff --git a/core/modules/filters/listops.js b/core/modules/filters/listops.js index 58f74f092..d7a07b62a 100644 --- a/core/modules/filters/listops.js +++ b/core/modules/filters/listops.js @@ -12,6 +12,23 @@ Filter operators for manipulating the current selection list /*global $tw: false */ "use strict"; +/* +Order a list +*/ +exports.order = function(source,operator,options) { + var results = []; + if(operator.operand.toLowerCase() === "reverse") { + source(function(tiddler,title) { + results.unshift(title); + }); + } else { + source(function(tiddler,title) { + results.push(title); + }); + } + return results; +}; + /* Reverse list */ diff --git a/editions/tw5.com/tiddlers/filters/order_Operator.tid b/editions/tw5.com/tiddlers/filters/order_Operator.tid new file mode 100644 index 000000000..57c240b85 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/order_Operator.tid @@ -0,0 +1,15 @@ +caption: order +created: 20161128185907280 +modified: 20161128191251557 +op-input: a [[selection of titles|Title Selection]] +op-output: the input, with the order reversed if <<.field F>> is the special value `reverse` +op-parameter: Either the string `reverse` or another value +op-parameter-name: F +op-purpose: selectively reverse the input list +tags: [[Filter Operators]] [[Common Operators]] [[Field Operators]] [[Order Operators]] +title: order Operator +type: text/vnd.tiddlywiki + +Either reverses or preserves the order of the input list according to whether the parameter is the special value `reverse`. + +<<.operator-examples "order">>