diff --git a/core/modules/filters/getindex.js b/core/modules/filters/getindex.js new file mode 100644 index 000000000..942596d84 --- /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.extractTiddlerDataItem(tiddler,operator.operand); + if(data) { + results.push(data); + } + }); + } + return results; +}; + +})(); 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..e4b35e733 --- /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: 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 a [[property|DataTiddlers]]" +paramName="P" +output="the values of property <<.place P>> in each of the input titles" +/> + +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