Commit 5f2b2cd5 by jyurek

Added per-attachment whiny_thumbnail settings.

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@302 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 53f9558a
...@@ -44,6 +44,7 @@ module Paperclip ...@@ -44,6 +44,7 @@ module Paperclip
end end
def []=(style, data) #:nodoc: def []=(style, data) #:nodoc:
@dirty = true
@files[style] = data @files[style] = data
end end
...@@ -150,10 +151,10 @@ module Paperclip ...@@ -150,10 +151,10 @@ module Paperclip
# Generates the thumbnails from the data supplied. Following this call, the data will # Generates the thumbnails from the data supplied. Following this call, the data will
# be available from for_attached_files. # be available from for_attached_files.
def convert data def convert(uploaded_file)
begin begin
definition.styles.each do |style, geometry| definition.styles.each do |style, geometry|
self[style] = Thumbnail.make(geometry, data) self[style] = Thumbnail.make(geometry, data, definition.whiny_thumbnails)
end end
rescue PaperclipError => e rescue PaperclipError => e
errors << e.message errors << e.message
......
...@@ -49,12 +49,14 @@ module Paperclip ...@@ -49,12 +49,14 @@ module Paperclip
attr_accessor :geometry, :data attr_accessor :geometry, :data
def initialize geometry, data def initialize geometry, data, whiny_thumbnails = nil
@geometry, @data = geometry, data @geometry, @data = geometry, data
@whiny_thumbnails = Paperclip.options[:whiny_thumbnails]
@whiny_thumbnails = whiny_thumbnails unless whiny_thumbnails.nil?
end end
def self.make geometry, data def self.make geometry, data, whiny_thumbnails = nil
new(geometry, data).make new(geometry, data, whiny_thumbnails).make
end end
def make def make
...@@ -70,8 +72,10 @@ module Paperclip ...@@ -70,8 +72,10 @@ module Paperclip
raise PaperclipError, "could not be thumbnailed. Is ImageMagick or GraphicsMagick installed and available?" raise PaperclipError, "could not be thumbnailed. Is ImageMagick or GraphicsMagick installed and available?"
rescue SystemCallError => e rescue SystemCallError => e
raise PaperclipError, "could not be thumbnailed." raise PaperclipError, "could not be thumbnailed."
rescue PaperclipError
raise if @whiny_thumbnails
end end
if Paperclip.options[:whiny_thumbnails] && !$?.success? if @whiny_thumbnails && !$?.success?
raise PaperclipError, "could not be thumbnailed because of an error with 'convert'." raise PaperclipError, "could not be thumbnailed because of an error with 'convert'."
end end
thumb thumb
......
...@@ -9,7 +9,7 @@ module Paperclip ...@@ -9,7 +9,7 @@ module Paperclip
type = self.path.match(/\.(\w+)$/)[1] || "data" type = self.path.match(/\.(\w+)$/)[1] || "data"
case type case type
when "jpg", "png", "gif" then "image/#{type}" when "jpg", "png", "gif" then "image/#{type}"
when "txt", "csv", "xml", "html", "htm" then "text/#{type}" when "txt", "csv", "xml", "html", "htm", "css", "js" then "text/#{type}"
else "x-application/#{type}" else "x-application/#{type}"
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment