Commit ee70992b by Jon Yurek

Thumbnail takes a hash of options instead of a list of args now

parent 9dc9f71f
......@@ -2,32 +2,32 @@ module Paperclip
# Handles thumbnailing images that are uploaded.
class Thumbnail
attr_accessor :file, :current_geometry, :target_geometry, :format, :whiny_thumbnails, :convert_options
attr_accessor :file, :current_geometry, :target_geometry, :format, :whiny, :convert_options
# Creates a Thumbnail object set to work on the +file+ given. It
# will attempt to transform the image into one defined by +target_geometry+
# which is a "WxH"-style string. +format+ will be inferred from the +file+
# unless specified. Thumbnail creation will raise no errors unless
# +whiny_thumbnails+ is true (which it is, by default. If +convert_options+ is
# +whiny+ is true (which it is, by default. If +convert_options+ is
# set, the options will be appended to the convert command upon image conversion
def initialize file, target_geometry, format = nil, convert_options = nil, whiny_thumbnails = true
def initialize file, options = {}
geometry = options[:geometry]
@file = file
@crop = target_geometry[-1,1] == '#'
@target_geometry = Geometry.parse target_geometry
@current_geometry = Geometry.from_file file
@convert_options = convert_options
@whiny_thumbnails = whiny_thumbnails
@crop = geometry[-1,1] == '#'
@target_geometry = Geometry.parse geometry
@current_geometry = Geometry.from_file @file
@convert_options = options[:convert_options]
@whiny = options[:whiny].nil? ? true : options[:whiny]
@format = options[:format]
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
@format = format
end
# Creates a thumbnail, as specified in +initialize+, +make+s it, and returns the
# resulting Tempfile.
def self.make file, dimensions, format = nil, convert_options = nil, whiny_thumbnails = true
new(file, dimensions, format, convert_options, whiny_thumbnails).make
def self.make file, options = {}
new(file, options).make
end
# Returns true if the +target_geometry+ is meant to crop.
......@@ -56,7 +56,7 @@ module Paperclip
begin
success = Paperclip.run("convert", command.gsub(/\s+/, " "))
rescue PaperclipCommandLineError
raise PaperclipError, "There was an error processing the thumbnail for #{@basename}" if @whiny_thumbnails
raise PaperclipError, "There was an error processing the thumbnail for #{@basename}" if @whiny
end
dst
......
......@@ -41,7 +41,7 @@ class ThumbnailTest < Test::Unit::TestCase
].each do |args|
context "being thumbnailed with a geometry of #{args[0]}" do
setup do
@thumb = Paperclip::Thumbnail.new(@file, args[0])
@thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
end
should "start with dimensions of 434x66" do
......@@ -68,7 +68,7 @@ class ThumbnailTest < Test::Unit::TestCase
context "being thumbnailed at 100x50 with cropping" do
setup do
@thumb = Paperclip::Thumbnail.new(@file, "100x50#")
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
end
should "report its correct current and target geometries" do
......@@ -80,8 +80,8 @@ class ThumbnailTest < Test::Unit::TestCase
assert_nil @thumb.format
end
should "have whiny_thumbnails turned on by default" do
assert @thumb.whiny_thumbnails
should "have whiny turned on by default" do
assert @thumb.whiny
end
should "have convert_options set to nil by default" do
......@@ -103,7 +103,9 @@ class ThumbnailTest < Test::Unit::TestCase
context "being thumbnailed with convert options set" do
setup do
@thumb = Paperclip::Thumbnail.new(@file, "100x50#", format=nil, convert_options="-strip -depth 8", whiny_thumbnails=true)
@thumb = Paperclip::Thumbnail.new(@file,
:geometry => "100x50#",
:convert_options => "-strip -depth 8")
end
should "have convert_options value set" do
......@@ -124,7 +126,9 @@ class ThumbnailTest < Test::Unit::TestCase
context "redefined to have bad convert_options setting" do
setup do
@thumb = Paperclip::Thumbnail.new(@file, "100x50#", format=nil, convert_options="-this-aint-no-option", whiny_thumbnails=true)
@thumb = Paperclip::Thumbnail.new(@file,
:geometry => "100x50#",
:convert_options => "-this-aint-no-option")
end
should "error when trying to create the thumbnail" do
......
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