diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-09-16 15:24:35 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-09-16 15:24:35 +0000 |
commit | 747e4ecd3a981e5d48d3028f5cd870b130eb65b4 (patch) | |
tree | 8f8bdf941521d4647db1ebcb0e9c450427ecbd63 /lib/plugins | |
parent | ca4f2c59b6479ad088aa87e6173bcdd5c7c66629 (diff) | |
download | redmine-747e4ecd3a981e5d48d3028f5cd870b130eb65b4.tar.gz redmine-747e4ecd3a981e5d48d3028f5cd870b130eb65b4.zip |
Adds a "depth" option to the child_pages macro (#10789).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10401 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb b/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb index 79d164485..a1c83cf50 100644 --- a/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb +++ b/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb @@ -73,15 +73,20 @@ module ActiveRecord # Returns list of descendants. # # root.descendants # => [child1, subchild1, subchild2] - def descendants - children + children.collect(&:descendants).flatten + def descendants(depth=nil) + depth ||= 0 + result = children.dup + unless depth == 1 + result += children.collect {|child| child.descendants(depth-1)}.flatten + end + result end # Returns list of descendants and a reference to the current node. # # root.self_and_descendants # => [root, child1, subchild1, subchild2] - def self_and_descendants - [self] + descendants + def self_and_descendants(depth=nil) + [self] + descendants(depth) end # Returns the root node of the tree. |