mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 12:07:19 +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:
parent
3e09eacd20
commit
9e8d05f699
@ -20,48 +20,48 @@ 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(customDefinition && customDefinition.srcVariable && customDefinition.srcVariable.isFunctionDefinition) {
|
||||
var variables = Object.create(null);
|
||||
$tw.utils.each(customDefinition.srcVariable.params,function(param,index) {
|
||||
var value = operator.operands[index];
|
||||
if(value === undefined) {
|
||||
value = param["default"] || "";
|
||||
}
|
||||
variables[param.name] = value;
|
||||
});
|
||||
var getVariable = function(name,opts) {
|
||||
if(name in variables) {
|
||||
return variables[name];
|
||||
} else {
|
||||
return options.widget.getVariable(name,opts);
|
||||
};
|
||||
};
|
||||
var getVariableInfo = function(name,opts) {
|
||||
if(name in variables) {
|
||||
return {
|
||||
text: variables[name]
|
||||
};
|
||||
} else {
|
||||
return options.widget.getVariableInfo(name,opts);
|
||||
};
|
||||
}
|
||||
var list = options.wiki.filterTiddlers(customDefinition.srcVariable.value,{getVariable: getVariable,getVariableInfo: getVariableInfo},source);
|
||||
if(operator.prefix === "!") {
|
||||
var results = [];
|
||||
source(function(tiddler,title) {
|
||||
if(list.indexOf(title) === -1) {
|
||||
results.push(title);
|
||||
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) {
|
||||
var value = operator.operands[index];
|
||||
if(value === undefined) {
|
||||
value = param["default"] || "";
|
||||
}
|
||||
variables[param.name] = value;
|
||||
});
|
||||
return results;
|
||||
} else {
|
||||
return list;
|
||||
var getVariable = function(name,opts) {
|
||||
if(name in variables) {
|
||||
return variables[name];
|
||||
} else {
|
||||
return options.widget.getVariable(name,opts);
|
||||
};
|
||||
};
|
||||
var getVariableInfo = function(name,opts) {
|
||||
if(name in variables) {
|
||||
return {
|
||||
text: variables[name]
|
||||
};
|
||||
} else {
|
||||
return options.widget.getVariableInfo(name,opts);
|
||||
};
|
||||
}
|
||||
var list = options.wiki.filterTiddlers(customDefinition.srcVariable.value,{getVariable: getVariable,getVariableInfo: getVariableInfo},source);
|
||||
if(operator.prefix === "!") {
|
||||
var results = [];
|
||||
source(function(tiddler,title) {
|
||||
if(list.indexOf(title) === -1) {
|
||||
results.push(title);
|
||||
}
|
||||
});
|
||||
return results;
|
||||
} else {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return fieldFilterOperatorFn(source,operator,options);
|
||||
}
|
||||
return fieldFilterOperatorFn(source,operator,options);
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user