Y-Xml tests pass
This commit is contained in:
@@ -216,19 +216,19 @@ module.exports = ()->
|
||||
o
|
||||
|
||||
push: (content)->
|
||||
@insertAfter @end.prev_cl, content
|
||||
@insertAfter @end.prev_cl, [content]
|
||||
|
||||
insertAfter: (left, content)->
|
||||
insertAfter: (left, contents)->
|
||||
right = left.next_cl
|
||||
while right.isDeleted()
|
||||
right = right.next_cl # find the first character to the right, that is not deleted. In the case that position is 0, its the Delimiter.
|
||||
left = right.prev_cl
|
||||
|
||||
# TODO: always expect an array as content. Then you can combine this with the other option (else)
|
||||
if content instanceof ops.Operation
|
||||
if contents instanceof ops.Operation
|
||||
(new ops.Insert null, content, undefined, left, right).execute()
|
||||
else
|
||||
for c in content
|
||||
for c in contents
|
||||
if c? and c._name? and c._getModel?
|
||||
c = c._getModel(@custom_types, @operations)
|
||||
tmp = (new ops.Insert null, c, undefined, left, right).execute()
|
||||
@@ -236,22 +236,23 @@ module.exports = ()->
|
||||
@
|
||||
|
||||
#
|
||||
# Inserts a string into the word.
|
||||
# Inserts an array of content into this list.
|
||||
# @Note: This expects an array as content!
|
||||
#
|
||||
# @return {ListManager Type} This String object.
|
||||
#
|
||||
insert: (position, content)->
|
||||
insert: (position, contents)->
|
||||
ith = @getOperationByPosition position
|
||||
# the (i-1)th character. e.g. "abc" the 1th character is "a"
|
||||
# the 0th character is the left Delimiter
|
||||
@insertAfter ith, [content]
|
||||
@insertAfter ith, contents
|
||||
|
||||
#
|
||||
# Deletes a part of the word.
|
||||
#
|
||||
# @return {ListManager Type} This String object
|
||||
#
|
||||
delete: (position, length)->
|
||||
delete: (position, length = 1)->
|
||||
o = @getOperationByPosition(position+1) # position 0 in this case is the deletion of the first character
|
||||
|
||||
delete_ops = []
|
||||
|
||||
@@ -17,7 +17,7 @@ class YList
|
||||
_getModel: (types, ops)->
|
||||
if not @_model?
|
||||
@_model = new ops.ListManager(@).execute()
|
||||
@insert 0, @_list
|
||||
@_model.insert 0, @_list
|
||||
delete @_list
|
||||
@_model
|
||||
|
||||
@@ -36,14 +36,20 @@ class YList
|
||||
@
|
||||
|
||||
#
|
||||
# Inserts a Array into the list.
|
||||
# Inserts an Object into the list.
|
||||
#
|
||||
# @return {ListManager Type} This String object.
|
||||
#
|
||||
insert: (position, content)->
|
||||
if typeof position isnt "number"
|
||||
throw new Error "Y.List.insert expects a Number as the first parameter!"
|
||||
@_model.insert position, content
|
||||
@_model.insert position, [content]
|
||||
@
|
||||
|
||||
insertContents: (position, contents)->
|
||||
if typeof position isnt "number"
|
||||
throw new Error "Y.List.insert expects a Number as the first parameter!"
|
||||
@_model.insert position, contents
|
||||
@
|
||||
|
||||
delete: (position, length)->
|
||||
|
||||
@@ -30,6 +30,8 @@ class YXml
|
||||
@_model.val("classes", new Y.Object(@_xml.classes))
|
||||
@_model.val("tagname", @_xml.tagname)
|
||||
@_model.val("children", new Y.List())
|
||||
if @_xml.parent?
|
||||
@_model.val("parent", @_xml.parent)
|
||||
delete @_xml
|
||||
@_model
|
||||
|
||||
@@ -38,8 +40,11 @@ class YXml
|
||||
|
||||
_setParent: (parent)->
|
||||
if parent instanceof YXml
|
||||
@remove()
|
||||
@_model.val("parent", parent)
|
||||
if @_model?
|
||||
@remove()
|
||||
@_model.val("parent", parent)
|
||||
else
|
||||
@_xml.parent = parent
|
||||
else
|
||||
throw new Error "parent must be of type Y.Xml!"
|
||||
|
||||
@@ -95,30 +100,32 @@ class YXml
|
||||
throw new Error "This Xml Element must not have siblings! (for it does not have a parent)"
|
||||
|
||||
# find the position of this element
|
||||
for c,position in parent.val("children").val()
|
||||
for c,position in parent.getChildren()
|
||||
if c is @
|
||||
break
|
||||
|
||||
contents = []
|
||||
for content in arguments
|
||||
if not (content instanceof YXml or content.constructor is String)
|
||||
if content instanceof YXml
|
||||
content._setParent(@_model.val("parent"))
|
||||
else if content.constructor isnt String
|
||||
throw new Error "Y.Xml.after expects instances of YXml or String as a parameter"
|
||||
contents.push content
|
||||
|
||||
parent._model.val("children").insert(position+1, contents)
|
||||
parent._model.val("children").insertContents(position+1, contents)
|
||||
|
||||
#
|
||||
# Insert content, specified by the parameter, to the end of this element
|
||||
# .append(content [, content])
|
||||
#
|
||||
append: ()->
|
||||
contents = []
|
||||
for content in arguments
|
||||
if not (content instanceof YXml or content.constructor is String)
|
||||
if content instanceof YXml
|
||||
content._setParent(@)
|
||||
else if content.constructor isnt String
|
||||
throw new Error "Y.Xml.after expects instances of YXml or String as a parameter"
|
||||
contents.push content
|
||||
|
||||
@_model.val("children").push(contents)
|
||||
@_model.val("children").push(content)
|
||||
@
|
||||
|
||||
#
|
||||
# Insert content, specified by the parameter, after this element
|
||||
@@ -130,23 +137,26 @@ class YXml
|
||||
throw new Error "This Xml Element must not have siblings! (for it does not have a parent)"
|
||||
|
||||
# find the position of this element
|
||||
for c,position in parent.val("children").val()
|
||||
for c,position in parent.getChildren()
|
||||
if c is @
|
||||
break
|
||||
|
||||
contents = []
|
||||
for content in arguments
|
||||
if not (content instanceof YXml or content.constructor is String)
|
||||
if content instanceof YXml
|
||||
content._setParent(@_model.val("parent"))
|
||||
else if content.constructor isnt String
|
||||
throw new Error "Y.Xml.after expects instances of YXml or String as a parameter"
|
||||
contents.push content
|
||||
|
||||
parent._model.val("children").insert(position, contents)
|
||||
parent._model.val("children").insertContents(position, contents)
|
||||
|
||||
#
|
||||
# Remove all child nodes of the set of matched elements from the DOM.
|
||||
# .empty()
|
||||
#
|
||||
empty: ()->
|
||||
# TODO: do it like this : @_model.val("children", new Y.List())
|
||||
for child in @_model.val("children").val()
|
||||
child.remove()
|
||||
|
||||
@@ -165,13 +175,13 @@ class YXml
|
||||
# .prepend(content [, content])
|
||||
#
|
||||
prepend: ()->
|
||||
contents = []
|
||||
for content in arguments
|
||||
if not (content instanceof YXml or content.constructor is String)
|
||||
if content instanceof YXml
|
||||
content._setParent(@)
|
||||
else if content.constructor isnt String
|
||||
throw new Error "Y.Xml.after expects instances of YXml or String as a parameter"
|
||||
contents.push content
|
||||
|
||||
@_model.val("children").insert(0, contents)
|
||||
@_model.val("children").insert(0, content)
|
||||
@
|
||||
|
||||
#
|
||||
# Remove this element from the DOM
|
||||
@@ -182,7 +192,7 @@ class YXml
|
||||
if parent instanceof YXml
|
||||
for c,i in parent.getChildren()
|
||||
if c is @
|
||||
parent._model.delete i
|
||||
parent._model.val("children").delete i
|
||||
break
|
||||
undefined
|
||||
|
||||
|
||||
Reference in New Issue
Block a user