From 8b771555a56ec9e6a4bcd2ad0b5a19181f4cc063 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Wed, 28 Jan 2015 22:15:52 +0100 Subject: [PATCH 1/5] initial commit Is `wiki.parseTextReference()` the appropriate way? --- core/modules/filters/getIndex.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 core/modules/filters/getIndex.js diff --git a/core/modules/filters/getIndex.js b/core/modules/filters/getIndex.js new file mode 100644 index 000000000..1d3dd0224 --- /dev/null +++ b/core/modules/filters/getIndex.js @@ -0,0 +1,32 @@ +/*\ +title: $:/core/modules/filters/getIndex.js +type: application/javascript +module-type: filteroperator + +returns the value at a given index of datatiddlers + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.getIndex = function(source,operator,options) { + var data,title,results = []; + if(operator.operand){ + source(function(tiddler,title) { + title = tiddler ? tiddler.fields.title : title; + data = options.wiki.parseTextReference(title,"",operator.operand,{}); + if(data) { + results.push(data.source); + } + }); + } + return results; +}; + +})(); From 8746e1ede0420ad44bb66f74e7f100b476016078 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Tue, 3 Feb 2015 14:50:16 +0100 Subject: [PATCH 2/5] renamed and documentation * renamed to all lowercase * added documentation * added examples --- .../filters/{getIndex.js => get_index.js} | 2 +- .../tiddlers/filters/examples/getindex.tid | 7 +++++++ editions/tw5.com/tiddlers/filters/getindex.tid | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) rename core/modules/filters/{getIndex.js => get_index.js} (93%) create mode 100644 editions/tw5.com/tiddlers/filters/examples/getindex.tid create mode 100644 editions/tw5.com/tiddlers/filters/getindex.tid diff --git a/core/modules/filters/getIndex.js b/core/modules/filters/get_index.js similarity index 93% rename from core/modules/filters/getIndex.js rename to core/modules/filters/get_index.js index 1d3dd0224..737175743 100644 --- a/core/modules/filters/getIndex.js +++ b/core/modules/filters/get_index.js @@ -1,5 +1,5 @@ /*\ -title: $:/core/modules/filters/getIndex.js +title: $:/core/modules/filters/getindex.js type: application/javascript module-type: filteroperator diff --git a/editions/tw5.com/tiddlers/filters/examples/getindex.tid b/editions/tw5.com/tiddlers/filters/examples/getindex.tid new file mode 100644 index 000000000..b0512507b --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/getindex.tid @@ -0,0 +1,7 @@ +created: 20150203140000000 +modified: 20150203140000000 +tags: [[getindex Operator]] [[Operator Examples]] +title: getindex Operator (Examples) + +<<.operator-example 1 "[[$:/palettes/Vanilla]getindex[background]]" "returns the value at index ''background'' of the [[DataTiddler|DataTiddlers]] [[$:/palettes/Vanilla]]">> +<<.operator-example 2 "[tag[$:/tags/Palette]getindex[background]]" "returns all background colors defined in any of the ColourPalettes">> \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/filters/getindex.tid b/editions/tw5.com/tiddlers/filters/getindex.tid new file mode 100644 index 000000000..1401af280 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/getindex.tid @@ -0,0 +1,17 @@ +created: 20150203140000000 +modified: 20150203140000000 +tags: [[Filter Operators]] [[Field Operators]] +title: getindex Operator +caption: getindex +purpose: returns the value at an index of DataTiddlers + +<$macrocall $name=".operator-def" +input="a [[selection of titles|Title Selection]]" +parameter="the name of an [[index|DataTiddlers]]" +paramName="i" +output="the values at index <<.place f>> in each of the input titles" +/> + +Each input title is tested in turn. If the corresponding tiddler is a [[DataTiddler|DataTiddlers]] and has the index <<.place i>> defined, its value is appended to the output. + +<<.operator-examples "getindex">> \ No newline at end of file From a8a0d0d09ef8f9c6babf6b952798cf74c07b70ef Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Tue, 3 Feb 2015 14:50:37 +0100 Subject: [PATCH 3/5] renaming in one go didn't work --- core/modules/filters/{get_index.js => getindex.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/modules/filters/{get_index.js => getindex.js} (100%) diff --git a/core/modules/filters/get_index.js b/core/modules/filters/getindex.js similarity index 100% rename from core/modules/filters/get_index.js rename to core/modules/filters/getindex.js From 726ccdee4996c74630e686cf2387b0611a234b42 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Wed, 4 Feb 2015 01:41:50 +0100 Subject: [PATCH 4/5] updated documentation thanks, @aelocson --- editions/tw5.com/tiddlers/filters/getindex.tid | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/editions/tw5.com/tiddlers/filters/getindex.tid b/editions/tw5.com/tiddlers/filters/getindex.tid index 1401af280..e4b35e733 100644 --- a/editions/tw5.com/tiddlers/filters/getindex.tid +++ b/editions/tw5.com/tiddlers/filters/getindex.tid @@ -3,15 +3,15 @@ modified: 20150203140000000 tags: [[Filter Operators]] [[Field Operators]] title: getindex Operator caption: getindex -purpose: returns the value at an index of DataTiddlers +purpose: select all values of a data property in the input titles <$macrocall $name=".operator-def" input="a [[selection of titles|Title Selection]]" -parameter="the name of an [[index|DataTiddlers]]" -paramName="i" -output="the values at index <<.place f>> in each of the input titles" +parameter="the name of a [[property|DataTiddlers]]" +paramName="P" +output="the values of property <<.place P>> in each of the input titles" /> -Each input title is tested in turn. If the corresponding tiddler is a [[DataTiddler|DataTiddlers]] and has the index <<.place i>> defined, its value is appended to the output. +Each input title is processed in turn, and is ignored if it does not denote a [[data tiddler|DataTiddlers]]. If the tiddler contains property <<.place P>>, the value of that property is [[dominantly appended|Dominant Append]] to the output. <<.operator-examples "getindex">> \ No newline at end of file From 7ed5c3ccfc5c264c3b0e2fcc3dc079ca8c972914 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Wed, 4 Feb 2015 01:49:31 +0100 Subject: [PATCH 5/5] use extractTiddlerDataItem not parseTextReference --- core/modules/filters/getindex.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/modules/filters/getindex.js b/core/modules/filters/getindex.js index 737175743..942596d84 100644 --- a/core/modules/filters/getindex.js +++ b/core/modules/filters/getindex.js @@ -20,9 +20,9 @@ exports.getIndex = function(source,operator,options) { if(operator.operand){ source(function(tiddler,title) { title = tiddler ? tiddler.fields.title : title; - data = options.wiki.parseTextReference(title,"",operator.operand,{}); + data = options.wiki.extractTiddlerDataItem(tiddler,operator.operand); if(data) { - results.push(data.source); + results.push(data); } }); }