Project

General

Profile

Patch #2174 » macros.rb.patch

Jan Topiński, 2008-11-13 10:44

View differences:

lib/redmine/wiki_formatting/macros.rb (kopia robocza)
77 77
        content_tag('dl', out)
78 78
      end
79 79
      
80
      desc "Displays a list of child pages."
80
      desc "Displays page name and list of child pages. When no parameter is given only current page child pages are displayed. Example:\n\n  !{{child_pages(Foo)}}\n\nresults in:\n \n* [[Foo]]\n** [[bar 1]]\n** [[bar 2]]\n\nwhile:\n\n !{{child_pages}}\n\nwill result on page [[Foo]] with:\n\n** [[bar 1]]\n** [[bar 2]]"
81 81
      macro :child_pages do |obj, args|
82
        raise 'This macro applies to wiki pages only.' unless obj.is_a?(WikiContent)
83
        render_page_hierarchy(obj.page.descendants.group_by(&:parent_id), obj.page.id)
82
        if args.size > 0 then
83
          project = @project
84
          title = args.first.to_s
85
          if title =~ %r{^([^\:]+)\:(.*)$}
86
            project_identifier, title = $1, $2
87
            project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
88
          end
89
          raise 'Unknow project' unless project && User.current.allowed_to?(:view_wiki_pages, project)
90
          raise 'No wiki for this project' unless !project.wiki.nil?
91
          page = project.wiki.find_page(title)
92
          #collect descendants and root
93
          pages = (page.descendants+[page]).group_by(&:parent_id)
94
          render_page_hierarchy(pages, page.parent_id)
95
        else
96
          raise 'This macro applies to wiki pages only.' unless obj.is_a?(WikiContent)
97
          page = obj.page
98
          #retain orginal rendering without root page
99
          render_page_hierarchy(page.descendants.group_by(&:parent_id), page.id)
100
        end
84 101
      end
85 102
      
86 103
      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)}}"
(2-2/2)