Wiki links can now refer other project wikis, using this syntax:
[[project:]] -> wiki starting page [[project:page]] [[project:page|text]] where 'project' is the project name or identifier. git-svn-id: http://redmine.rubyforge.org/svn/trunk@643 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
38e0c237a4
commit
a5849ee044
|
@ -126,23 +126,33 @@ module ApplicationHelper
|
||||||
case options[:wiki_links]
|
case options[:wiki_links]
|
||||||
when :local
|
when :local
|
||||||
# used for local links to html files
|
# used for local links to html files
|
||||||
format_wiki_link = Proc.new {|title| "#{title}.html" }
|
format_wiki_link = Proc.new {|project, title| "#{title}.html" }
|
||||||
when :anchor
|
when :anchor
|
||||||
# used for single-file wiki export
|
# used for single-file wiki export
|
||||||
format_wiki_link = Proc.new {|title| "##{title}" }
|
format_wiki_link = Proc.new {|project, title| "##{title}" }
|
||||||
else
|
else
|
||||||
if @project
|
format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
|
||||||
format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title }
|
|
||||||
else
|
|
||||||
format_wiki_link = Proc.new {|title| title }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# turn wiki links into textile links:
|
# turn wiki links into html links
|
||||||
# example:
|
# example:
|
||||||
# [[link]] -> "link":link
|
# [[mypage]]
|
||||||
# [[link|title]] -> "title":link
|
# [[mypage|mytext]]
|
||||||
text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| link_to(($3 || $1), format_wiki_link.call(Wiki.titleize($1)), :class => 'wiki-page') }
|
# wiki links can refer other project wikis, using project name or identifier:
|
||||||
|
# [[project:]] -> wiki starting page
|
||||||
|
# [[project:mypage]]
|
||||||
|
# [[project:mypage|mytext]]
|
||||||
|
text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) do |m|
|
||||||
|
project = @project
|
||||||
|
page = $1
|
||||||
|
title = $3
|
||||||
|
if page =~ /^([^\:]+)\:(.*)$/
|
||||||
|
project = Project.find_by_name($1) || Project.find_by_identifier($1)
|
||||||
|
page = $2
|
||||||
|
title = $1 if page.blank?
|
||||||
|
end
|
||||||
|
link_to((title || page), format_wiki_link.call(project, Wiki.titleize(page)), :class => 'wiki-page')
|
||||||
|
end
|
||||||
|
|
||||||
# turn issue ids into links
|
# turn issue ids into links
|
||||||
# example:
|
# example:
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Wiki < ActiveRecord::Base
|
||||||
has_many :pages, :class_name => 'WikiPage', :dependent => :destroy
|
has_many :pages, :class_name => 'WikiPage', :dependent => :destroy
|
||||||
|
|
||||||
validates_presence_of :start_page
|
validates_presence_of :start_page
|
||||||
validates_format_of :start_page, :with => /^[^,\.\/\?\;\|]*$/
|
validates_format_of :start_page, :with => /^[^,\.\/\?\;\|\:]*$/
|
||||||
|
|
||||||
# find the page with the given title
|
# find the page with the given title
|
||||||
# if page doesn't exist, return a new page
|
# if page doesn't exist, return a new page
|
||||||
|
@ -38,9 +38,9 @@ class Wiki < ActiveRecord::Base
|
||||||
# turn a string into a valid page title
|
# turn a string into a valid page title
|
||||||
def self.titleize(title)
|
def self.titleize(title)
|
||||||
# replace spaces with _ and remove unwanted caracters
|
# replace spaces with _ and remove unwanted caracters
|
||||||
title = title.gsub(/\s+/, '_').delete(',./?;|') if title
|
title = title.gsub(/\s+/, '_').delete(',./?;|:') if title
|
||||||
# upcase the first letter
|
# upcase the first letter
|
||||||
title = title[0..0].upcase + title[1..-1] if title
|
title = (title.length > 1 ? title.first.upcase + title[1..-1] : title.upcase) if title
|
||||||
title
|
title
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue