Skip to content
Browse files

Added per-attachment whiny_thumbnail settings.

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@302 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
1 parent 53f9558 commit 5f2b2cd59ee60ba2910a595ef334bb49af1f67f8 jyurek committed
Showing with 12 additions and 7 deletions.
  1. +3 −2 lib/paperclip/attachment.rb
  2. +8 −4 lib/paperclip/thumbnail.rb
  3. +1 −1 lib/paperclip/upfile.rb
View
5 lib/paperclip/attachment.rb
@@ -44,6 +44,7 @@ def [](style) #:nodoc:
end
def []=(style, data) #:nodoc:
+ @dirty = true
@files[style] = data
end
@@ -150,10 +151,10 @@ def exists?(style)
# Generates the thumbnails from the data supplied. Following this call, the data will
# be available from for_attached_files.
- def convert data
+ def convert(uploaded_file)
begin
definition.styles.each do |style, geometry|
- self[style] = Thumbnail.make(geometry, data)
+ self[style] = Thumbnail.make(geometry, data, definition.whiny_thumbnails)
end
rescue PaperclipError => e
errors << e.message
View
12 lib/paperclip/thumbnail.rb
@@ -49,12 +49,14 @@ def inspect
attr_accessor :geometry, :data
- def initialize geometry, data
+ def initialize geometry, data, whiny_thumbnails = nil
@geometry, @data = geometry, data
+ @whiny_thumbnails = Paperclip.options[:whiny_thumbnails]
+ @whiny_thumbnails = whiny_thumbnails unless whiny_thumbnails.nil?
end
- def self.make geometry, data
- new(geometry, data).make
+ def self.make geometry, data, whiny_thumbnails = nil
+ new(geometry, data, whiny_thumbnails).make
end
def make
@@ -70,8 +72,10 @@ def make
raise PaperclipError, "could not be thumbnailed. Is ImageMagick or GraphicsMagick installed and available?"
rescue SystemCallError => e
raise PaperclipError, "could not be thumbnailed."
+ rescue PaperclipError
+ raise if @whiny_thumbnails
end
- if Paperclip.options[:whiny_thumbnails] && !$?.success?
+ if @whiny_thumbnails && !$?.success?
raise PaperclipError, "could not be thumbnailed because of an error with 'convert'."
end
thumb
View
2 lib/paperclip/upfile.rb
@@ -9,7 +9,7 @@ def content_type
type = self.path.match(/\.(\w+)$/)[1] || "data"
case 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}"
end
end

0 comments on commit 5f2b2cd

Please sign in to comment.
Something went wrong with that request. Please try again.