From cb5f162babe577ede5a113b49d072b51a97ecaad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 17 Dec 2013 14:52:24 +0100 Subject: [PATCH] wlxml: Remove "meta-" prefix for defined (aka "meta") attributes 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 | 21 +++++++++------------ src/wlxml/wlxml.test.js | 13 +++++++++---- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index a320da3..7f6e931 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -9,13 +9,6 @@ define([ /* globals Node */ -// utils - -var isMetaAttribute = function(attrName) { - return attrName.substr(0, 5) === 'meta-'; -}; - -// 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) { - 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) { - this.setAttr('meta-'+key, value); + this.setAttr(key, value); }, getOtherAttributes: function() { - var toret = {}; + var toret = {}, + node = this; 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; }, + isMetaAttribute: function(attrName) { + return attrName !== 'class' &&_.contains(_.keys(this.getMetaAttributes()), attrName); + }, _getXMLDOMToDump: function() { var DOM = this._$.clone(true, true); diff --git a/src/wlxml/wlxml.test.js b/src/wlxml/wlxml.test.js index 9f846f6..516b47c 100644 --- a/src/wlxml/wlxml.test.js +++ b/src/wlxml/wlxml.test.js @@ -27,9 +27,14 @@ describe('WLXMLDocument', function() { expect(node.getClass()).to.equal('class.subclass'); }); - it('returns attributes other than class and meta-* as other attributes', function() { - var node = nodeFromXML(''); - expect(node.getOtherAttributes()).to.eql({attr1: 'val1', attr2: 'val2'}); + it('returns unregistered attributes', function() { + var testClasses = { + 'testClass': { + attrs: {'attr1': {type: 'string'}} + } + }, + doc = getDocumentFromXML('', {wlxmlClasses: testClasses}); + expect(doc.root.getOtherAttributes()).to.eql({attr: {value:'val'}}); }); }); @@ -76,7 +81,7 @@ describe('WLXMLDocument', function() { } }, node = getDocumentFromXML( - '', + '', {wlxmlClasses: testClasses} ).root, attrs = node.getMetaAttributes(); -- 2.20.1