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)
crop_geometry = cropping(dst, ratio, scale)
else
scale_geometry = dst.to_s
end
[ scale_geometry, crop_geometry ]
end
private
def scaling dst, ratio
if ratio.horizontal? || ratio.square?
[ "%dx" % dst.width, ratio.width ] [ "%dx" % dst.width, ratio.width ]
else else
[ "x%d" % dst.height, ratio.height ] [ "x%d" % dst.height, ratio.height ]
end end
end
crop_geometry = if ratio.horizontal? || ratio.square? 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 ] "%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
else else
"%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ] "%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
end end
else
scale_geometry = dst.to_s
end
[ scale_geometry, crop_geometry ]
end end
end end
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