Commit 2ec8a947
Changed files (5)
app/models/large_version.rb
@@ -0,0 +1,9 @@
+ class LargeVersion < Version
+ def initialize(photo)
+ super(photo, :large, "large_")
+ end
+
+ def adjust(image)
+ image.resize_to_fit(570, 630)
+ end
+ end
app/models/original_version.rb
@@ -0,0 +1,7 @@
+ class OriginalVersion < Version
+ def initialize(photo)
+ super(photo, :original, "")
+ end
+
+ def adjust(image); end
+ end
app/models/photo.rb
@@ -33,62 +33,4 @@ class Photo < ActiveRecord::Base
def versions
@versions ||= [OriginalVersion.new(self), LargeVersion.new(self), ThumbnailVersion.new(self)]
end
-
- class Version
- attr_reader :key, :prefix, :photo
-
- def initialize(photo, key, prefix)
- @key = key
- @prefix = prefix
- @photo = photo
- end
-
- def adjust(image)
- fail "Please override with version specific behaviours"
- end
-
- def for?(other_key)
- key == other_key
- end
-
- def url_for(asset_host)
- if photo.is_processed?
- "#{asset_host}/#{create_key}"
- else
- ActionController::Base.helpers.asset_path("#{key}_default.png")
- end
- end
-
- def create_key
- "uploads/photo/image/#{photo.id}/#{prefix}#{photo.image}"
- end
- end
-
- class OriginalVersion < Version
- def initialize(photo)
- super(photo, :original, "")
- end
-
- def adjust(image); end
- end
-
- class LargeVersion < Version
- def initialize(photo)
- super(photo, :large, "large_")
- end
-
- def adjust(image)
- image.resize_to_fit(570, 630)
- end
- end
-
- class ThumbnailVersion < Version
- def initialize(photo)
- super(photo, :thumb, "thumb_")
- end
-
- def adjust(image)
- image.resize_to_fill(260, 180)
- end
- end
end
app/models/thumbnail_version.rb
@@ -0,0 +1,9 @@
+ class ThumbnailVersion < Version
+ def initialize(photo)
+ super(photo, :thumb, "thumb_")
+ end
+
+ def adjust(image)
+ image.resize_to_fill(260, 180)
+ end
+ end
app/models/version.rb
@@ -0,0 +1,29 @@
+ class Version
+ attr_reader :key, :prefix, :photo
+
+ def initialize(photo, key, prefix)
+ @key = key
+ @prefix = prefix
+ @photo = photo
+ end
+
+ def adjust(image)
+ fail "Please override with version specific behaviours"
+ end
+
+ def for?(other_key)
+ key == other_key
+ end
+
+ def url_for(asset_host)
+ if photo.is_processed?
+ "#{asset_host}/#{create_key}"
+ else
+ ActionController::Base.helpers.asset_path("#{key}_default.png")
+ end
+ end
+
+ def create_key
+ "uploads/photo/image/#{photo.id}/#{prefix}#{photo.image}"
+ end
+ end