Optimization: load attachments when needed.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3581 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
c3e8d1d512
commit
2f5c17a0f6
|
@ -414,13 +414,11 @@ module ApplicationHelper
|
||||||
only_path = options.delete(:only_path) == false ? false : true
|
only_path = options.delete(:only_path) == false ? false : true
|
||||||
|
|
||||||
# when using an image link, try to use an attachment, if possible
|
# when using an image link, try to use an attachment, if possible
|
||||||
attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
|
if options[:attachments] || (obj && obj.respond_to?(:attachments))
|
||||||
|
attachments = nil
|
||||||
if attachments
|
|
||||||
attachments = attachments.sort_by(&:created_on).reverse
|
|
||||||
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
|
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
|
||||||
filename, ext, alt, alttext = $1.downcase, $2, $3, $4
|
filename, ext, alt, alttext = $1.downcase, $2, $3, $4
|
||||||
|
attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
|
||||||
# search for the picture in attachments
|
# search for the picture in attachments
|
||||||
if found = attachments.detect { |att| att.filename.downcase == filename }
|
if found = attachments.detect { |att| att.filename.downcase == filename }
|
||||||
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
|
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
|
||||||
|
@ -592,6 +590,7 @@ module ApplicationHelper
|
||||||
:class => (prefix == 'export' ? 'source download' : 'source')
|
:class => (prefix == 'export' ? 'source download' : 'source')
|
||||||
end
|
end
|
||||||
when 'attachment'
|
when 'attachment'
|
||||||
|
attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
|
||||||
if attachments && attachment = attachments.detect {|a| a.filename == name }
|
if attachments && attachment = attachments.detect {|a| a.filename == name }
|
||||||
link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
|
link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
|
||||||
:class => 'attachment'
|
:class => 'attachment'
|
||||||
|
|
|
@ -211,6 +211,14 @@ RAW
|
||||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
|
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_attachment_links
|
||||||
|
attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment')
|
||||||
|
to_test = {
|
||||||
|
'attachment:error281.txt' => attachment_link
|
||||||
|
}
|
||||||
|
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
|
||||||
|
end
|
||||||
|
|
||||||
def test_wiki_links
|
def test_wiki_links
|
||||||
to_test = {
|
to_test = {
|
||||||
'[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
|
'[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
|
||||||
|
|
Loading…
Reference in New Issue