Y-Xml tests pass
This commit is contained in:
@@ -256,21 +256,21 @@ module.exports = function() {
|
||||
};
|
||||
|
||||
ListManager.prototype.push = function(content) {
|
||||
return this.insertAfter(this.end.prev_cl, content);
|
||||
return this.insertAfter(this.end.prev_cl, [content]);
|
||||
};
|
||||
|
||||
ListManager.prototype.insertAfter = function(left, content) {
|
||||
ListManager.prototype.insertAfter = function(left, contents) {
|
||||
var c, right, tmp, _i, _len;
|
||||
right = left.next_cl;
|
||||
while (right.isDeleted()) {
|
||||
right = right.next_cl;
|
||||
}
|
||||
left = right.prev_cl;
|
||||
if (content instanceof ops.Operation) {
|
||||
if (contents instanceof ops.Operation) {
|
||||
(new ops.Insert(null, content, void 0, left, right)).execute();
|
||||
} else {
|
||||
for (_i = 0, _len = content.length; _i < _len; _i++) {
|
||||
c = content[_i];
|
||||
for (_i = 0, _len = contents.length; _i < _len; _i++) {
|
||||
c = contents[_i];
|
||||
if ((c != null) && (c._name != null) && (c._getModel != null)) {
|
||||
c = c._getModel(this.custom_types, this.operations);
|
||||
}
|
||||
@@ -281,14 +281,17 @@ module.exports = function() {
|
||||
return this;
|
||||
};
|
||||
|
||||
ListManager.prototype.insert = function(position, content) {
|
||||
ListManager.prototype.insert = function(position, contents) {
|
||||
var ith;
|
||||
ith = this.getOperationByPosition(position);
|
||||
return this.insertAfter(ith, [content]);
|
||||
return this.insertAfter(ith, contents);
|
||||
};
|
||||
|
||||
ListManager.prototype["delete"] = function(position, length) {
|
||||
var d, delete_ops, i, o, _i;
|
||||
if (length == null) {
|
||||
length = 1;
|
||||
}
|
||||
o = this.getOperationByPosition(position + 1);
|
||||
delete_ops = [];
|
||||
for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) {
|
||||
|
||||
@@ -16,7 +16,7 @@ YList = (function() {
|
||||
YList.prototype._getModel = function(types, ops) {
|
||||
if (this._model == null) {
|
||||
this._model = new ops.ListManager(this).execute();
|
||||
this.insert(0, this._list);
|
||||
this._model.insert(0, this._list);
|
||||
}
|
||||
delete this._list;
|
||||
return this._model;
|
||||
@@ -45,7 +45,15 @@ YList = (function() {
|
||||
if (typeof position !== "number") {
|
||||
throw new Error("Y.List.insert expects a Number as the first parameter!");
|
||||
}
|
||||
this._model.insert(position, content);
|
||||
this._model.insert(position, [content]);
|
||||
return this;
|
||||
};
|
||||
|
||||
YList.prototype.insertContents = function(position, contents) {
|
||||
if (typeof position !== "number") {
|
||||
throw new Error("Y.List.insert expects a Number as the first parameter!");
|
||||
}
|
||||
this._model.insert(position, contents);
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ YXml = (function() {
|
||||
this._model.val("classes", new Y.Object(this._xml.classes));
|
||||
this._model.val("tagname", this._xml.tagname);
|
||||
this._model.val("children", new Y.List());
|
||||
if (this._xml.parent != null) {
|
||||
this._model.val("parent", this._xml.parent);
|
||||
}
|
||||
}
|
||||
delete this._xml;
|
||||
return this._model;
|
||||
@@ -54,8 +57,12 @@ YXml = (function() {
|
||||
|
||||
YXml.prototype._setParent = function(parent) {
|
||||
if (parent instanceof YXml) {
|
||||
this.remove();
|
||||
return this._model.val("parent", parent);
|
||||
if (this._model != null) {
|
||||
this.remove();
|
||||
return this._model.val("parent", parent);
|
||||
} else {
|
||||
return this._xml.parent = parent;
|
||||
}
|
||||
} else {
|
||||
throw new Error("parent must be of type Y.Xml!");
|
||||
}
|
||||
@@ -119,7 +126,7 @@ YXml = (function() {
|
||||
if (parent == null) {
|
||||
throw new Error("This Xml Element must not have siblings! (for it does not have a parent)");
|
||||
}
|
||||
_ref = parent.val("children").val();
|
||||
_ref = parent.getChildren();
|
||||
for (position = _i = 0, _len = _ref.length; _i < _len; position = ++_i) {
|
||||
c = _ref[position];
|
||||
if (c === this) {
|
||||
@@ -129,25 +136,28 @@ YXml = (function() {
|
||||
contents = [];
|
||||
for (_j = 0, _len1 = arguments.length; _j < _len1; _j++) {
|
||||
content = arguments[_j];
|
||||
if (!(content instanceof YXml || content.constructor === String)) {
|
||||
if (content instanceof YXml) {
|
||||
content._setParent(this._model.val("parent"));
|
||||
} else if (content.constructor !== String) {
|
||||
throw new Error("Y.Xml.after expects instances of YXml or String as a parameter");
|
||||
}
|
||||
contents.push(content);
|
||||
}
|
||||
return parent._model.val("children").insert(position + 1, contents);
|
||||
return parent._model.val("children").insertContents(position + 1, contents);
|
||||
};
|
||||
|
||||
YXml.prototype.append = function() {
|
||||
var content, contents, _i, _len;
|
||||
contents = [];
|
||||
var content, _i, _len;
|
||||
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
|
||||
content = arguments[_i];
|
||||
if (!(content instanceof YXml || content.constructor === String)) {
|
||||
if (content instanceof YXml) {
|
||||
content._setParent(this);
|
||||
} else if (content.constructor !== String) {
|
||||
throw new Error("Y.Xml.after expects instances of YXml or String as a parameter");
|
||||
}
|
||||
contents.push(content);
|
||||
this._model.val("children").push(content);
|
||||
}
|
||||
return this._model.val("children").push(contents);
|
||||
return this;
|
||||
};
|
||||
|
||||
YXml.prototype.before = function() {
|
||||
@@ -156,7 +166,7 @@ YXml = (function() {
|
||||
if (parent == null) {
|
||||
throw new Error("This Xml Element must not have siblings! (for it does not have a parent)");
|
||||
}
|
||||
_ref = parent.val("children").val();
|
||||
_ref = parent.getChildren();
|
||||
for (position = _i = 0, _len = _ref.length; _i < _len; position = ++_i) {
|
||||
c = _ref[position];
|
||||
if (c === this) {
|
||||
@@ -166,12 +176,14 @@ YXml = (function() {
|
||||
contents = [];
|
||||
for (_j = 0, _len1 = arguments.length; _j < _len1; _j++) {
|
||||
content = arguments[_j];
|
||||
if (!(content instanceof YXml || content.constructor === String)) {
|
||||
if (content instanceof YXml) {
|
||||
content._setParent(this._model.val("parent"));
|
||||
} else if (content.constructor !== String) {
|
||||
throw new Error("Y.Xml.after expects instances of YXml or String as a parameter");
|
||||
}
|
||||
contents.push(content);
|
||||
}
|
||||
return parent._model.val("children").insert(position, contents);
|
||||
return parent._model.val("children").insertContents(position, contents);
|
||||
};
|
||||
|
||||
YXml.prototype.empty = function() {
|
||||
@@ -194,16 +206,17 @@ YXml = (function() {
|
||||
};
|
||||
|
||||
YXml.prototype.prepend = function() {
|
||||
var content, contents, _i, _len;
|
||||
contents = [];
|
||||
var content, _i, _len;
|
||||
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
|
||||
content = arguments[_i];
|
||||
if (!(content instanceof YXml || content.constructor === String)) {
|
||||
if (content instanceof YXml) {
|
||||
content._setParent(this);
|
||||
} else if (content.constructor !== String) {
|
||||
throw new Error("Y.Xml.after expects instances of YXml or String as a parameter");
|
||||
}
|
||||
contents.push(content);
|
||||
this._model.val("children").insert(0, content);
|
||||
}
|
||||
return this._model.val("children").insert(0, contents);
|
||||
return this;
|
||||
};
|
||||
|
||||
YXml.prototype.remove = function() {
|
||||
@@ -214,7 +227,7 @@ YXml = (function() {
|
||||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||||
c = _ref[i];
|
||||
if (c === this) {
|
||||
parent._model["delete"](i);
|
||||
parent._model.val("children")["delete"](i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user