summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-03-09 20:03:25 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-03-09 20:03:25 +0000
commit5dfb162fb6b97e24aab9a6eebd93096d91e2018f (patch)
treeaed427c5b1461e5f9bc0e41cf50b4696e615fba0
parent02ff5764d5c6ff3b8d5275b2e154dd961f2286d6 (diff)
downloadredmine-5dfb162fb6b97e24aab9a6eebd93096d91e2018f.tar.gz
redmine-5dfb162fb6b97e24aab9a6eebd93096d91e2018f.zip
modified textilizable helper method:
* no more eval statement * r12 in text will be turned into a link to the revision 12 in the repository * #12 in text will be turned into a link to the issue 12 git-svn-id: http://redmine.rubyforge.org/svn/branches/work@320 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--wiki/app/helpers/application_helper.rb35
1 files changed, 26 insertions, 9 deletions
diff --git a/wiki/app/helpers/application_helper.rb b/wiki/app/helpers/application_helper.rb
index 46eb12dd4..f9010df15 100644
--- a/wiki/app/helpers/application_helper.rb
+++ b/wiki/app/helpers/application_helper.rb
@@ -94,23 +94,40 @@ module ApplicationHelper
# textilize text according to system settings and RedCloth availability
def textilizable(text, options = {})
+ # different methods for formatting wiki links
case options[:wiki_links]
when :local
- wiki_link_format = 'Wiki.titleize($1) + ".html"'
+ # used for local links to html files
+ format_wiki_link = Proc.new {|title| "#{title}.html" }
when :anchor
- wiki_link_format = '"#" + Wiki.titleize($1)'
+ # used for single-file wiki export
+ format_wiki_link = Proc.new {|title| "##{title}" }
else
- if @project.nil?
- wiki_link_format = 'Wiki.titleize($1)'
+ if @project
+ format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title }
else
- wiki_link_format = '"/wiki/#{@project.id}/#{Wiki.titleize($1)}"'
+ format_wiki_link = Proc.new {|title| title }
end
end
- # turn wiki links in textile links: "text":url
- text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + (eval wiki_link_format) }
+
+ # turn wiki links into textile links:
+ # example:
+ # [[link]] -> "link":link
+ # [[link|title]] -> "title":link
+ text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + format_wiki_link.call(Wiki.titleize($1)) }
+
+ # turn issue ids to textile links
+ # example:
+ # #52 -> "#52":/issues/show/52
+ text = text.gsub(/#(\d+)([\s\.\(\)\-,:;])/) {|m| "\"##{$1}\":" + url_for(:controller => 'issues', :action => 'show', :id => $1) + $2 }
+
+ # turn revision ids to textile links (@project needed)
+ # example:
+ # r52 -> "r52":/repositories/revision/6?rev=52 (@project.id is 6)
+ text = text.gsub(/r(\d+)([\s\.\(\)\-,:;])/) {|m| "\"r#{$1}\":" + url_for(:controller => 'repositories', :action => 'revision', :id => @project.id, :rev => $1) + $2 } if @project
+
+ # finally textilize text
text = (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize") ? auto_link(RedCloth.new(text, [:filter_html]).to_html) : simple_format(auto_link(h(text)))
- # turn "#id" patterns into links to issues
- text = text.gsub(/#(\d+)([^;\d])/, "<a href='/issues/show/\\1'>#\\1</a>\\2")
end
def error_messages_for(object_name, options = {})