jenkins-bot has submitted this change and it was merged.
Change subject: Template tool: Refactor parameter mapping
......................................................................
Template tool: Refactor parameter mapping
Change-Id: Ie2c8b57a91b86c34ad2643133cda200f448c9e23
---
M modules/tools/ext.cx.tools.template.js
M tests/qunit/tools/ext.cx.tools.template.test.js
2 files changed, 31 insertions(+), 15 deletions(-)
Approvals:
Nikerabbit: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/tools/ext.cx.tools.template.js
b/modules/tools/ext.cx.tools.template.js
index b34a408..60ed75f 100644
--- a/modules/tools/ext.cx.tools.template.js
+++ b/modules/tools/ext.cx.tools.template.js
@@ -113,13 +113,35 @@
* Adapt a template using template mapping
*/
TemplateTool.prototype.adapt = function () {
- var targetParams = {},
- templateTool = this,
- sourceParams = this.templateData.parts[ 0
].template.params;
-
mw.log( '[CX] Adapting template ' + this.templateTitle + '
based on mapping.' );
// Update the name of the template
this.templateData.parts[ 0 ].template.target.wt =
this.templateMapping.targetname;
+ this.templateData.parts[ 0 ].template.params =
this.getTargetParams( this.getSourceParams() );
+ this.$template.attr( 'data-mw', JSON.stringify(
this.templateData ) );
+
+ // Make templates uneditable unless whitelisted
+ if ( !this.templateMapping.editable ) {
+ this.$template.data( 'editable', false );
+ }
+ };
+
+ /**
+ * Get the source parameters for the template
+ *
+ * @return {Object} Source parameters - key-value pairs.
+ */
+ TemplateTool.prototype.getSourceParams = function () {
+ return this.templateData.parts[ 0 ].template.params;
+ };
+
+ /**
+ * Get the target parameters for the template after mapping
+ *
+ * @return {Object} Target parameters - key-value pairs.
+ */
+ TemplateTool.prototype.getTargetParams = function ( sourceParams ) {
+ var targetParams = {},
+ self = this;
// Update the template parameters
$.each( sourceParams, function ( key, value ) {
@@ -131,22 +153,16 @@
}
// Copy over other parameters, but map known keys
- if ( templateTool.templateMapping.parameters &&
- templateTool.templateMapping.parameters[ key ]
!== undefined
+ if ( self.templateMapping.parameters &&
+ self.templateMapping.parameters[ key ] !==
undefined
) {
- key = templateTool.templateMapping.parameters[
key ];
+ key = self.templateMapping.parameters[ key ];
}
targetParams[ key ] = value;
} );
- this.templateData.parts[ 0 ].template.params = targetParams;
- this.$template.attr( 'data-mw', JSON.stringify(
this.templateData ) );
-
- // Make templates uneditable unless whitelisted
- if ( !this.templateMapping.editable ) {
- this.$template.data( 'editable', false );
- }
+ return targetParams;
};
/**
diff --git a/tests/qunit/tools/ext.cx.tools.template.test.js
b/tests/qunit/tools/ext.cx.tools.template.test.js
index 88807a1..a53f4ea 100644
--- a/tests/qunit/tools/ext.cx.tools.template.test.js
+++ b/tests/qunit/tools/ext.cx.tools.template.test.js
@@ -111,7 +111,7 @@
templateTool.process().then( function () {
var i, key, mappedKey,
templateData = $template.data(
'mw' ),
- templateKeys = Object.keys(
templateData.parts[ 0 ].template.params ),
+ templateKeys = Object.keys(
templateTool.getSourceParams() ),
templateMapping =
$template.data( 'template-mapping' ),
templateMappingKeys =
Object.keys( templateMapping.parameters );
--
To view, visit https://gerrit.wikimedia.org/r/295779
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie2c8b57a91b86c34ad2643133cda200f448c9e23
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits