1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-17 23:34:50 +00:00

Add support for accessing function parameters as name/value pairs

This commit is contained in:
jeremy@jermolene.com 2022-05-02 10:00:50 +01:00
parent bbc6661192
commit 5f02cc49fd
2 changed files with 39 additions and 2 deletions

View File

@ -49,10 +49,16 @@ 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,
self.setVariable(name,transclusionWidget.getTransclusionParameter(name,index,self.getAttribute(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));
} }
// Construct the child widgets // Construct the child widgets
this.makeChildWidgets(); this.makeChildWidgets();

View File

@ -0,0 +1,31 @@
title: Transclude/Parameterised/Name/Values
description: Parameterised transclusion accessing parameters as name/value pairs
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
{{TiddlerOne}}
{{TiddlerOne|Ferret}}
{{TiddlerOne|Butterfly|Moth}}
{{TiddlerOne|Beetle|Scorpion|Snake}}
{{TiddlerOne||TiddlerTwo|Beetle|Scorpion|Snake}}
_
title: TiddlerOne
\whitespace trim
\parameters(zero:'Jaguar',one:'Lizard',two:'Mole')
<$list filter="[enlist<paramNames>]" counter="counter">
{<$text text={{{ [enlist<paramNames>nth<counter>] }}}/>:<$text text={{{ [enlist<paramValues>nth<counter>] }}}/>}
</$list>
_
title: TiddlerTwo
\whitespace trim
\parameters(zero:'Mouse',one:'Horse',two:'Owl')
(<$transclude $tiddler=<<currentTiddler>> zero=<<zero>> one=<<one>> two=<<two>>/>)
_
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>