@@ -77,21 +77,24 module Redmine | |||
|
77 | 77 | content_tag('dl', out) |
|
78 | 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 | 81 | macro :include do |obj, args| |
|
82 | if @project && !@project.wiki.nil? | |
|
83 | page = @project.wiki.find_page(args.first) | |
|
84 | if page && page.content | |
|
82 | project = @project | |
|
83 | title = args.first.to_s | |
|
84 | if title =~ %r{^([^\:]+)\:(.*)$} | |
|
85 | project_identifier, title = $1, $2 | |
|
86 | project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier) | |
|
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 | |
|
85 | 92 |
|
|
86 | 93 |
|
|
87 | 94 |
|
|
88 | 95 |
|
|
89 | 96 |
|
|
90 | 97 |
|
|
91 | else | |
|
92 | raise "Page #{args.first} doesn't exist" | |
|
93 | end | |
|
94 | end | |
|
95 | 98 | end |
|
96 | 99 | end |
|
97 | 100 | end |
@@ -168,6 +168,24 class ApplicationHelperTest < HelperTestCase | |||
|
168 | 168 | assert_equal '<p>{{hello_world}}</p>', textilizable(text) |
|
169 | 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 | 189 | def test_date_format_default |
|
172 | 190 | today = Date.today |
|
173 | 191 | Setting.date_format = '' |
General Comments 0
You need to be logged in to leave comments.
Login now