1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-08 23:03:50 +00:00

Add filter output list to JSON

This commit is contained in:
Jeremy Ruston 2025-04-02 18:01:15 +01:00
parent ddeb4fd6e6
commit 037b4aa227
3 changed files with 36 additions and 1 deletions

View File

@ -15,7 +15,7 @@ Export our filter function
exports.inspect = function(source,operator,options) { exports.inspect = function(source,operator,options) {
var self = this, var self = this,
inputFilter = operator.operands[0] || "", inputFilter = operator.operands[0] || "",
output = {input: [],runs: []}, output = {input: [],runs: [], inputFilter: inputFilter},
currentRun; currentRun;
// Save the input // Save the input
source(function(tiddler,title) { source(function(tiddler,title) {
@ -29,11 +29,13 @@ exports.inspect = function(source,operator,options) {
var details ={ var details ={
input: results.toArray(), input: results.toArray(),
prefixName: innerOptions.prefixName, prefixName: innerOptions.prefixName,
suffixes: innerOptions.suffixes,
operators: [] operators: []
}; };
currentRun = details.operators; currentRun = details.operators;
var innerResults = filterRunPrefixFunction.call(null,operationFunction,innerOptions); var innerResults = filterRunPrefixFunction.call(null,operationFunction,innerOptions);
innerResults(results,innerSource,innerWidget); innerResults(results,innerSource,innerWidget);
details.output = results.toArray();
output.runs.push(details); output.runs.push(details);
}; };
}, },
@ -52,12 +54,14 @@ exports.inspect = function(source,operator,options) {
}); });
currentRun.push(details); currentRun.push(details);
var innerResults = operatorFunction.apply(null,Array.prototype.slice.call(arguments,1)); var innerResults = operatorFunction.apply(null,Array.prototype.slice.call(arguments,1));
details.output = innerResults.slice(0);
return innerResults; return innerResults;
} }
} }
}); });
output.output = compiledFilter.call(options.wiki,source,options.widget); output.output = compiledFilter.call(options.wiki,source,options.widget);
var results = []; var results = [];
console.log(`Inspected ${JSON.stringify(output,null,4)}`);
results.push(JSON.stringify(output,null,4)); results.push(JSON.stringify(output,null,4));
return results; return results;
}; };

View File

@ -31,6 +31,7 @@ title: ExpectedResult
{ {
"input": [], "input": [],
"prefixName": "or", "prefixName": "or",
"suffixes": [],
"operators": [ "operators": [
{ {
"operatorName": "title", "operatorName": "title",
@ -41,8 +42,14 @@ title: ExpectedResult
"$:/core", "$:/core",
"ExpectedResult", "ExpectedResult",
"Output" "Output"
],
"output": [
"1"
] ]
} }
],
"output": [
"1"
] ]
}, },
{ {
@ -50,6 +57,7 @@ title: ExpectedResult
"1" "1"
], ],
"prefixName": "or", "prefixName": "or",
"suffixes": [],
"operators": [ "operators": [
{ {
"operatorName": "title", "operatorName": "title",
@ -60,8 +68,15 @@ title: ExpectedResult
"$:/core", "$:/core",
"ExpectedResult", "ExpectedResult",
"Output" "Output"
],
"output": [
"2"
] ]
} }
],
"output": [
"1",
"2"
] ]
}, },
{ {
@ -70,6 +85,7 @@ title: ExpectedResult
"2" "2"
], ],
"prefixName": "or", "prefixName": "or",
"suffixes": [],
"operators": [ "operators": [
{ {
"operatorName": "title", "operatorName": "title",
@ -80,8 +96,9 @@ title: ExpectedResult
"$:/core", "$:/core",
"ExpectedResult", "ExpectedResult",
"Output" "Output"
] ],
} "output": [
"3"
] ]
} }
], ],
@ -90,4 +107,12 @@ title: ExpectedResult
"2", "2",
"3" "3"
] ]
}
],
"inputFilter": "1 2 3",
"output": [
"1",
"2",
"3"
]
}</p> }</p>

View File

@ -15,6 +15,7 @@ type: text/vnd.tiddlywiki
The JSON object contains the following properties: The JSON object contains the following properties:
* `input`: the input titles passed to the filter * `input`: the input titles passed to the filter
* `inputFilter`: the filter being inspected
* `output`: the output titles resulting from evaluating the filter * `output`: the output titles resulting from evaluating the filter
* `runs`: an array of objects, each of which represents a single run of the filter. Each object contains the following properties: * `runs`: an array of objects, each of which represents a single run of the filter. Each object contains the following properties:
** `prefixName`: the name of the prefix operator that was used in this run ** `prefixName`: the name of the prefix operator that was used in this run
@ -23,4 +24,9 @@ The JSON object contains the following properties:
*** `operatorName`: the name of the operator *** `operatorName`: the name of the operator
*** `operands`: an array of string operands passed to the operator *** `operands`: an array of string operands passed to the operator
*** `input`: the input titles passed to the operator *** `input`: the input titles passed to the operator
*** `output`: the output titles resulting from evaluating the operator
!! Examples
<$transclude $variable="inspect-filter" filter="1 2 3" inputFilter="[all[tiddler]]"/>