summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb13
-rw-r--r--lib/redmine/wiki_formatting/macros.rb6
2 files changed, 13 insertions, 6 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.
diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb
index 23e6caf00..1ae86345b 100644
--- a/lib/redmine/wiki_formatting/macros.rb
+++ b/lib/redmine/wiki_formatting/macros.rb
@@ -183,7 +183,9 @@ module Redmine
" !{{child_pages(Foo)}} -- lists all children of page Foo\n" +
" !{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo"
macro :child_pages do |obj, args|
- args, options = extract_macro_options(args, :parent)
+ args, options = extract_macro_options(args, :parent, :depth)
+ options[:depth] = options[:depth].to_i if options[:depth].present?
+
page = nil
if args.size > 0
page = Wiki.find_page(args.first.to_s, :project => @project)
@@ -193,7 +195,7 @@ module Redmine
raise 'With no argument, this macro can be called from wiki pages only.'
end
raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
- pages = ([page] + page.descendants).group_by(&:parent_id)
+ pages = page.self_and_descendants(options[:depth]).group_by(&:parent_id)
render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id)
end