summaryrefslogtreecommitdiffstats
path: root/app/helpers/application_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r--app/helpers/application_helper.rb120
1 files changed, 60 insertions, 60 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 321d19007..ece92d615 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -405,11 +405,19 @@ module ApplicationHelper
raise ArgumentError, 'invalid arguments to textilizable'
end
return '' if text.blank?
+ project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
+ only_path = options.delete(:only_path) == false ? false : true
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
- only_path = options.delete(:only_path) == false ? false : true
-
+ [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
+ send method_name, text, project, obj, attr, only_path, options
+ end
+
+ text
+ end
+
+ def parse_inline_attachments(text, project, obj, attr, only_path, options)
# when using an image link, try to use an attachment, if possible
if options[:attachments] || (obj && obj.respond_to?(:attachments))
attachments = nil
@@ -429,33 +437,20 @@ module ApplicationHelper
end
end
end
+ end
-
- # different methods for formatting wiki links
- case options[:wiki_links]
- when :local
- # used for local links to html files
- format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" }
- when :anchor
- # used for single-file wiki export
- format_wiki_link = Proc.new {|project, title, anchor| "##{title}" }
- else
- format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
- end
-
- project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
-
- # Wiki links
- #
- # Examples:
- # [[mypage]]
- # [[mypage|mytext]]
- # wiki links can refer other project wikis, using project name or identifier:
- # [[project:]] -> wiki starting page
- # [[project:|mytext]]
- # [[project:mypage]]
- # [[project:mypage|mytext]]
- text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
+ # Wiki links
+ #
+ # Examples:
+ # [[mypage]]
+ # [[mypage|mytext]]
+ # wiki links can refer other project wikis, using project name or identifier:
+ # [[project:]] -> wiki starting page
+ # [[project:|mytext]]
+ # [[project:mypage]]
+ # [[project:mypage|mytext]]
+ def parse_wiki_links(text, project, obj, attr, only_path, options)
+ text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
link_project = project
esc, all, page, title = $1, $2, $3, $5
if esc.nil?
@@ -473,8 +468,13 @@ module ApplicationHelper
end
# check if page exists
wiki_page = link_project.wiki.find_page(page)
- link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor),
- :class => ('wiki-page' + (wiki_page ? '' : ' new')))
+ url = case options[:wiki_links]
+ when :local; "#{title}.html"
+ when :anchor; "##{title}" # used for single-file wiki export
+ else
+ url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
+ end
+ link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
else
# project or wiki doesn't exist
all
@@ -483,34 +483,36 @@ module ApplicationHelper
all
end
end
-
- # Redmine links
- #
- # Examples:
- # Issues:
- # #52 -> Link to issue #52
- # Changesets:
- # r52 -> Link to revision 52
- # commit:a85130f -> Link to scmid starting with a85130f
- # Documents:
- # document#17 -> Link to document with id 17
- # document:Greetings -> Link to the document with title "Greetings"
- # document:"Some document" -> Link to the document with title "Some document"
- # Versions:
- # version#3 -> Link to version with id 3
- # version:1.0.0 -> Link to version named "1.0.0"
- # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
- # Attachments:
- # attachment:file.zip -> Link to the attachment of the current object named file.zip
- # Source files:
- # source:some/file -> Link to the file located at /some/file in the project's repository
- # source:some/file@52 -> Link to the file's revision 52
- # source:some/file#L120 -> Link to line 120 of the file
- # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
- # export:some/file -> Force the download of the file
- # Forum messages:
- # message#1218 -> Link to message with id 1218
- text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
+ end
+
+ # Redmine links
+ #
+ # Examples:
+ # Issues:
+ # #52 -> Link to issue #52
+ # Changesets:
+ # r52 -> Link to revision 52
+ # commit:a85130f -> Link to scmid starting with a85130f
+ # Documents:
+ # document#17 -> Link to document with id 17
+ # document:Greetings -> Link to the document with title "Greetings"
+ # document:"Some document" -> Link to the document with title "Some document"
+ # Versions:
+ # version#3 -> Link to version with id 3
+ # version:1.0.0 -> Link to version named "1.0.0"
+ # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
+ # Attachments:
+ # attachment:file.zip -> Link to the attachment of the current object named file.zip
+ # Source files:
+ # source:some/file -> Link to the file located at /some/file in the project's repository
+ # source:some/file@52 -> Link to the file's revision 52
+ # source:some/file#L120 -> Link to line 120 of the file
+ # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
+ # export:some/file -> Force the download of the file
+ # Forum messages:
+ # message#1218 -> Link to message with id 1218
+ def parse_redmine_links(text, project, obj, attr, only_path, options)
+ text.gsub!(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8
link = nil
if esc.nil?
@@ -602,8 +604,6 @@ module ApplicationHelper
end
leading + (link || "#{prefix}#{sep}#{identifier}")
end
-
- text
end
# Same as Rails' simple_format helper without using paragraphs