@@ -357,16 +357,15 module ApplicationHelper | |||||
357 | attachments = attachments.sort_by(&:created_on).reverse |
|
357 | attachments = attachments.sort_by(&:created_on).reverse | |
358 | text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(bmp|gif|jpg|jpeg|png))!/i) do |m| |
|
358 | text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(bmp|gif|jpg|jpeg|png))!/i) do |m| | |
359 | style = $1 |
|
359 | style = $1 | |
360 | filename = $6 |
|
360 | filename = $6.downcase | |
361 | rf = Regexp.new(Regexp.escape(filename), Regexp::IGNORECASE) |
|
|||
362 | # search for the picture in attachments |
|
361 | # search for the picture in attachments | |
363 |
if found = attachments.detect { |att| att.filename = |
|
362 | if found = attachments.detect { |att| att.filename.downcase == filename } | |
364 | image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found |
|
363 | image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found | |
365 | desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1") |
|
364 | desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1") | |
366 | alt = desc.blank? ? nil : "(#{desc})" |
|
365 | alt = desc.blank? ? nil : "(#{desc})" | |
367 | "!#{style}#{image_url}#{alt}!" |
|
366 | "!#{style}#{image_url}#{alt}!" | |
368 | else |
|
367 | else | |
369 | "!#{style}#{filename}!" |
|
368 | m | |
370 | end |
|
369 | end | |
371 | end |
|
370 | end | |
372 | end |
|
371 | end |
@@ -89,7 +89,9 class ApplicationHelperTest < HelperTestCase | |||||
89 | def test_attached_images |
|
89 | def test_attached_images | |
90 | to_test = { |
|
90 | to_test = { | |
91 | 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', |
|
91 | 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', | |
92 | 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />' |
|
92 | 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', | |
|
93 | 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />', | |||
|
94 | 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />' | |||
93 | } |
|
95 | } | |
94 | attachments = Attachment.find(:all) |
|
96 | attachments = Attachment.find(:all) | |
95 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } |
|
97 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } |
General Comments 0
You need to be logged in to leave comments.
Login now