##// END OF EJS Templates
Wiki links can now refer other project wikis, using this syntax:...
Jean-Philippe Lang -
r637:a5849ee04483
parent child
Show More
@@ -126,23 +126,33 module ApplicationHelper
126 case options[:wiki_links]
126 case options[:wiki_links]
127 when :local
127 when :local
128 # used for local links to html files
128 # used for local links to html files
129 format_wiki_link = Proc.new {|title| "#{title}.html" }
129 format_wiki_link = Proc.new {|project, title| "#{title}.html" }
130 when :anchor
130 when :anchor
131 # used for single-file wiki export
131 # used for single-file wiki export
132 format_wiki_link = Proc.new {|title| "##{title}" }
132 format_wiki_link = Proc.new {|project, title| "##{title}" }
133 else
133 else
134 if @project
134 format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
135 format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title }
136 else
137 format_wiki_link = Proc.new {|title| title }
138 end
139 end
135 end
140
136
141 # turn wiki links into textile links:
137 # turn wiki links into html links
142 # example:
138 # example:
143 # [[link]] -> "link":link
139 # [[mypage]]
144 # [[link|title]] -> "title":link
140 # [[mypage|mytext]]
145 text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| link_to(($3 || $1), format_wiki_link.call(Wiki.titleize($1)), :class => 'wiki-page') }
141 # wiki links can refer other project wikis, using project name or identifier:
142 # [[project:]] -> wiki starting page
143 # [[project:mypage]]
144 # [[project:mypage|mytext]]
145 text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) do |m|
146 project = @project
147 page = $1
148 title = $3
149 if page =~ /^([^\:]+)\:(.*)$/
150 project = Project.find_by_name($1) || Project.find_by_identifier($1)
151 page = $2
152 title = $1 if page.blank?
153 end
154 link_to((title || page), format_wiki_link.call(project, Wiki.titleize(page)), :class => 'wiki-page')
155 end
146
156
147 # turn issue ids into links
157 # turn issue ids into links
148 # example:
158 # example:
@@ -20,7 +20,7 class Wiki < ActiveRecord::Base
20 has_many :pages, :class_name => 'WikiPage', :dependent => :destroy
20 has_many :pages, :class_name => 'WikiPage', :dependent => :destroy
21
21
22 validates_presence_of :start_page
22 validates_presence_of :start_page
23 validates_format_of :start_page, :with => /^[^,\.\/\?\;\|]*$/
23 validates_format_of :start_page, :with => /^[^,\.\/\?\;\|\:]*$/
24
24
25 # find the page with the given title
25 # find the page with the given title
26 # if page doesn't exist, return a new page
26 # if page doesn't exist, return a new page
@@ -38,9 +38,9 class Wiki < ActiveRecord::Base
38 # turn a string into a valid page title
38 # turn a string into a valid page title
39 def self.titleize(title)
39 def self.titleize(title)
40 # replace spaces with _ and remove unwanted caracters
40 # replace spaces with _ and remove unwanted caracters
41 title = title.gsub(/\s+/, '_').delete(',./?;|') if title
41 title = title.gsub(/\s+/, '_').delete(',./?;|:') if title
42 # upcase the first letter
42 # upcase the first letter
43 title = title[0..0].upcase + title[1..-1] if title
43 title = (title.length > 1 ? title.first.upcase + title[1..-1] : title.upcase) if title
44 title
44 title
45 end
45 end
46 end
46 end
General Comments 0
You need to be logged in to leave comments. Login now