From b72afda7a2ccedda1f5bdca1fe41da634ca6b134 Mon Sep 17 00:00:00 2001 From: David Johnston Date: Sun, 22 Sep 2013 09:57:23 +0100 Subject: [PATCH 1/5] Next in List filter --- core/modules/filters/next.js | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 core/modules/filters/next.js diff --git a/core/modules/filters/next.js b/core/modules/filters/next.js new file mode 100644 index 000000000..22c80cc03 --- /dev/null +++ b/core/modules/filters/next.js @@ -0,0 +1,43 @@ +/*\ +title: $:/core/modules/filters/next.js +type: application/javascript +module-type: filteroperator + +Filter operator returning the tiddler whose title occurs next in the list supplied in the operand tiddler + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.next = function(source,operator,options) { + var results = [], + list = options.wiki.getTiddlerList(operator.operand); + + function checkTiddler(title) { + var match = list.indexOf(title); + // increment match and then test if result is in range + match++; + if(match > 0 && match < list.length) { + results.push(list[match]); + } + } + // Iterate through the source tiddlers + if($tw.utils.isArray(source)) { + $tw.utils.each(source,function(title) { + checkTiddler(title); + }); + } else { + $tw.utils.each(source,function(element,title) { + checkTiddler(title); + }); + } + return results; +}; + +})(); From f0b6790ae13de1e53548bc9ed42430f70b480043 Mon Sep 17 00:00:00 2001 From: David Johnston Date: Sun, 22 Sep 2013 09:58:18 +0100 Subject: [PATCH 2/5] Previous in list filter. --- core/modules/filters/previous.js | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 core/modules/filters/previous.js diff --git a/core/modules/filters/previous.js b/core/modules/filters/previous.js new file mode 100644 index 000000000..cc536b8af --- /dev/null +++ b/core/modules/filters/previous.js @@ -0,0 +1,43 @@ +/*\ +title: $:/core/modules/filters/previous.js +type: application/javascript +module-type: filteroperator + +Filter operator returning the tiddler whose title occurs immediately prior in the list supplied in the operand tiddler + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.previous = function(source,operator,options) { + var results = [], + list = options.wiki.getTiddlerList(operator.operand); + + function checkTiddler(title) { + var match = list.indexOf(title); + // decrement match and then test if result is in range + match--; + if( match >= 0 ) { + results.push(list[match]); + } + } + // Iterate through the source tiddlers + if($tw.utils.isArray(source)) { + $tw.utils.each(source,function(title) { + checkTiddler(title); + }); + } else { + $tw.utils.each(source,function(element,title) { + checkTiddler(title); + }); + } + return results; +}; + +})(); From 8127662f77dec62b484340870b490850edda9028 Mon Sep 17 00:00:00 2001 From: David Johnston Date: Sun, 22 Sep 2013 10:02:40 +0100 Subject: [PATCH 3/5] Tests added for the Next and Previous Filters. --- editions/test/tiddlers/tests/test-filters.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index fe32ea72b..42c8767e8 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -148,6 +148,16 @@ describe("Filter tests", function() { expect(wiki.filterTiddlers("[tag[one]list[TiddlerSeventh]sort[title]]").join(",")).toBe("Tiddler Three,TiddlerOne"); }); + it("should handle the next operator", function() { + expect(wiki.filterTiddlers("[[Tiddler Three]next[TiddlerSeventh]]").join(",")).toBe("a fourth tiddler"); + expect(wiki.filterTiddlers("[[MissingTiddler]next[TiddlerSeventh]]").join(",")).toBe(""); + }); + + it("should handle the previous operator", function() { + expect(wiki.filterTiddlers("[[Tiddler Three]previous[iddlerSeventh]]").join(",")).toBe("TiddlerOne"); + expect(wiki.filterTiddlers("[[TiddlerOne]previous[TiddlerSeventh]]").join(",")).toBe(""); + }); + it("should handle the search operator", function() { expect(wiki.filterTiddlers("[search[the]sort[title]]").join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,one,Tiddler Three,TiddlerOne"); expect(wiki.filterTiddlers("[search{Tiddler8}sort[title]]").join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,one,Tiddler Three,TiddlerOne"); From afa5156db972d2ded7fed8f2805b4cf0c77af272 Mon Sep 17 00:00:00 2001 From: David Johnston Date: Sun, 22 Sep 2013 10:09:22 +0100 Subject: [PATCH 4/5] Added Next and Previous to filters concept tiddler. --- editions/tw5.com/tiddlers/concepts/TiddlerFilters.tid | 2 ++ 1 file changed, 2 insertions(+) diff --git a/editions/tw5.com/tiddlers/concepts/TiddlerFilters.tid b/editions/tw5.com/tiddlers/concepts/TiddlerFilters.tid index 1e74fa99f..2976427f4 100644 --- a/editions/tw5.com/tiddlers/concepts/TiddlerFilters.tid +++ b/editions/tw5.com/tiddlers/concepts/TiddlerFilters.tid @@ -48,6 +48,8 @@ A filter string consists of one or more runs of filter operators that each look * ''links'': selects the outgoing links on the currently selected tiddlers * ''backlinks'': selects the tiddlers that link to the currently selected tiddlers * ''list'': selects the tiddlers listed in a specified [[TiddlerList|TiddlerLists]] +* ''next'': selects the next item in a TiddlerList after the current tiddler +* ''previous'': selects the previous item in a TiddlerList before the current tiddler * ''listed'': selects the TiddlerLists that include the current tiddler * ''each'': selects one tiddler for each discrete value of the specified field * ''eachday'': selects one tiddler for each discrete day in the specified date field From 904a079432dbea57c0be03008a9036d68b14ed1e Mon Sep 17 00:00:00 2001 From: David Johnston Date: Sun, 22 Sep 2013 21:17:46 +0100 Subject: [PATCH 5/5] Variable name corrected. --- editions/test/tiddlers/tests/test-filters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index 42c8767e8..19d74f35e 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -154,7 +154,7 @@ describe("Filter tests", function() { }); it("should handle the previous operator", function() { - expect(wiki.filterTiddlers("[[Tiddler Three]previous[iddlerSeventh]]").join(",")).toBe("TiddlerOne"); + expect(wiki.filterTiddlers("[[Tiddler Three]previous[TiddlerSeventh]]").join(",")).toBe("TiddlerOne"); expect(wiki.filterTiddlers("[[TiddlerOne]previous[TiddlerSeventh]]").join(",")).toBe(""); });