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()); ...@@ -8,4 +8,4 @@ console.log(psd.header.export());
// console.log("Finished!"); // console.log("Finished!");
// }); // });
console.log(psd.tree().children[0].export()); console.log(psd.tree().children[0].children[0].nextSibling().export());
\ No newline at end of file \ No newline at end of file
...@@ -11,12 +11,12 @@ module.exports = ...@@ -11,12 +11,12 @@ module.exports =
return [] if not @parent? or @parent.isRoot() return [] if not @parent? or @parent.isRoot()
return @parent.ancestors().concat [@parent] return @parent.ancestors().concat [@parent]
hasChildren: -> @children().length > 0 hasChildren: -> @children.length > 0
childless: -> not @hasChildren() childless: -> not @hasChildren()
siblings: -> siblings: ->
return [] unless @parent? return [] unless @parent?
@parent.children() @parent.children
nextSibling: -> nextSibling: ->
return null unless @parent? return null unless @parent?
...@@ -31,12 +31,12 @@ module.exports = ...@@ -31,12 +31,12 @@ module.exports =
hasSiblings: -> @siblings().length > 1 hasSiblings: -> @siblings().length > 1
onlyChild: -> not @hasSiblings() onlyChild: -> not @hasSiblings()
descendants: -> _.flatten @children().map((n) -> n.subtree()) descendants: -> _.flatten @children.map((n) -> n.subtree())
subtree: -> [@].concat @descendants() subtree: -> [@].concat @descendants()
depth: -> @ancestors().length + 1 depth: -> @ancestors().length + 1
path: (asArray = false) -> 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('/') 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