From 542df63ccfc401b875413addb6adecbc600e7f8a Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Fri, 3 Jun 2022 11:21:32 +0100 Subject: [PATCH] Simplify metaparameters implementation --- core/modules/widgets/parameters.js | 9 +++------ core/modules/widgets/transclude.js | 29 ++++++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/core/modules/widgets/parameters.js b/core/modules/widgets/parameters.js index ce65ac101..e0f301113 100644 --- a/core/modules/widgets/parameters.js +++ b/core/modules/widgets/parameters.js @@ -68,15 +68,12 @@ ParametersWidget.prototype.execute = function() { self.setVariable(name,value); }); // Assign any metaparameters - var assignMetaParameter = function(name) { + $tw.utils.each(pointer.getTransclusionMetaParameters(),function(getValue,name) { var variableName = self.getAttribute("$" + name); if(variableName !== undefined) { - self.setVariable(variableName,pointer.getTransclusionMetaParameter(name)); + self.setVariable(variableName,getValue(name)); } - }; - assignMetaParameter("parseAsInline"); - assignMetaParameter("parseTreeNodes"); - assignMetaParameter("params"); + }); } // Construct the child widgets this.makeChildWidgets(); diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index e6bd6aec3..d9a10515b 100755 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -306,19 +306,22 @@ TranscludeWidget.prototype.getTransclusionParameter = function(name,index,defaul /* Get one of the special parameters to be provided by the parameters widget */ -TranscludeWidget.prototype.getTransclusionMetaParameter = function(name) { - switch(name) { - case "parseAsInline": - return this.parseAsInline ? "yes" : "no"; - case "parseTreeNodes": - return JSON.stringify(this.parseTreeNode); - case "slotFillParseTrees": - return JSON.stringify(this.slotFillParseTrees); - case "params": - return JSON.stringify(this.stringParametersByName); - default: - return ""; - } +TranscludeWidget.prototype.getTransclusionMetaParameters = function() { + var self = this; + return { + "parseAsInline": function() { + return self.parseAsInline ? "yes" : "no"; + }, + "parseTreeNodes": function() { + return JSON.stringify(self.parseTreeNode); + }, + "slotFillParseTrees": function() { + return JSON.stringify(self.slotFillParseTrees); + }, + "params": function() { + JSON.stringify(self.stringParametersByName); + } + }; }; /*