From 103f4f6637238d48a0a14922efd203ecc7f19230 Mon Sep 17 00:00:00 2001 From: Stephan Hradek Date: Sat, 4 Jan 2014 00:01:17 +0100 Subject: [PATCH] added some more filters --- core/modules/filters/listops.js | 37 +++++++++++++++++++ .../tiddlers/concepts/TiddlerFilters.tid | 6 +++ 2 files changed, 43 insertions(+) diff --git a/core/modules/filters/listops.js b/core/modules/filters/listops.js index 8d22b052f..2c8e36631 100644 --- a/core/modules/filters/listops.js +++ b/core/modules/filters/listops.js @@ -76,4 +76,41 @@ exports.rest = function(source,operator,options) { return results; }; +exports.butfirst = exports.rest; +exports.bf = exports.rest; + +exports.butlast = function(source,operator,options) { + var results = []; + var count = operator.operand || 1; + // Iterate through the source tiddlers + if($tw.utils.isArray(source)) { + results = source.slice(0,-count); + } else { + for(var title in source) { + results.push(title); + }; + results = results.slice(0,-count); + } + return results; +}; +exports.bl = exports.butlast; + +exports.nth = function(source,operator,options) { + var results = []; + var count = operator.operand || 1; + // Iterate through the source tiddlers + if($tw.utils.isArray(source)) { + results = source.slice(count-1,count); + } else { + for(var title in source) { + --count; + if(count > 0) continue; + if(count < 0) break; + results.push(title); + break; + }; + } + return results; +}; + })(); diff --git a/editions/tw5.com/tiddlers/concepts/TiddlerFilters.tid b/editions/tw5.com/tiddlers/concepts/TiddlerFilters.tid index 00d3f0dc0..36ce724ed 100644 --- a/editions/tw5.com/tiddlers/concepts/TiddlerFilters.tid +++ b/editions/tw5.com/tiddlers/concepts/TiddlerFilters.tid @@ -61,6 +61,12 @@ A filter string consists of one or more runs of filter operators that each look * ''first'': selects the first tiddler of the list (or the first n if the operand is n) * ''last'': selects the last tiddler of the list (or the last n if the operand is n) * ''rest'': selects all but the first tiddler of the list (or all but the first n if the operand is n) +* ''butfirst'': synonym for ''rest'' +* ''bf'': another synonym for ''rest'' +* ''butlast'': selects all but the last tiddler of the list (or all but the last n if the operand is n) +* ''bl'': another synonym for ''butlast'' +* ''nth'': selects the n-th tiddler of the list. Defaults to n = 1. + An operator can be negated with by preceding it with `!`, for example `[!tag[Tommy]]` selects the tiddlers that are not tagged with `Tommy`.