1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +00:00

Merge pull request #1452 from tobibeer/getIndex-filter

getIndex filter
This commit is contained in:
Jeremy Ruston 2015-02-07 11:53:07 +00:00
commit 68930f333a
3 changed files with 56 additions and 0 deletions

View File

@ -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;
};
})();

View File

@ -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">>

View File

@ -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">>