@@ -414,13 +414,11 module ApplicationHelper | |||||
414 | only_path = options.delete(:only_path) == false ? false : true |
|
414 | only_path = options.delete(:only_path) == false ? false : true | |
415 |
|
415 | |||
416 | # when using an image link, try to use an attachment, if possible |
|
416 | # when using an image link, try to use an attachment, if possible | |
417 |
|
|
417 | if options[:attachments] || (obj && obj.respond_to?(:attachments)) | |
418 |
|
418 | attachments = nil | ||
419 | if attachments |
|
|||
420 | attachments = attachments.sort_by(&:created_on).reverse |
|
|||
421 | text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| |
|
419 | text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| | |
422 | filename, ext, alt, alttext = $1.downcase, $2, $3, $4 |
|
420 | filename, ext, alt, alttext = $1.downcase, $2, $3, $4 | |
423 |
|
421 | attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse | ||
424 | # search for the picture in attachments |
|
422 | # search for the picture in attachments | |
425 | if found = attachments.detect { |att| att.filename.downcase == filename } |
|
423 | if found = attachments.detect { |att| att.filename.downcase == filename } | |
426 | image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found |
|
424 | image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found | |
@@ -592,6 +590,7 module ApplicationHelper | |||||
592 | :class => (prefix == 'export' ? 'source download' : 'source') |
|
590 | :class => (prefix == 'export' ? 'source download' : 'source') | |
593 | end |
|
591 | end | |
594 | when 'attachment' |
|
592 | when 'attachment' | |
|
593 | attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) | |||
595 | if attachments && attachment = attachments.detect {|a| a.filename == name } |
|
594 | if attachments && attachment = attachments.detect {|a| a.filename == name } | |
596 | link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, |
|
595 | link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, | |
597 | :class => 'attachment' |
|
596 | :class => 'attachment' |
@@ -211,6 +211,14 RAW | |||||
211 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } |
|
211 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } | |
212 | end |
|
212 | end | |
213 |
|
213 | |||
|
214 | def test_attachment_links | |||
|
215 | attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment') | |||
|
216 | to_test = { | |||
|
217 | 'attachment:error281.txt' => attachment_link | |||
|
218 | } | |||
|
219 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" } | |||
|
220 | end | |||
|
221 | ||||
214 | def test_wiki_links |
|
222 | def test_wiki_links | |
215 | to_test = { |
|
223 | to_test = { | |
216 | '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', |
|
224 | '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', |
General Comments 0
You need to be logged in to leave comments.
Login now