mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-07-01 09:43:16 +00:00
allowing variable number of arguments for non-argument macros
This commit is contained in:
parent
489b40314b
commit
853cca906c
|
@ -143,29 +143,34 @@ Widget.prototype.evaluateMacroModule = function(name,actualParams,defaultValue)
|
||||||
if($tw.utils.hop($tw.macros,name)) {
|
if($tw.utils.hop($tw.macros,name)) {
|
||||||
var macro = $tw.macros[name],
|
var macro = $tw.macros[name],
|
||||||
args = [];
|
args = [];
|
||||||
var nextAnonParameter = 0, // Next candidate anonymous parameter in macro call
|
if(macro.params.length > 0) {
|
||||||
paramInfo, paramValue;
|
var nextAnonParameter = 0, // Next candidate anonymous parameter in macro call
|
||||||
// Step through each of the parameters in the macro definition
|
paramInfo, paramValue;
|
||||||
for(var p=0; p<macro.params.length; p++) {
|
// Step through each of the parameters in the macro definition
|
||||||
// Check if we've got a macro call parameter with the same name
|
for(var p=0; p<macro.params.length; p++) {
|
||||||
paramInfo = macro.params[p];
|
// Check if we've got a macro call parameter with the same name
|
||||||
paramValue = undefined;
|
paramInfo = macro.params[p];
|
||||||
for(var m=0; m<actualParams.length; m++) {
|
paramValue = undefined;
|
||||||
if(actualParams[m].name === paramInfo.name) {
|
for(var m=0; m<actualParams.length; m++) {
|
||||||
paramValue = actualParams[m].value;
|
if(actualParams[m].name === paramInfo.name) {
|
||||||
|
paramValue = actualParams[m].value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// If not, use the next available anonymous macro call parameter
|
||||||
|
while(nextAnonParameter < actualParams.length && actualParams[nextAnonParameter].name) {
|
||||||
|
nextAnonParameter++;
|
||||||
|
}
|
||||||
|
if(paramValue === undefined && nextAnonParameter < actualParams.length) {
|
||||||
|
paramValue = actualParams[nextAnonParameter++].value;
|
||||||
|
}
|
||||||
|
// If we've still not got a value, use the default, if any
|
||||||
|
paramValue = paramValue || paramInfo["default"] || "";
|
||||||
|
// Save the parameter
|
||||||
|
args.push(paramValue);
|
||||||
}
|
}
|
||||||
// If not, use the next available anonymous macro call parameter
|
}
|
||||||
while(nextAnonParameter < actualParams.length && actualParams[nextAnonParameter].name) {
|
else for(var i=0; i<actualParams.length; ++i) {
|
||||||
nextAnonParameter++;
|
args.push(actualParams[i].value);
|
||||||
}
|
|
||||||
if(paramValue === undefined && nextAnonParameter < actualParams.length) {
|
|
||||||
paramValue = actualParams[nextAnonParameter++].value;
|
|
||||||
}
|
|
||||||
// If we've still not got a value, use the default, if any
|
|
||||||
paramValue = paramValue || paramInfo["default"] || "";
|
|
||||||
// Save the parameter
|
|
||||||
args.push(paramValue);
|
|
||||||
}
|
}
|
||||||
return macro.run.apply(this,args)
|
return macro.run.apply(this,args)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user