Project

General

Profile

Patch #3962 ยป maxnesting-parameter.patch

Oxan -, 2009-10-02 21:36

View differences:

app/helpers/application_helper.rb (working copy)
end
end
def render_page_hierarchy(pages, node=nil)
def render_page_hierarchy(pages, node=nil, maxnesting=nil, curnesting=0)
content = ''
if pages[node]
content << "<ul class=\"pages-hierarchy\">\n"
......
content << "<li>"
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :id => page.project, :page => page.title},
:title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
content << "\n" + render_page_hierarchy(pages, page.id, maxnesting, curnesting + 1) if pages[page.id] and (maxnesting.nil? or curnesting < maxnesting)
content << "</li>\n"
end
content << "</ul>\n"
lib/redmine/wiki_formatting/macros.rb (working copy)
desc "Displays a list of child pages. With no argument, it displays the child pages of the current wiki page. Examples:\n\n" +
" !{{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)}} -- same as above with a link to page Foo\n" +
" !{{child_pages(Foo, parent=1, maxnesting=1)}} -- maximum nesting of 1 (show only Foo and direct children)"
macro :child_pages do |obj, args|
args, options = extract_macro_options(args, :parent)
args, options = extract_macro_options(args, :parent, :maxnesting)
page = nil
if args.size > 0
page = Wiki.find_page(args.first.to_s, :project => @project)
......
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)
render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id)
render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id, options[:maxnesting].to_i)
end
desc "Include a wiki page. Example:\n\n !{{include(Foo)}}\n\nor to include a page of a specific project wiki:\n\n !{{include(projectname:Foo)}}"
    (1-1/1)