1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-14 11:15:41 +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 // Process each parameter
if(transclusionWidget) { if(transclusionWidget) {
var paramNames = [], paramValues = [];
$tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(self.parseTreeNode),function(attr,index) { $tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(self.parseTreeNode),function(attr,index) {
var name = attr.name, var name = attr.name,
value = transclusionWidget.getTransclusionParameter(name,index,self.getAttribute(name)); value = transclusionWidget.getTransclusionParameter(name,index,self.getAttribute(name));
self.setVariable(name,value); self.setVariable(name,value);
paramNames.push(name);
paramValues.push(value);
}); });
self.setVariable("paramNames",$tw.utils.stringifyList(paramNames)); this.setVariable("paramNames",$tw.utils.stringifyList(transclusionWidget.getTransclusionParameterNames()));
self.setVariable("paramValues",$tw.utils.stringifyList(paramValues)); this.setVariable("paramValues",$tw.utils.stringifyList(transclusionWidget.getTransclusionParameterValues()));
} }
// Construct the child widgets // Construct the child widgets
this.makeChildWidgets(); this.makeChildWidgets();

View File

@ -177,16 +177,12 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
tree: [ tree: [
{ {
type: "parameters", type: "parameters",
children: parser.tree, children: parser.tree
attributes: {},
orderedAttributes: []
} }
] ]
} }
$tw.utils.each(variableInfo.variableParams,function(param,index) { $tw.utils.each(variableInfo.variableParams,function(param) {
var attr = {name: param.name, type: "string", value: param["default"]}; $tw.utils.addAttributeToParseTreeNode(parser.tree[0],param.name,param["default"])
parser.tree[0].attributes[param.name] = attr;
parser.tree[0].orderedAttributes.push(attr);
}); });
} }
} }
@ -232,16 +228,23 @@ TranscludeWidget.prototype.getTransclusionParameter = function(name,index,defaul
return defaultValue; 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) { TranscludeWidget.prototype.getTransclusionParameterValues = function() {
if(index in this.stringParametersByPosition) { var self = this,
return this.stringParametersByPosition[index]; values = [];
} else { $tw.utils.each(Object.keys(this.stringParametersByName),function(name) {
return defaultValue; values.push(self.stringParametersByName[name]);
} });
return values;
}; };
/* /*

View File

@ -28,4 +28,4 @@ title: TiddlerTwo
_ _
title: ExpectedResult 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>