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
This commit is contained in:
Jean-Philippe Lang
2007-03-09 20:03:25 +00:00
parent 02ff5764d5
commit 5dfb162fb6

View File

@@ -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 = {})