@@ -77,21 +77,24 module Redmine | |||||
77 | content_tag('dl', out) |
|
77 | content_tag('dl', out) | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | desc "Include a wiki page. Example:\n\n !{{include(Foo)}}" |
|
80 | 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)}}" | |
81 | macro :include do |obj, args| |
|
81 | macro :include do |obj, args| | |
82 | if @project && !@project.wiki.nil? |
|
82 | project = @project | |
83 | page = @project.wiki.find_page(args.first) |
|
83 | title = args.first.to_s | |
84 | if page && page.content |
|
84 | if title =~ %r{^([^\:]+)\:(.*)$} | |
85 | @included_wiki_pages ||= [] |
|
85 | project_identifier, title = $1, $2 | |
86 | raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title) |
|
86 | project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier) | |
87 | @included_wiki_pages << page.title |
|
|||
88 | out = textilizable(page.content, :text, :attachments => page.attachments) |
|
|||
89 | @included_wiki_pages.pop |
|
|||
90 | out |
|
|||
91 | else |
|
|||
92 | raise "Page #{args.first} doesn't exist" |
|
|||
93 | end |
|
|||
94 | end |
|
87 | end | |
|
88 | raise 'Unknow project' unless project && User.current.allowed_to?(:view_wiki_pages, project) | |||
|
89 | raise 'No wiki for this project' unless !project.wiki.nil? | |||
|
90 | page = project.wiki.find_page(title) | |||
|
91 | raise "Page #{args.first} doesn't exist" unless page && page.content | |||
|
92 | @included_wiki_pages ||= [] | |||
|
93 | raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title) | |||
|
94 | @included_wiki_pages << page.title | |||
|
95 | out = textilizable(page.content, :text, :attachments => page.attachments) | |||
|
96 | @included_wiki_pages.pop | |||
|
97 | out | |||
95 | end |
|
98 | end | |
96 | end |
|
99 | end | |
97 | end |
|
100 | end |
@@ -168,6 +168,24 class ApplicationHelperTest < HelperTestCase | |||||
168 | assert_equal '<p>{{hello_world}}</p>', textilizable(text) |
|
168 | assert_equal '<p>{{hello_world}}</p>', textilizable(text) | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
|
171 | def test_macro_include | |||
|
172 | @project = Project.find(1) | |||
|
173 | # include a page of the current project wiki | |||
|
174 | text = "{{include(Another page)}}" | |||
|
175 | assert textilizable(text).match(/This is a link to a ticket/) | |||
|
176 | ||||
|
177 | @project = nil | |||
|
178 | # include a page of a specific project wiki | |||
|
179 | text = "{{include(ecookbook:Another page)}}" | |||
|
180 | assert textilizable(text).match(/This is a link to a ticket/) | |||
|
181 | ||||
|
182 | text = "{{include(ecookbook:)}}" | |||
|
183 | assert textilizable(text).match(/CookBook documentation/) | |||
|
184 | ||||
|
185 | text = "{{include(unknowidentifier:somepage)}}" | |||
|
186 | assert textilizable(text).match(/Unknow project/) | |||
|
187 | end | |||
|
188 | ||||
171 | def test_date_format_default |
|
189 | def test_date_format_default | |
172 | today = Date.today |
|
190 | today = Date.today | |
173 | Setting.date_format = '' |
|
191 | Setting.date_format = '' |
General Comments 0
You need to be logged in to leave comments.
Login now