1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-29 23:40:45 +00:00

Fix parameter handling

This commit is contained in:
jeremy@jermolene.com 2022-05-03 12:54:29 +01:00
parent c4743ebbec
commit e1df50d981
4 changed files with 21 additions and 21 deletions

View File

@ -49,16 +49,13 @@ ParametersWidget.prototype.execute = function() {
}
// Process each parameter
if(transclusionWidget) {
var paramNames = [], paramValues = [];
$tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(self.parseTreeNode),function(attr,index) {
var name = attr.name,
value = transclusionWidget.getTransclusionParameter(name,index,self.getAttribute(name));
self.setVariable(name,value);
paramNames.push(name);
paramValues.push(value);
});
self.setVariable("paramNames",$tw.utils.stringifyList(paramNames));
self.setVariable("paramValues",$tw.utils.stringifyList(paramValues));
});
this.setVariable("paramNames",$tw.utils.stringifyList(transclusionWidget.getTransclusionParameterNames()));
this.setVariable("paramValues",$tw.utils.stringifyList(transclusionWidget.getTransclusionParameterValues()));
}
// Construct the child widgets
this.makeChildWidgets();

View File

@ -177,16 +177,12 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
tree: [
{
type: "parameters",
children: parser.tree,
attributes: {},
orderedAttributes: []
children: parser.tree
}
]
}
$tw.utils.each(variableInfo.variableParams,function(param,index) {
var attr = {name: param.name, type: "string", value: param["default"]};
parser.tree[0].attributes[param.name] = attr;
parser.tree[0].orderedAttributes.push(attr);
$tw.utils.each(variableInfo.variableParams,function(param) {
$tw.utils.addAttributeToParseTreeNode(parser.tree[0],param.name,param["default"])
});
}
}
@ -232,16 +228,23 @@ TranscludeWidget.prototype.getTransclusionParameter = function(name,index,defaul
return defaultValue;
};
/*
Get an array of the names of all the provided transclusion parameters
*/
TranscludeWidget.prototype.getTransclusionParameterNames = function() {
return Object.keys(this.stringParametersByName);
};
/*
Fetch the value of a parameter identified by its position
Get an array of the values of all the provided transclusion parameters
*/
TranscludeWidget.prototype.getTransclusionParameterByPosition = function(index,defaultValue) {
if(index in this.stringParametersByPosition) {
return this.stringParametersByPosition[index];
} else {
return defaultValue;
}
TranscludeWidget.prototype.getTransclusionParameterValues = function() {
var self = this,
values = [];
$tw.utils.each(Object.keys(this.stringParametersByName),function(name) {
values.push(self.stringParametersByName[name]);
});
return values;
};
/*

View File

@ -28,4 +28,4 @@ title: TiddlerTwo
_
title: ExpectedResult
<p>{zero:Jaguar}{one:Lizard}{two:Mole}</p><p>{zero:Ferret}{one:Lizard}{two:Mole}</p><p>{zero:Butterfly}{one:Moth}{two:Mole}</p><p>{zero:Beetle}{one:Scorpion}{two:Snake}</p><p>({zero:Beetle}{one:Scorpion}{two:Snake})</p>
<p></p><p>{0:Ferret}</p><p>{0:Butterfly}{1:Moth}</p><p>{0:Beetle}{1:Scorpion}{2:Snake}</p><p>({zero:Beetle}{one:Scorpion}{two:Snake})</p>