[CB-11120] Allow short/display name in config.xml
authorDarryl Pogue <darryl@dpogue.ca>
Sun, 5 Jun 2016 03:34:51 +0000 (20:34 -0700)
committerSteve Gill <stevengill97@gmail.com>
Fri, 24 Mar 2017 04:49:57 +0000 (21:49 -0700)
This adds support for a "short" display name to be specified as an
attribute of the `name` element in config.xml.

This attribute is defined in the W3C Widgets spec, on which config.xml
is loosely based:
https://www.w3.org/TR/widgets/#the-short-attribute

 This closes #453

spec/ConfigParser/ConfigParser.spec.js
src/ConfigParser/ConfigParser.js

index f3e334d..fa49550 100644 (file)
@@ -83,7 +83,20 @@ describe('config.xml parser', function () {
                 cfg.setName('this.is.bat.country');
                 expect(cfg.name()).toEqual('this.is.bat.country');
             });
+
+            describe('short name', function() {
+                it('should default to the app name', function() {
+                    expect(cfg.shortName()).toEqual('Hello Cordova');
+                });
+
+                it('should allow setting the app short name', function() {
+                    cfg.setShortName('Hi CDV');
+                    expect(cfg.name()).toEqual('Hello Cordova');
+                    expect(cfg.shortName()).toEqual('Hi CDV');
+                });
+            });
         });
+
         describe('preference', function() {
             it('Test 010 : should return the value of a global preference', function() {
                 expect(cfg.getPreference('fullscreen')).toEqual('true');
index e477a89..cd718de 100644 (file)
@@ -116,6 +116,16 @@ ConfigParser.prototype = {
         var el = findOrCreate(this.doc, 'name');
         el.text = name;
     },
+    shortName: function() {
+        return this.doc.find('name').attrib['short'] || this.name();
+    },
+    setShortName: function(shortname) {
+        var el = findOrCreate(this.doc, 'name');
+        if (!el.text) {
+            el.text = shortname;
+        }
+        el.attrib['short'] = shortname;
+    },
     description: function() {
         return getNodeTextSafe(this.doc.find('description'));
     },