@@ -414,13 +414,11 module ApplicationHelper | |||
|
414 | 414 | only_path = options.delete(:only_path) == false ? false : true |
|
415 | 415 | |
|
416 | 416 | # when using an image link, try to use an attachment, if possible |
|
417 |
|
|
|
418 | ||
|
419 | if attachments | |
|
420 | attachments = attachments.sort_by(&:created_on).reverse | |
|
417 | if options[:attachments] || (obj && obj.respond_to?(:attachments)) | |
|
418 | attachments = nil | |
|
421 | 419 | text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| |
|
422 | 420 | filename, ext, alt, alttext = $1.downcase, $2, $3, $4 |
|
423 | ||
|
421 | attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse | |
|
424 | 422 | # search for the picture in attachments |
|
425 | 423 | if found = attachments.detect { |att| att.filename.downcase == filename } |
|
426 | 424 | image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found |
@@ -592,6 +590,7 module ApplicationHelper | |||
|
592 | 590 | :class => (prefix == 'export' ? 'source download' : 'source') |
|
593 | 591 | end |
|
594 | 592 | when 'attachment' |
|
593 | attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) | |
|
595 | 594 | if attachments && attachment = attachments.detect {|a| a.filename == name } |
|
596 | 595 | link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, |
|
597 | 596 | :class => 'attachment' |
@@ -211,6 +211,14 RAW | |||
|
211 | 211 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } |
|
212 | 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 | 222 | def test_wiki_links |
|
215 | 223 | to_test = { |
|
216 | 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