Commit 0fabebff by jyurek

Formatting and refactoring transformation_to a bit

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@405 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 632f5ffb
...@@ -79,22 +79,31 @@ module Paperclip ...@@ -79,22 +79,31 @@ module Paperclip
ratio = Geometry.new( dst.width / self.width, dst.height / self.height ) ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
if crop if crop
scale_geometry, scale = if ratio.horizontal? || ratio.square? scale_geometry, scale = scaling(dst, ratio)
[ "%dx" % dst.width, ratio.width ] crop_geometry = cropping(dst, ratio, scale)
else
[ "x%d" % dst.height, ratio.height ]
end
crop_geometry = if ratio.horizontal? || ratio.square?
"%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
else
"%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
end
else else
scale_geometry = dst.to_s scale_geometry = dst.to_s
end end
[ scale_geometry, crop_geometry ] [ scale_geometry, crop_geometry ]
end end
private
def scaling dst, ratio
if ratio.horizontal? || ratio.square?
[ "%dx" % dst.width, ratio.width ]
else
[ "x%d" % dst.height, ratio.height ]
end
end
def cropping dst, ratio, scale
if ratio.horizontal? || ratio.square?
"%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
else
"%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
end
end
end end
end end
...@@ -10,14 +10,14 @@ module Paperclip ...@@ -10,14 +10,14 @@ module Paperclip
# unless specified. Thumbnail creation will raise no errors unless # unless specified. Thumbnail creation will raise no errors unless
# +whiny_thumbnails+ is true (which it is, by default. # +whiny_thumbnails+ is true (which it is, by default.
def initialize file, target_geometry, format = nil, whiny_thumbnails = true def initialize file, target_geometry, format = nil, whiny_thumbnails = true
@file = file @file = file
@crop = target_geometry[-1,1] == '#' @crop = target_geometry[-1,1] == '#'
@target_geometry = Geometry.parse target_geometry @target_geometry = Geometry.parse target_geometry
@current_geometry = Geometry.from_file file @current_geometry = Geometry.from_file file
@whiny_thumbnails = whiny_thumbnails @whiny_thumbnails = whiny_thumbnails
@current_format = File.extname(@file.path) @current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format) @basename = File.basename(@file.path, @current_format)
@format = format @format = format
end end
......
...@@ -15,14 +15,6 @@ $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip') ...@@ -15,14 +15,6 @@ $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
require File.join(ROOT, 'lib', 'paperclip.rb') require File.join(ROOT, 'lib', 'paperclip.rb')
class String
unless methods.include? :pluralize
def pluralize
"#{self}s"
end
end
end
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
......
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