1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-30 17:23:16 +00:00

Add 'indexes' filter operator

Returns the indexes within a data tiddler.

We’re about to use this to enumerate the colours within a palette.
This commit is contained in:
Jermolene 2014-02-20 10:00:13 +00:00
parent 2744671211
commit 5417b8c4d7
2 changed files with 46 additions and 3 deletions

View File

@ -0,0 +1,43 @@
/*\
title: $:/core/modules/filters/indexes.js
type: application/javascript
module-type: filteroperator
Filter operator for returning the indexes of a data tiddler
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.indexes = function(source,operator,options) {
var self = this,
results = [];
// Function to check an individual title
function checkTiddler(title) {
// Return the fields on the specified tiddler
var data = options.wiki.getTiddlerData(title,{});
if(data) {
$tw.utils.pushTop(results,Object.keys(data));
}
}
// 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);
});
}
results.sort();
return results;
};
})();

View File

@ -1,5 +1,5 @@
created: 20130827080000000
modified: 20140210141253282
modified: 20140220091253282
tags: concepts
title: TiddlerFilters
type: text/vnd.tiddlywiki
@ -67,8 +67,8 @@ A filter string consists of one or more runs of filter operators that each look
* ''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.
* ''nth'': selects the n-th tiddler of the list. Defaults to n = 1
* ''indexes'': selects the names of the indexes within a [[DataTiddler|DataTiddlers]]
An operator can be negated with by preceding it with `!`, for example `[!tag[Tommy]]` selects the tiddlers that are not tagged with `Tommy`.