1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-07 22:33:50 +00:00

Require period prefix for custom filter operator functions

To ensure that custom filter operators cannot clash with future core operators.
This commit is contained in:
jeremy@jermolene.com 2022-05-23 16:40:21 +01:00
parent 3e09eacd20
commit 9e8d05f699
4 changed files with 48 additions and 48 deletions

View File

@ -20,8 +20,8 @@ var fieldFilterOperatorFn = require("$:/core/modules/filters/field.js").field;
Export our filter function
*/
exports["[unknown]"] = function(source,operator,options) {
var customDefinitionTitle = "[" + operator.operator + "[]]",
customDefinition = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(customDefinitionTitle);
if(operator.operator.charAt(0) === ".") {
var customDefinition = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(operator.operator);
if(customDefinition && customDefinition.srcVariable && customDefinition.srcVariable.isFunctionDefinition) {
var variables = Object.create(null);
$tw.utils.each(customDefinition.srcVariable.params,function(param,index) {
@ -59,9 +59,9 @@ exports["[unknown]"] = function(source,operator,options) {
} else {
return list;
}
} else {
return fieldFilterOperatorFn(source,operator,options);
}
}
return fieldFilterOperatorFn(source,operator,options);
};
})();

View File

@ -6,17 +6,17 @@ tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\function [dividebysomething[]](first:ignored,factor:0.5)
\function .dividebysomething(first:ignored,factor:0.5)
[divide[2]multiply<factor>]
\end
\function [multiplebysomething[]](first:ignored,factor:2)
[multiply[2]dividebysomething[],<factor>]
\function .multiplebysomething(first:ignored,factor:2)
[multiply[2].dividebysomething[],<factor>]
\end
<$text text={{{ [[123]multiplebysomething[]] }}}/>
<$text text={{{ [[123].multiplebysomething[]] }}}/>
-
<$text text={{{ [[123]multiplebysomething[x],[4]] }}}/>
<$text text={{{ [[123].multiplebysomething[x],[4]] }}}/>
+
title: ExpectedResult

View File

@ -6,13 +6,13 @@ tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\function [multiplybysomething[]](first:ignored,factor:2)
\function .multiplybysomething(first:ignored,factor:2)
[multiply[2]multiply<factor>]
\end
<$text text={{{ [[123]multiplybysomething[]] }}}/>
<$text text={{{ [[123].multiplybysomething[]] }}}/>
-
<$text text={{{ [[123]multiplybysomething[x],[4]] }}}/>
<$text text={{{ [[123].multiplybysomething[x],[4]] }}}/>
+
title: ExpectedResult

View File

@ -5,11 +5,11 @@ tags: [[$:/tags/wiki-test-spec]]
title: Output
\function [multiplybytwo[]]()
\function .multiplybytwo()
[multiply[2]]
\end
<$text text={{{ [[123]multiplybytwo[]] }}}/>
<$text text={{{ [[123].multiplybytwo[]] }}}/>
+
title: ExpectedResult