From 570cad1c7f90e685961130918f09a7f9b2951f8c Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sun, 27 Apr 2014 18:45:01 +0100 Subject: [PATCH] Add 'get' filter operator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prompted by @sukima’s work on #586 --- core/modules/filters/get.js | 31 +++++++++++++++++++ .../tiddlers/filters/FilterOperator get.tid | 12 +++++++ 2 files changed, 43 insertions(+) create mode 100644 core/modules/filters/get.js create mode 100644 editions/tw5.com/tiddlers/filters/FilterOperator get.tid diff --git a/core/modules/filters/get.js b/core/modules/filters/get.js new file mode 100644 index 000000000..feae6684e --- /dev/null +++ b/core/modules/filters/get.js @@ -0,0 +1,31 @@ +/*\ +title: $:/core/modules/filters/get.js +type: application/javascript +module-type: filteroperator + +Filter operator for replacing tiddler titles by the value of the field specified in the operand. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.get = function(source,operator,options) { + var results = []; + source(function(tiddler,title) { + if(tiddler) { + var value = tiddler.getFieldString(operator.operand); + if(value) { + results.push(value); + } + } + }); + return results; +}; + +})(); diff --git a/editions/tw5.com/tiddlers/filters/FilterOperator get.tid b/editions/tw5.com/tiddlers/filters/FilterOperator get.tid new file mode 100644 index 000000000..0b79e2287 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/FilterOperator get.tid @@ -0,0 +1,12 @@ +created: 20140426183123179 +modified: 20140426183123179 +tags: filters +title: FilterOperator: get +type: text/vnd.tiddlywiki + +The ''get'' filter operator replaces the titles of the tiddlers in the current list with the values of the field specified by the operand. + +For example: + +|!Filter String |!Description | +|`[all[current]get[draft.of]]` |If the current tiddler is a draft, returns the original tiddler, otherwise returns an empty list |