mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-06-24 06:13:17 +00:00
Add new "lookup" filter
This commit is contained in:
parent
1b7d9d65f4
commit
aa417fe899
30
core/modules/filters/lookup.js
Normal file
30
core/modules/filters/lookup.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*\
|
||||||
|
title: $:/core/modules/filters/lookup.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: filteroperator
|
||||||
|
|
||||||
|
Filter operator that looks up values via a title prefix
|
||||||
|
|
||||||
|
[lookup:<field>[<prefix>]]
|
||||||
|
|
||||||
|
Prepends the prefix to the selected items and returns the specified field value
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Export our filter function
|
||||||
|
*/
|
||||||
|
exports.lookup = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push(options.wiki.getTiddlerText(operator.operand + title) || options.wiki.getTiddlerText(operator.operand + operator.suffix));
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
|
@ -82,6 +82,11 @@ describe("Filter tests", function() {
|
||||||
|
|
||||||
// Our tests
|
// Our tests
|
||||||
|
|
||||||
|
it("should handle the lookup operator", function() {
|
||||||
|
expect(wiki.filterTiddlers("Six Seventh 8 +[lookup[Tiddler]]").join(",")).toBe("Missing inaction from TiddlerOne,,Tidd");
|
||||||
|
expect(wiki.filterTiddlers("Six Seventh 8 +[lookup:8[Tiddler]]").join(",")).toBe("Missing inaction from TiddlerOne,Tidd,Tidd");
|
||||||
|
});
|
||||||
|
|
||||||
it("should retrieve shadow tiddlers", function() {
|
it("should retrieve shadow tiddlers", function() {
|
||||||
expect(wiki.getTiddlerText("Tiddler8")).toBe("Tidd");
|
expect(wiki.getTiddlerText("Tiddler8")).toBe("Tidd");
|
||||||
});
|
});
|
||||||
|
|
7
editions/tw5.com/tiddlers/lookup Operator (Examples).tid
Normal file
7
editions/tw5.com/tiddlers/lookup Operator (Examples).tid
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
created: 20170907144257037
|
||||||
|
modified: 20170907144559822
|
||||||
|
title: lookup Operator (Examples)
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.operator-example 1 "[all[shadows+tiddlers]tag[$:/tags/PageControls]lookup[$:/config/PageControlButtons/Visibility/]]" "Retrieve the visibility status of each page control button">>
|
||||||
|
<<.operator-example 2 "[all[shadows+tiddlers]tag[$:/tags/PageControls]lookup:show[$:/config/PageControlButtons/Visibility/]]" "Retrieve the visibility status of each page control button, this time with a default value">>
|
24
editions/tw5.com/tiddlers/lookup Operator.tid
Normal file
24
editions/tw5.com/tiddlers/lookup Operator.tid
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
caption: lookup
|
||||||
|
created: 20170907103639431
|
||||||
|
modified: 20170907144703051
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-output: the lookup values corresponding to each input title
|
||||||
|
op-parameter: prefix applied to input titles to yield title of lookup tiddler from which value is retrieved
|
||||||
|
op-parameter-name: P
|
||||||
|
op-purpose: applies a prefix to each input title to yield the title of a tiddler from which the final value is retrieved
|
||||||
|
op-suffix: the default value to be used for missing lookups
|
||||||
|
op-suffix-name: D
|
||||||
|
tags: [[Filter Operators]]
|
||||||
|
title: lookup Operator
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
<<.from-version "5.1.14">>
|
||||||
|
|
||||||
|
The action of this operator is as follows:
|
||||||
|
|
||||||
|
* Apply the specified prefix to each input tiddler title, yielding a new list of tiddler titles
|
||||||
|
* Transclude the value of each of those tiddlers
|
||||||
|
** Substitute the default value for missing or empty tiddlers
|
||||||
|
* Return the list of values
|
||||||
|
|
||||||
|
<<.operator-examples "lookup">>
|
Loading…
Reference in New Issue
Block a user