wlxml: Remove "meta-" prefix for defined (aka "meta") attributes
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 17 Dec 2013 13:52:24 +0000 (14:52 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 17 Dec 2013 13:52:24 +0000 (14:52 +0100)
This change unifies structure type returned by getOtherAttributes
with the one returned by getMetaAttributes so that these two can
be easily merged if necessary.

src/wlxml/wlxml.js
src/wlxml/wlxml.test.js

index a320da3..7f6e931 100644 (file)
@@ -9,13 +9,6 @@ define([
 
 /* globals Node */
 
 
 /* globals Node */
 
-// utils
-
-var isMetaAttribute = function(attrName) {
-    return attrName.substr(0, 5) === 'meta-';
-};
-
-//
 
 var AttributesList = function() {};
 AttributesList.prototype = Object.create({});
 
 var AttributesList = function() {};
 AttributesList.prototype = Object.create({});
@@ -62,24 +55,28 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, {
             classDesc = this.document.options.wlxmlClasses[classCurrent];
             if(classDesc) {
                 _.keys(classDesc.attrs).forEach(function(attrName) {
             classDesc = this.document.options.wlxmlClasses[classCurrent];
             if(classDesc) {
                 _.keys(classDesc.attrs).forEach(function(attrName) {
-                    toret[attrName] = _.extend({value: this.getAttr('meta-' + attrName)}, classDesc.attrs[attrName]);
+                    toret[attrName] = _.extend({value: this.getAttr(attrName)}, classDesc.attrs[attrName]);
                 }.bind(this));
             }
         }.bind(this));
         return toret;
     },
     setMetaAttribute: function(key, value) {
                 }.bind(this));
             }
         }.bind(this));
         return toret;
     },
     setMetaAttribute: function(key, value) {
-        this.setAttr('meta-'+key, value);
+        this.setAttr(key, value);
     },
     getOtherAttributes: function() {
     },
     getOtherAttributes: function() {
-        var toret = {};
+        var toret = {},
+            node = this;
         this.getAttrs().forEach(function(attr) {
         this.getAttrs().forEach(function(attr) {
-            if(attr.name !== 'class' && !isMetaAttribute(attr.name)) {
-                toret[attr.name] = attr.value;
+            if(attr.name !== 'class' && !node.isMetaAttribute(attr.name)) {
+                toret[attr.name] = {value: attr.value};
             }
         });
         return toret;
     },
             }
         });
         return toret;
     },
+    isMetaAttribute: function(attrName) {
+        return attrName !== 'class' &&_.contains(_.keys(this.getMetaAttributes()), attrName);
+    },
 
     _getXMLDOMToDump: function() {
         var DOM = this._$.clone(true, true);
 
     _getXMLDOMToDump: function() {
         var DOM = this._$.clone(true, true);
index 9f846f6..516b47c 100644 (file)
@@ -27,9 +27,14 @@ describe('WLXMLDocument', function() {
             expect(node.getClass()).to.equal('class.subclass');
         });
 
             expect(node.getClass()).to.equal('class.subclass');
         });
 
-        it('returns attributes other than class and meta-* as other attributes', function() {
-            var node = nodeFromXML('<span class="uri" meta-attr="val" attr1="val1" attr2="val2"></span>');
-            expect(node.getOtherAttributes()).to.eql({attr1: 'val1', attr2: 'val2'});
+        it('returns unregistered attributes', function() {
+            var testClasses = {
+                    'testClass': {
+                        attrs: {'attr1': {type: 'string'}}
+                    }
+                },
+                doc = getDocumentFromXML('<span class="testClass" attr="val" attr1="val1"></span>', {wlxmlClasses: testClasses});
+            expect(doc.root.getOtherAttributes()).to.eql({attr: {value:'val'}});
         });
     });
 
         });
     });
 
@@ -76,7 +81,7 @@ describe('WLXMLDocument', function() {
                         }
                     },
                     node = getDocumentFromXML(
                         }
                     },
                     node = getDocumentFromXML(
-                        '<span class="test" meta-attr1="val1" meta-attr2="2014-01-01"></span>',
+                        '<span class="test" attr1="val1" attr2="2014-01-01"></span>',
                         {wlxmlClasses: testClasses}
                     ).root,
                     attrs = node.getMetaAttributes();
                         {wlxmlClasses: testClasses}
                     ).root,
                     attrs = node.getMetaAttributes();