1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-04-08 03:36:38 +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) {
var self = this,
inputFilter = operator.operands[0] || "",
output = {input: [],runs: []},
output = {input: [],runs: [], inputFilter: inputFilter},
currentRun;
// Save the input
source(function(tiddler,title) {
@ -29,11 +29,13 @@ exports.inspect = function(source,operator,options) {
var details ={
input: results.toArray(),
prefixName: innerOptions.prefixName,
suffixes: innerOptions.suffixes,
operators: []
};
currentRun = details.operators;
var innerResults = filterRunPrefixFunction.call(null,operationFunction,innerOptions);
innerResults(results,innerSource,innerWidget);
details.output = results.toArray();
output.runs.push(details);
};
},
@ -52,12 +54,14 @@ exports.inspect = function(source,operator,options) {
});
currentRun.push(details);
var innerResults = operatorFunction.apply(null,Array.prototype.slice.call(arguments,1));
details.output = innerResults.slice(0);
return innerResults;
}
}
});
output.output = compiledFilter.call(options.wiki,source,options.widget);
var results = [];
console.log(`Inspected ${JSON.stringify(output,null,4)}`);
results.push(JSON.stringify(output,null,4));
return results;
};

View File

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

View File

@ -15,6 +15,7 @@ type: text/vnd.tiddlywiki
The JSON object contains the following properties:
* `input`: the input titles passed to the filter
* `inputFilter`: the filter being inspected
* `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:
** `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
*** `operands`: an array of string operands 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]]"/>