filename, ext, alt, alttext = $1.downcase, $2, $3, $4
# search for the picture in attachments
if found = Attachment.latest_attach(attachments, filename)
- image_url = url_for :only_path => only_path, :controller => 'attachments',
- :action => 'download', :id => found
+ image_url = download_named_attachment_path(found, found.filename, :only_path => only_path)
desc = found.description.to_s.gsub('"', '')
if !desc.blank? && alttext.blank?
alt = " title=\"#{desc}\" alt=\"#{desc}\""
def test_attached_images
to_test = {
- 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
- 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
+ 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
+ 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
# link image
- '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3" title="This is a logo" alt="This is a logo" /></a>',
+ '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" /></a>',
}
attachments = Attachment.all
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
to_test = {
'Inline image: !testtest.jpg!' =>
- 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '" alt="" />',
+ 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '/testtest.JPG" alt="" />',
'Inline image: !testtest.jpeg!' =>
- 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
+ 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testtest.jpeg" alt="" />',
'Inline image: !testtest.jpe!' =>
- 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '" alt="" />',
+ 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '/testtest.JPE" alt="" />',
'Inline image: !testtest.bmp!' =>
- 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '" alt="" />',
+ 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '/Testtest.BMP" alt="" />',
}
attachments = [a1, a2, a3, a4]
to_test = {
'Inline image: !testfile.png!' =>
- 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
+ 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
'Inline image: !Testfile.PNG!' =>
- 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
+ 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
}
attachments = [a1, a2]
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }