Revert "extend lookup op flexibility with 2 parameters (#5315)"

This reverts commit 81b5fe944a.

See https://github.com/Jermolene/TiddlyWiki5/pull/5315#issuecomment-848725198 for explanation
publishing-framework
jeremy@jermolene.com 2021-05-26 13:25:19 +01:00
rodzic 903cfd98a6
commit 082aeb92ac
3 zmienionych plików z 17 dodań i 63 usunięć

Wyświetl plik

@ -5,11 +5,9 @@ module-type: filteroperator
Filter operator that looks up values via a title prefix Filter operator that looks up values via a title prefix
[lookup:<defaultvalue>:<field OR index>[<prefix>],[<field-name OR index-name>]] [lookup:<field>[<prefix>]]
Prepends the prefix to the selected items and returns the specified Prepends the prefix to the selected items and returns the specified field value
field or index value. If the 2nd suffix does not exist, it defaults to field.
If the second operand is missing it defaults to "text" for fields, and "0" for indexes
\*/ \*/
(function(){ (function(){
@ -22,35 +20,10 @@ If the second operand is missing it defaults to "text" for fields, and "0" for i
Export our filter function Export our filter function
*/ */
exports.lookup = function(source,operator,options) { exports.lookup = function(source,operator,options) {
var results = [], var results = [];
suffixes = operator.suffixes || [], source(function(tiddler,title) {
defaultSuffix = suffixes[0] ? (suffixes[0][0] || "") : "", results.push(options.wiki.getTiddlerText(operator.operand + title) || operator.suffix || '');
indexSuffix = (suffixes[1] && suffixes[1][0] === "index") ? true : false, });
target;
if(operator.operands.length == 2) {
target = operator.operands[1]
} else {
target = indexSuffix ? "0": "text";
}
if(indexSuffix) {
source(function(tiddler,title) {
var targetTitle = operator.operands[0] + title;
var data = options.wiki.extractTiddlerDataItem(targetTitle,target,defaultSuffix);
results.push(data);
});
} else {
source(function(tiddler,title) {
var targetTitle = operator.operands[0] + title;
var targetTiddler = options.wiki.getTiddler(targetTitle);
if(targetTiddler) {
var value = targetTiddler.getFieldString(target);
if(value == "" && defaultSuffix !== "") {
value = defaultSuffix;
}
results.push(value);
}
});
}
return results; return results;
}; };

Wyświetl plik

@ -1,10 +1,7 @@
created: 20170907144257037 created: 20170907144257037
modified: 20201224034837935 modified: 20170907144559822
title: lookup Operator (Examples) title: lookup Operator (Examples)
type: text/vnd.tiddlywiki 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 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">> <<.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">>
<<.operator-example 3 "[all[tiddlers]has[plugin-type]removeprefix[$:/plugins/tiddlywiki/]lookup:missing-description:field[$:/plugins/tiddlywiki/],[description]]" "Retrieve the description of all plugin-tiddlers that are in the `$:/plugins/tiddlywiki/` namespace.">>
<<.operator-example 4 "OriginalTiddlerPaths +[lookup:missing-index:index[$:/config/],[HelloThere]]" "Lookup the original tiddler path on disk for the [[Hello There]] tiddler.">>
<<.operator-example 5 "OriginalTiddlerPaths +[lookup:missing-index:index[$:/config/],[MissingTiddler]]" "Lookup the original tiddler path on disk for the [[MissingTiddler]] tiddler.">>

Wyświetl plik

@ -1,40 +1,24 @@
caption: lookup caption: lookup
created: 20170907103639431 created: 20170907103639431
modified: 20210116081305739 modified: 20170907144703051
op-input: a [[selection of titles|Title Selection]] op-input: a [[selection of titles|Title Selection]]
op-output: the lookup values corresponding to each lookup tiddler 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. Now accepts 1 or 2 parameters, see below for details op-parameter: prefix applied to input titles to yield title of lookup tiddler from which value is retrieved
op-parameter-name: P, T 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. With a single parameter, the default field is "text" and the default index is "0". If a second parameter is provided, that becomes the target field or index. 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. This operator can now accept a second suffix, see below for details op-suffix: the default value to be used for missing lookups
op-suffix-name: D, I op-suffix-name: D
tags: [[Filter Operators]] tags: [[Filter Operators]]
title: lookup Operator title: lookup Operator
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
<<.from-version "5.1.15">> <<.from-version "5.1.15">>
The action of this operator is as follows with 1 parameter: The action of this operator is as follows:
* Apply the specified prefix to each input tiddler title, yielding a new list of tiddler titles * Apply the specified prefix to each input tiddler title, yielding a new list of tiddler titles
* Transclude the value of the `text` field each of those tiddlers * Transclude the value of each of those tiddlers
** Substitute the default value for missing or empty values ** Substitute the default value for missing or empty tiddlers
* Return the list of values
<<.from-version "5.1.24">>
The action of this operator is as follows with 2 parameters:
If there are two parameters provided, use the second parameter as the target field or index.
<<.note """If there is only one parameter given, the filter checks for a second suffix equal to "index". If this suffix is found, the default target index is "0".
In all other cases, the default target field is "text".""">>
Then:
* Apply the specified prefix to each input tiddler title, yielding a new list of tiddler titles
* Transclude the value of the target field or index
** Substitute the default value for missing or empty values
* Return the list of values * Return the list of values
<<.operator-examples "lookup">> <<.operator-examples "lookup">>