Skip to content

Commit

Permalink
Refactor dependency on widget.getVariableInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Jermolene committed Jun 11, 2023
1 parent cc383e6 commit 66212cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/modules/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Adds tiddler filtering methods to the $tw.Wiki object.
/*global $tw: false */
"use strict";

var widgetClass = require("$:/core/modules/widgets/widget.js").widget;

/* Maximum permitted filter recursion depth */
var MAX_FILTER_DEPTH = 300;

Expand Down Expand Up @@ -269,8 +271,7 @@ exports.compileFilter = function(filterString) {
operand.value = self.getTextReference(operand.text,"",currTiddlerTitle);
} else if(operand.variable) {
var varTree = $tw.utils.parseFilterVariable(operand.text);
var variableInfo = widget.getVariableInfo(varTree.name,{params: varTree.params, source: source});
operand.value = (variableInfo.resultList ? variableInfo.resultList[0] : variableInfo.text) || "";
operand.value = widgetClass.evaluateVariable(widget,varTree.name,{params: varTree.params, source: source})[0] || "";
} else {
operand.value = operand.text;
}
Expand Down
14 changes: 14 additions & 0 deletions core/modules/widgets/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,20 @@ Widget.prototype.allowActionPropagation = function() {
return true;
};

/*
Evaluate a variable with parameters. This is a static convenience method that attempts to evaluate a variable as a function, returning an array of strings
*/
Widget.evaluateVariable = function(widget,name,options) {
var result;
if(widget.getVariableInfo) {
var variableInfo = widget.getVariableInfo(name,options);
result = variableInfo.resultList || [variableInfo.text];
} else {
result = [widget.getVariable(name)];
}
return result;
};

exports.widget = Widget;

})();

1 comment on commit 66212cd

@vercel
Copy link

@vercel vercel bot commented on 66212cd Jun 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tiddlywiki5 – ./

tiddlywiki5-jermolene.vercel.app
tiddlywiki5-git-master-jermolene.vercel.app
tiddlywiki5.vercel.app

Please sign in to comment.