From 3797ab014e12da2f41647a129531ed95b022893e Mon Sep 17 00:00:00 2001 From: Gabriel Rubens Date: Sat, 14 May 2016 15:51:06 -0300 Subject: [PATCH] Implement App.appendToConfig --- tools/cordova/builder.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tools/cordova/builder.js b/tools/cordova/builder.js index 3eff75e8fd..f3cf2be256 100644 --- a/tools/cordova/builder.js +++ b/tools/cordova/builder.js @@ -104,6 +104,9 @@ export class CordovaBuilder { } }; + // Custom elements that will be appended into config.xml's widgets + this.custom = []; + const packageMap = this.projectContext.packageMap; if (packageMap && packageMap.getInfo('launch-screen')) { @@ -250,6 +253,17 @@ export class CordovaBuilder { }); }); + // Set custom tags into widget element + _.each(this.custom, elementSet => { + let tag = config + .element(elementSet.name, elementSet.contents.attrs); + + _.each(elementSet.contents.children, child => { + tag.element(child.name, child.attrs); + if(child.txt) tag.txt(child.txt); + }); + }); + config.element('content', { src: this.metadata.contentUrl }); // Copy all the access rules @@ -628,6 +642,22 @@ configuration. The key may be deprecated.`); } builder.accessRules[pattern] = options; + }, + + /** + * @summary Append custom tags into config's widget element. + * + * `App.appendToConfig('custom-tag', {attrs: '', children: {}});` + * + * @param {String} elementName The tag name + * @param {Object} contents The contents + * @memberOf App + */ + appendToConfig: function (name, contents) { + builder.custom.push({ + name, + contents + }); } }; }