Include macro can include a page of another project wiki using !{{include(projectname:Foo)}} (#1052).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1350 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e644435715
commit
0329094f01
@ -77,21 +77,24 @@ module Redmine
|
|||||||
content_tag('dl', out)
|
content_tag('dl', out)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Include a wiki page. Example:\n\n !{{include(Foo)}}"
|
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)}}"
|
||||||
macro :include do |obj, args|
|
macro :include do |obj, args|
|
||||||
if @project && !@project.wiki.nil?
|
project = @project
|
||||||
page = @project.wiki.find_page(args.first)
|
title = args.first.to_s
|
||||||
if page && page.content
|
if title =~ %r{^([^\:]+)\:(.*)$}
|
||||||
@included_wiki_pages ||= []
|
project_identifier, title = $1, $2
|
||||||
raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title)
|
project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
|
||||||
@included_wiki_pages << page.title
|
|
||||||
out = textilizable(page.content, :text, :attachments => page.attachments)
|
|
||||||
@included_wiki_pages.pop
|
|
||||||
out
|
|
||||||
else
|
|
||||||
raise "Page #{args.first} doesn't exist"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
raise 'Unknow project' unless project && User.current.allowed_to?(:view_wiki_pages, project)
|
||||||
|
raise 'No wiki for this project' unless !project.wiki.nil?
|
||||||
|
page = project.wiki.find_page(title)
|
||||||
|
raise "Page #{args.first} doesn't exist" unless page && page.content
|
||||||
|
@included_wiki_pages ||= []
|
||||||
|
raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title)
|
||||||
|
@included_wiki_pages << page.title
|
||||||
|
out = textilizable(page.content, :text, :attachments => page.attachments)
|
||||||
|
@included_wiki_pages.pop
|
||||||
|
out
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -168,6 +168,24 @@ class ApplicationHelperTest < HelperTestCase
|
|||||||
assert_equal '<p>{{hello_world}}</p>', textilizable(text)
|
assert_equal '<p>{{hello_world}}</p>', textilizable(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_macro_include
|
||||||
|
@project = Project.find(1)
|
||||||
|
# include a page of the current project wiki
|
||||||
|
text = "{{include(Another page)}}"
|
||||||
|
assert textilizable(text).match(/This is a link to a ticket/)
|
||||||
|
|
||||||
|
@project = nil
|
||||||
|
# include a page of a specific project wiki
|
||||||
|
text = "{{include(ecookbook:Another page)}}"
|
||||||
|
assert textilizable(text).match(/This is a link to a ticket/)
|
||||||
|
|
||||||
|
text = "{{include(ecookbook:)}}"
|
||||||
|
assert textilizable(text).match(/CookBook documentation/)
|
||||||
|
|
||||||
|
text = "{{include(unknowidentifier:somepage)}}"
|
||||||
|
assert textilizable(text).match(/Unknow project/)
|
||||||
|
end
|
||||||
|
|
||||||
def test_date_format_default
|
def test_date_format_default
|
||||||
today = Date.today
|
today = Date.today
|
||||||
Setting.date_format = ''
|
Setting.date_format = ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user