Commit 33021c04 authored by Ryan LeFevre's avatar Ryan LeFevre

Fix some ancestry functions

parent b2a661b5
......@@ -8,4 +8,4 @@ console.log(psd.header.export());
// console.log("Finished!");
// });
console.log(psd.tree().children[0].export());
\ No newline at end of file
console.log(psd.tree().children[0].children[0].nextSibling().export());
\ No newline at end of file
......@@ -11,12 +11,12 @@ module.exports =
return [] if not @parent? or @parent.isRoot()
return @parent.ancestors().concat [@parent]
hasChildren: -> @children().length > 0
hasChildren: -> @children.length > 0
childless: -> not @hasChildren()
siblings: ->
return [] unless @parent?
@parent.children()
@parent.children
nextSibling: ->
return null unless @parent?
......@@ -31,12 +31,12 @@ module.exports =
hasSiblings: -> @siblings().length > 1
onlyChild: -> not @hasSiblings()
descendants: -> _.flatten @children().map((n) -> n.subtree())
descendants: -> _.flatten @children.map((n) -> n.subtree())
subtree: -> [@].concat @descendants()
depth: -> @ancestors().length + 1
path: (asArray = false) ->
path = @ancestors.map((n) -> n.name).concat([@name])
path = @ancestors().map((n) -> n.name).concat([@name])
if asArray then path else path.join('/')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment