summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
fb23a59)
This change unifies structure type returned by getOtherAttributes
with the one returned by getMetaAttributes so that these two can
be easily merged if necessary.
-// 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({});
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 = {},
+ 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};
+ 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);
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'}});
}
},
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();