Created
March 8, 2011 15:39
-
-
Save charly/860420 to your computer and use it in GitHub Desktop.
a nice little module to help migrate from attachment_fu to carrierwave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Helps you migrate from attachment_fu | |
# put it in your /lib dir and include it your xxxx_uploader.rb | |
module UploaderFu | |
def partition_dir | |
("%08d" % model.id).scan(/\d{4}/).join("/") | |
end | |
def model_dir | |
"#{model.class.to_s.underscore}/#{mounted_as}/" | |
end | |
def root_dir | |
version_name ? "public/images" : "uploads" | |
end | |
# store dir is composed of root_dir, model_dir, partition_dir | |
# override/change any of those to fit your needs | |
def store_dir | |
File.join Rails.root, root_dir, model_dir, partition_dir | |
end | |
### For AttachmentFu Legacy : | |
# version :thumb do | |
# process :resize_to_fill => [80, 80] | |
# | |
# def full_filename(for_file) | |
# full_filename_fu( super ) | |
# end | |
# | |
# end | |
def full_filename_fu( filename ) | |
version_prefix = "#{version_name}_" | |
filename = filename.gsub(version_prefix, "") | |
ext = nil | |
basename = filename.gsub /\.\w+$/ do |s| | |
ext = s; '' | |
end | |
"#{basename}_#{version_name}#{ext}" | |
end | |
def extension_white_list | |
%w(jpg jpeg gif png) | |
end | |
def default_url | |
File.join "/images", model_dir, default_url_filename | |
end | |
def default_url_filename | |
[version_name, "default.jpg"].compact.join('_') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment