Commit eebc7d98 by Mike Burns

Also abstract out the string geometry parser from Thumbnail, to reduce coupling.

parent 3f7aee30
......@@ -18,19 +18,20 @@ module Paperclip
# Options include:
#
# +geometry+ - the desired width and height of the thumbnail
# +file_geometry_parser+ - an object with a method named +from_file+ that takes an image file and produces its geometry. Defaults to Paperclip::Geometry
# +file_geometry_parser+ - an object with a method named +from_file+ that takes an image file and produces its geometry and a +transformation_to+. Defaults to Paperclip::Geometry
# +string_geometry_parser+ - an object with a method named +parse+ that takes a string and produces an object with +width+, +height+, and +to_s+ accessors. Defaults to Paperclip::Geometry
# +source_file_options+ - flags passed to the +convert+ command that influence how the source file is read
# +convert_options+ - flags passed to the +convert+ command that influence how the image is processed
# +whiny+ - whether to raise an error when processing fails. Defaults to true.
# +whiny+ - whether to raise an error when processing fails. Defaults to true
# +format+ - the desired filename extension
# +animated+ - whether to merge all the layers in the image. Defaults to true.
# +animated+ - whether to merge all the layers in the image. Defaults to true
def initialize(file, options = {}, attachment = nil)
super
geometry = options[:geometry]
geometry = options[:geometry] # this is not an option
@file = file
@crop = geometry[-1,1] == '#'
@target_geometry = Geometry.parse(geometry)
@target_geometry = (options[:string_geometry_parser] || Geometry).parse(geometry)
@current_geometry = (options[:file_geometry_parser] || Geometry).from_file(@file)
@source_file_options = options[:source_file_options]
@convert_options = options[:convert_options]
......
......@@ -225,7 +225,7 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
context "passing a custom geometry parser" do
context "passing a custom file geometry parser" do
should "produce the appropriate transformation_command" do
GeoParser = Class.new do
def self.from_file(file)
......@@ -236,7 +236,7 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :file_geometry_parser => GeoParser)
thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :file_geometry_parser => GeoParser)
transformation_command = thumb.transformation_command
......@@ -250,6 +250,27 @@ class ThumbnailTest < Test::Unit::TestCase
%{expected #{transformation_command.inspect} to include '"SCALE"'}
end
end
context "passing a custom geometry string parser" do
should "produce the appropriate transformation_command" do
GeoParser = Class.new do
def self.parse(s)
new
end
def to_s
"151x167"
end
end
thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :string_geometry_parser => GeoParser)
transformation_command = thumb.transformation_command
assert transformation_command.include?('"151x167"'),
%{expected #{transformation_command.inspect} to include '151x167'}
end
end
end
context "A multipage PDF" 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