Project

General

Profile

Feature #10789 » child_pages_with_depth1.patch

Alexander Oryol, 2012-04-27 11:17

View differences:

lib/redmine/wiki_formatting/macros.rb
" !{{child_pages}} -- can be used from a wiki page only\n" +
" !{{child_pages(Foo)}} -- lists all children of page Foo\n" +
" !{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo"
" !{{child_pages(Foo, parent=1, depth=3)}} -- same as above with specified nesting level (default 2)"
macro :child_pages do |obj, args|
args, options = extract_macro_options(args, :parent)
args, options = extract_macro_options(args, :parent, :depth)
page = nil
if args.size > 0
page = Wiki.find_page(args.first.to_s, :project => @project)
......
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] + page.descendants(options[:depth])).group_by(&:parent_id)
render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id)
end
vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb
# Returns list of descendants.
#
# root.descendants # => [child1, subchild1, subchild2]
def descendants
children + children.collect(&:children).flatten
# root.descendants(1) # => [child1]
#
# Defaults: depth = 2 (old behavior)
def descendants(depth=2)
depth = 2 if depth.nil?
depth = depth.to_i
result = children.dup
result += children.collect { |item| item.descendants(depth-1) }.flatten if depth > 1
result
end
# Returns list of descendants and a reference to the current node.
(2-2/2)