From 3801e2536cb1adf4ff1077f06e3d98862868b2bc Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 14 Apr 2025 10:58:40 +0100 Subject: [PATCH] Reorganise tiddlers Some of the titles were not consistent --- .../config/AdvancedSearchFilterDefaultTab.tid | 2 - .../tiddlers/system/DefaultTiddlers.tid | 8 ++-- .../tiddlers/system/DefaultTiddlers.tid | 8 ++-- .../internals/cascades/viewtemplatebody.tid | 5 --- plugins/tiddlywiki/internals/config.tid | 2 +- .../InspectResultsTab.tid | 2 +- .../docs}/InspectFilterMacro.tid | 6 +-- .../docs}/inspect Operator.tid | 16 +++---- .../docs}/inspect-filter Macro (Examples).tid | 5 +-- .../{ => filterinspection}/inspect-filter.tid | 2 +- .../{ => filterinspection}/modules/inspect.js | 2 +- .../{ => filterinspection}/modules/startup.js | 44 ++++++++++++++++--- .../{ => filterinspection}/styles.tid | 2 +- .../tests/wikitext/Simple.tid | 2 +- .../viewtemplatebody.tid | 2 +- .../viewtemplatebodycascade.tid | 5 +++ .../AdvancedSearchDefaultTab.tid | 0 .../AdvancedSearchFilterDefaultTab.tid | 2 + .../testfiltermacro.tid} | 2 +- 19 files changed, 71 insertions(+), 46 deletions(-) delete mode 100644 core/wiki/config/AdvancedSearchFilterDefaultTab.tid delete mode 100644 plugins/tiddlywiki/internals/cascades/viewtemplatebody.tid rename plugins/tiddlywiki/internals/{ => filterinspection}/InspectResultsTab.tid (78%) rename plugins/tiddlywiki/internals/{ => filterinspection/docs}/InspectFilterMacro.tid (83%) rename plugins/tiddlywiki/internals/{ => filterinspection/docs}/inspect Operator.tid (65%) rename plugins/tiddlywiki/internals/{ => filterinspection/docs}/inspect-filter Macro (Examples).tid (92%) rename plugins/tiddlywiki/internals/{ => filterinspection}/inspect-filter.tid (98%) rename plugins/tiddlywiki/internals/{ => filterinspection}/modules/inspect.js (89%) rename plugins/tiddlywiki/internals/{ => filterinspection}/modules/startup.js (72%) rename plugins/tiddlywiki/internals/{ => filterinspection}/styles.tid (98%) rename plugins/tiddlywiki/internals/{ => filterinspection}/tests/wikitext/Simple.tid (99%) rename plugins/tiddlywiki/internals/{templates => filterinspection}/viewtemplatebody.tid (50%) create mode 100644 plugins/tiddlywiki/internals/filterinspection/viewtemplatebodycascade.tid rename {core/wiki/config => plugins/tiddlywiki/internals/not-to-be-merged}/AdvancedSearchDefaultTab.tid (100%) create mode 100644 plugins/tiddlywiki/internals/not-to-be-merged/AdvancedSearchFilterDefaultTab.tid rename plugins/tiddlywiki/internals/{testfilter.tid => not-to-be-merged/testfiltermacro.tid} (68%) diff --git a/core/wiki/config/AdvancedSearchFilterDefaultTab.tid b/core/wiki/config/AdvancedSearchFilterDefaultTab.tid deleted file mode 100644 index f3e1715764..0000000000 --- a/core/wiki/config/AdvancedSearchFilterDefaultTab.tid +++ /dev/null @@ -1,2 +0,0 @@ -title: $:/state/tab--251342953 -text: $:/plugins/tiddlywiki/internals/InspectResultsTab diff --git a/editions/prerelease/tiddlers/system/DefaultTiddlers.tid b/editions/prerelease/tiddlers/system/DefaultTiddlers.tid index 96dc1e98b7..42fdc77f7a 100644 --- a/editions/prerelease/tiddlers/system/DefaultTiddlers.tid +++ b/editions/prerelease/tiddlers/system/DefaultTiddlers.tid @@ -2,8 +2,8 @@ created: 20131127215321439 modified: 20140912135951542 title: $:/DefaultTiddlers -[[$:/plugins/internals/config]] +[[$:/plugins/tiddlywiki/internals/config]] [[$:/AdvancedSearch]] -[[inspect Operator]] -[[inspect-filter Macro]] -[[inspect-filter Macro (Examples)]] +[[$:/plugins/tiddlywiki/internals/filterinspection/docs/inspectoperator]] +[[$:/plugins/tiddlywiki/internals/filterinspection/docs/InspectFilterMacro]] +[[$:/plugins/tiddlywiki/internals/filterinspection/docs/inspectfiltermacro/examples]] diff --git a/editions/tw5.com/tiddlers/system/DefaultTiddlers.tid b/editions/tw5.com/tiddlers/system/DefaultTiddlers.tid index 8b8e144fee..1259ab9e91 100644 --- a/editions/tw5.com/tiddlers/system/DefaultTiddlers.tid +++ b/editions/tw5.com/tiddlers/system/DefaultTiddlers.tid @@ -3,8 +3,8 @@ modified: 20140912135951542 title: $:/DefaultTiddlers type: text/vnd.tiddlywiki -[[$:/plugins/internals/config]] +[[$:/plugins/tiddlywiki/internals/config]] [[$:/AdvancedSearch]] -[[inspect Operator]] -[[inspect-filter Macro]] -[[inspect-filter Macro (Examples)]] +[[$:/plugins/tiddlywiki/internals/filterinspection/docs/inspectoperator]] +[[$:/plugins/tiddlywiki/internals/filterinspection/docs/InspectFilterMacro]] +[[$:/plugins/tiddlywiki/internals/filterinspection/docs/inspectfiltermacro/examples]] diff --git a/plugins/tiddlywiki/internals/cascades/viewtemplatebody.tid b/plugins/tiddlywiki/internals/cascades/viewtemplatebody.tid deleted file mode 100644 index 7f5a4cef0a..0000000000 --- a/plugins/tiddlywiki/internals/cascades/viewtemplatebody.tid +++ /dev/null @@ -1,5 +0,0 @@ -title: $:/plugins/internals/cascades/viewtemplatebody -tags: $:/tags/ViewTemplateBodyFilter -list-before: - -[tag[$:/tags/FilterInspectionOutput]type[application/json]then[$:/plugins/internals/templates/viewtemplatebody]] \ No newline at end of file diff --git a/plugins/tiddlywiki/internals/config.tid b/plugins/tiddlywiki/internals/config.tid index 9e5ba23dfd..fdc73bc863 100644 --- a/plugins/tiddlywiki/internals/config.tid +++ b/plugins/tiddlywiki/internals/config.tid @@ -1,4 +1,4 @@ -title: $:/plugins/internals/config +title: $:/plugins/tiddlywiki/internals/config tags: $:/tags/ControlPanel caption: Internals diff --git a/plugins/tiddlywiki/internals/InspectResultsTab.tid b/plugins/tiddlywiki/internals/filterinspection/InspectResultsTab.tid similarity index 78% rename from plugins/tiddlywiki/internals/InspectResultsTab.tid rename to plugins/tiddlywiki/internals/filterinspection/InspectResultsTab.tid index fdb6189df8..8de2103141 100644 --- a/plugins/tiddlywiki/internals/InspectResultsTab.tid +++ b/plugins/tiddlywiki/internals/filterinspection/InspectResultsTab.tid @@ -1,4 +1,4 @@ -title: $:/plugins/tiddlywiki/internals/InspectResultsTab +title: $:/plugins/tiddlywiki/internals/filterinspection/InspectResultsTab tags: $:/tags/AdvancedSearch/FilterResults caption: Inspect list-after: $:/core/ui/AdvancedSearch/Filter/FilterResults/Results diff --git a/plugins/tiddlywiki/internals/InspectFilterMacro.tid b/plugins/tiddlywiki/internals/filterinspection/docs/InspectFilterMacro.tid similarity index 83% rename from plugins/tiddlywiki/internals/InspectFilterMacro.tid rename to plugins/tiddlywiki/internals/filterinspection/docs/InspectFilterMacro.tid index 1d8653ea8a..5af32ebac5 100644 --- a/plugins/tiddlywiki/internals/InspectFilterMacro.tid +++ b/plugins/tiddlywiki/internals/filterinspection/docs/InspectFilterMacro.tid @@ -1,7 +1,5 @@ caption: inspect-filter -created: 20250401094200994 -modified: 20250401094200994 -title: inspect-filter Macro +title: $:/plugins/tiddlywiki/internals/filterinspection/docs/InspectFilterMacro type: text/vnd.tiddlywiki The <<.def inspect-filter>> [[macro|Macros]] displays a schematic representation of the filter evaluation process, including the input, output and intermediate results of evaluating the specified filter. It is based on the [[inspect operator|inspect Operator]]. @@ -17,4 +15,4 @@ By default the tabs are arranged horizontally above the content. To get vertical ;orientation : Optionally, the orientation of the schematic representation, defaulting to `horizontal`. Set to `vertical` to display the tabs vertically. This is useful for narrow windows or when the content is too wide to fit in a horizontal tab layout -<<.macro-examples "inspect-filter">> +[[Examples|$:/plugins/tiddlywiki/internals/filterinspection/docs/inspectfiltermacro/examples]] diff --git a/plugins/tiddlywiki/internals/inspect Operator.tid b/plugins/tiddlywiki/internals/filterinspection/docs/inspect Operator.tid similarity index 65% rename from plugins/tiddlywiki/internals/inspect Operator.tid rename to plugins/tiddlywiki/internals/filterinspection/docs/inspect Operator.tid index 1e43cdde2a..041bf506f8 100644 --- a/plugins/tiddlywiki/internals/inspect Operator.tid +++ b/plugins/tiddlywiki/internals/filterinspection/docs/inspect Operator.tid @@ -1,16 +1,14 @@ caption: inspect -created: 20250401094200994 -modified: 20250401094200994 -op-input: a [[selection of titles|Title Selection]] -op-output: a JSON object containing the input, output and intermediate results of evaluating the specified filter -op-parameter: the filter to be inspected -op-parameter-name: F -op-purpose: inspect the evaluation of a filter to aid debugging tags: [[Filter Operators]] -title: inspect Operator +title: $:/plugins/tiddlywiki/internals/filterinspection/docs/inspectoperator type: text/vnd.tiddlywiki -<<.from-version "5.3.7">> The <<.op inspect>> operator evaluates a filter with the specified input titles and returns a JSON object containing the input, output and intermediate results of evaluating the specified filter. +The ''inspect'' operator evaluates a filter with the specified input titles and returns a JSON object containing the input, output and intermediate results of evaluating the specified filter. + +|Operator Purpose |Inspect the evaluation of a filter to aid debugging | +|Operator Input |A selection of titles | +|Operator Output |A JSON object containing the input, output and intermediate results of evaluating the specified filter | +|Operator Parameter |The filter to be inspected | The JSON object contains the following properties: diff --git a/plugins/tiddlywiki/internals/inspect-filter Macro (Examples).tid b/plugins/tiddlywiki/internals/filterinspection/docs/inspect-filter Macro (Examples).tid similarity index 92% rename from plugins/tiddlywiki/internals/inspect-filter Macro (Examples).tid rename to plugins/tiddlywiki/internals/filterinspection/docs/inspect-filter Macro (Examples).tid index d3c8320544..97f30c3edb 100644 --- a/plugins/tiddlywiki/internals/inspect-filter Macro (Examples).tid +++ b/plugins/tiddlywiki/internals/filterinspection/docs/inspect-filter Macro (Examples).tid @@ -1,10 +1,7 @@ -created: 20250401094200994 -modified: 20250401094200994 +title: $:/plugins/tiddlywiki/internals/filterinspection/docs/inspectfiltermacro/examples tags: [[Macro Examples]] -title: inspect-filter Macro (Examples) type: text/vnd.tiddlywiki - <$macrocall $name=".example" n="1" eg=""" <$transclude $variable="inspect-filter" filter="[tags[]prefix[$:/]] :sort[length[]add[1]] +[first[2]tagging[]]" inputFilter="[all[tiddlers]]"/> """/> diff --git a/plugins/tiddlywiki/internals/inspect-filter.tid b/plugins/tiddlywiki/internals/filterinspection/inspect-filter.tid similarity index 98% rename from plugins/tiddlywiki/internals/inspect-filter.tid rename to plugins/tiddlywiki/internals/filterinspection/inspect-filter.tid index 7719675c0a..779c61e329 100644 --- a/plugins/tiddlywiki/internals/inspect-filter.tid +++ b/plugins/tiddlywiki/internals/filterinspection/inspect-filter.tid @@ -1,4 +1,4 @@ -title: $:/plugins/tiddlywiki/internals/inspect-filter +title: $:/plugins/tiddlywiki/internals/filterinspection/inspectfiltermacro tags: $:/tags/Macro \whitespace trim diff --git a/plugins/tiddlywiki/internals/modules/inspect.js b/plugins/tiddlywiki/internals/filterinspection/modules/inspect.js similarity index 89% rename from plugins/tiddlywiki/internals/modules/inspect.js rename to plugins/tiddlywiki/internals/filterinspection/modules/inspect.js index 110f554af3..4aabaccaab 100644 --- a/plugins/tiddlywiki/internals/modules/inspect.js +++ b/plugins/tiddlywiki/internals/filterinspection/modules/inspect.js @@ -1,5 +1,5 @@ /*\ -title: $:/plugins/tiddlywiki/internals/filters/inspect.js +title: $:/plugins/tiddlywiki/internals/filterinspection/modules/inspect.js type: application/javascript module-type: filteroperator diff --git a/plugins/tiddlywiki/internals/modules/startup.js b/plugins/tiddlywiki/internals/filterinspection/modules/startup.js similarity index 72% rename from plugins/tiddlywiki/internals/modules/startup.js rename to plugins/tiddlywiki/internals/filterinspection/modules/startup.js index 75ab7cd79d..23697571ff 100644 --- a/plugins/tiddlywiki/internals/modules/startup.js +++ b/plugins/tiddlywiki/internals/filterinspection/modules/startup.js @@ -1,5 +1,5 @@ /*\ -title: $:/plugins/tiddlywiki/internals/startup.js +title: $:/plugins/tiddlywiki/internals/filterinspection/modules/startup.js type: application/javascript module-type: startup @@ -15,12 +15,17 @@ exports.before = ["startup"]; exports.synchronous = true; exports.startup = function() { + // Publish public methods $tw.plugins = $tw.plugins || {}; $tw.plugins.internals = { getWrappers: getWrappers }; + // We accumulate the output of the filter inspection into an array. We can't directly write to the wiki since we might be in the middle + // of the refresh cycle, when writes to the wiki are not allowed var accumulator = []; + // Add our hook for each filter evaluation $tw.hooks.addHook("th-filter-evaluation",function(filterString,wrappers) { + // Get the list of tiddlers to be inspected var inspectedFilters = []; $tw.wiki.eachTiddlerPlusShadows(function(tiddler,title) { if(tiddler.fields.tags && tiddler.fields.tags.indexOf("$:/tags/InspectableFilter") !== -1 && !tiddler.fields["draft.of"] && tiddler.fields.text) { @@ -35,12 +40,14 @@ exports.startup = function() { if(wrappers.prefix || wrappers.operation || wrappers.operator) { return wrappers; } + // Flush the accumulator, making each filter inspection output record into a separate tiddler var flushAccumulator = function() { if(accumulator.length) { $tw.utils.each(accumulator,function(jsonInspectionOutput) { // Get the output as a string - var stringInspectionOutput = JSON.stringify(jsonInspectionOutput), - logPrefix = `$:/temp/filter-inspection/${ + $tw.utils.stringifyDate(new Date())}: `, + var stringInspectionOutput = JSON.stringify(jsonInspectionOutput); + // Compute the log prefix and its length + var logPrefix = `$:/temp/filter-inspection/${ + $tw.utils.stringifyDate(new Date())}: `, logPrefixLength = logPrefix.length; // Check if the the output is the same as the last log with the same filter var logTitles = []; @@ -86,45 +93,62 @@ exports.startup = function() { }); }; +/* +Return the wrappers for evaluating a given filter +fnDone is a function that will be called with the output of the filter evaluation as the single argument +inputFilter is the filter to be evaluated +*/ function getWrappers(fnDone,inputFilter) { + // Skeleton output record var output = { inputFilter: inputFilter, input: [], runs: [] - }, - currentRun,currentOperation; + }; + // Keep track of where the current run and the current operation are being written + var currentRun,currentOperation; // Compile the filter with wrapper functions to log the details return { start: function(source) { - // Save the input + // Save the input so that we have it in the output record source(function(tiddler,title) { output.input.push(title); }); }, prefix: function(filterRunPrefixFunction,operationFunction,innerOptions) { + // Function to be called at the start of each filter run return function(results,innerSource,innerWidget) { + // Save the details of this filte run var details ={ input: results.toArray(), prefixName: innerOptions.prefixName, suffixes: innerOptions.suffixes, operations: [] }; + // Save the current run so that we can add operations to it currentRun = details.operations; + // Get the filter run prefix function var innerResults = filterRunPrefixFunction.call(null,operationFunction,innerOptions); + // Invoke the filter run innerResults(results,innerSource,innerWidget); + // Save the results of the filter run details.output = results.toArray(); output.runs.push(details); }; }, operation: function(operationFunction,operation) { + // Record the operation var details = { operators: [] } + // Keep track of where the current operation should be being written currentOperation = details.operators; currentRun.push(details); + // Invoke the operation operationFunction(); }, operator: function(operatorFunction,innerSource,innerOperator,innerOptions) { + // Record the operator var details = { operatorName: innerOperator.operatorName, operands: innerOperator.operands, @@ -135,11 +159,15 @@ function getWrappers(fnDone,inputFilter) { regexp: innerOperator.regexp, input: [] }; + // Copy the input innerSource(function(tiddler,title) { details.input.push(title); }); + // Save this operation currentOperation.push(details); + // Invoke the operator var innerResults = operatorFunction.apply(null,Array.prototype.slice.call(arguments,1)); + // Make sure the results are an array so that we can store them if(!$tw.utils.isArray(innerResults)) { var resultArray = []; innerResults(function(tiddler,title) { @@ -147,12 +175,16 @@ function getWrappers(fnDone,inputFilter) { }); innerResults = resultArray; } + // Store the results in the output details.output = innerResults; + // Return the results return innerResults; }, done: function(results) { + // Save the results of the filter evaluation output.output = results; // console.log(`Inspected ${JSON.stringify(output,null,4)}`); + // Invoke the done function if(fnDone) { fnDone(output); } diff --git a/plugins/tiddlywiki/internals/styles.tid b/plugins/tiddlywiki/internals/filterinspection/styles.tid similarity index 98% rename from plugins/tiddlywiki/internals/styles.tid rename to plugins/tiddlywiki/internals/filterinspection/styles.tid index 1856de60fb..cc5271241a 100644 --- a/plugins/tiddlywiki/internals/styles.tid +++ b/plugins/tiddlywiki/internals/filterinspection/styles.tid @@ -1,4 +1,4 @@ -title: $:/plugins/tiddlywiki/internals/styles +title: $:/plugins/tiddlywiki/internals/filterinspection/styles tags: $:/tags/Stylesheet \rules only filteredtranscludeinline transcludeinline macrodef macrocallinline macrocallblock diff --git a/plugins/tiddlywiki/internals/tests/wikitext/Simple.tid b/plugins/tiddlywiki/internals/filterinspection/tests/wikitext/Simple.tid similarity index 99% rename from plugins/tiddlywiki/internals/tests/wikitext/Simple.tid rename to plugins/tiddlywiki/internals/filterinspection/tests/wikitext/Simple.tid index dddd3f9ebf..a60076167d 100644 --- a/plugins/tiddlywiki/internals/tests/wikitext/Simple.tid +++ b/plugins/tiddlywiki/internals/filterinspection/tests/wikitext/Simple.tid @@ -1,4 +1,4 @@ -title: InspectFilter/Simple +title: $:/plugins/tiddlywiki/internals/filterinspection/tests/wikitext/Simple description: Test filter inspection type: text/vnd.tiddlywiki-multiple tags: [[$:/tags/wiki-test-spec]] diff --git a/plugins/tiddlywiki/internals/templates/viewtemplatebody.tid b/plugins/tiddlywiki/internals/filterinspection/viewtemplatebody.tid similarity index 50% rename from plugins/tiddlywiki/internals/templates/viewtemplatebody.tid rename to plugins/tiddlywiki/internals/filterinspection/viewtemplatebody.tid index 054a0e6977..0090e58978 100644 --- a/plugins/tiddlywiki/internals/templates/viewtemplatebody.tid +++ b/plugins/tiddlywiki/internals/filterinspection/viewtemplatebody.tid @@ -1,3 +1,3 @@ -title: $:/plugins/internals/templates/viewtemplatebody +title: $:/plugins/tiddlywiki/internals/filterinspection/viewtemplatebody <$transclude $variable="inspect-filter-output" jsonOutput={{!!text}} /> diff --git a/plugins/tiddlywiki/internals/filterinspection/viewtemplatebodycascade.tid b/plugins/tiddlywiki/internals/filterinspection/viewtemplatebodycascade.tid new file mode 100644 index 0000000000..315150f2ae --- /dev/null +++ b/plugins/tiddlywiki/internals/filterinspection/viewtemplatebodycascade.tid @@ -0,0 +1,5 @@ +title: $:/plugins/tiddlywiki/internals/filterinspection/cascades/viewtemplatebody +tags: $:/tags/ViewTemplateBodyFilter +list-before: + +[tag[$:/tags/FilterInspectionOutput]type[application/json]then[$:/plugins/tiddlywiki/internals/filterinspection/viewtemplatebody]] \ No newline at end of file diff --git a/core/wiki/config/AdvancedSearchDefaultTab.tid b/plugins/tiddlywiki/internals/not-to-be-merged/AdvancedSearchDefaultTab.tid similarity index 100% rename from core/wiki/config/AdvancedSearchDefaultTab.tid rename to plugins/tiddlywiki/internals/not-to-be-merged/AdvancedSearchDefaultTab.tid diff --git a/plugins/tiddlywiki/internals/not-to-be-merged/AdvancedSearchFilterDefaultTab.tid b/plugins/tiddlywiki/internals/not-to-be-merged/AdvancedSearchFilterDefaultTab.tid new file mode 100644 index 0000000000..efd4c2d5e1 --- /dev/null +++ b/plugins/tiddlywiki/internals/not-to-be-merged/AdvancedSearchFilterDefaultTab.tid @@ -0,0 +1,2 @@ +title: $:/state/tab--251342953 +text: $:/plugins/tiddlywiki/internals/filterinspection/InspectResultsTab diff --git a/plugins/tiddlywiki/internals/testfilter.tid b/plugins/tiddlywiki/internals/not-to-be-merged/testfiltermacro.tid similarity index 68% rename from plugins/tiddlywiki/internals/testfilter.tid rename to plugins/tiddlywiki/internals/not-to-be-merged/testfiltermacro.tid index 12a26cea83..c4200c2f0e 100644 --- a/plugins/tiddlywiki/internals/testfilter.tid +++ b/plugins/tiddlywiki/internals/not-to-be-merged/testfiltermacro.tid @@ -1,4 +1,4 @@ -title: $:/plugins/internals/testfilter +title: $:/plugins/tiddlywiki/internals/testfilter tags: $:/tags/InspectableFilter type: text/plain