Class: ImageUploader

Inherits:
FileUploader show all
Includes:
CarrierWave::MiniMagick
Defined in:
mod/05_standard/lib/image_uploader.rb

Instance Attribute Summary

Attributes inherited from FileUploader

#mod

Instance Method Summary collapse

Methods inherited from FileUploader

#action_id, #cache_dir, #create_versions?, #db_content, #extension, #file_dir, #filename, #mod_file?, #original_filename, #retrieve_dir, #retrieve_path, #store_dir, #store_path, #tmp_path, #url, #url_filename

Methods included from Card::Location

#card_path, #card_url, #page_path

Instance Method Details

#full_filename(for_file) ⇒ Object

add ‘original’ if no version is given



43
44
45
46
47
48
49
50
51
# File 'mod/05_standard/lib/image_uploader.rb', line 43

def full_filename for_file
  name = super(for_file)
  if version_name
    name
  else
    parts = name.split '.'
    "#{parts.shift}-original.#{parts.join('.')}"
  end
end

#identifierObject

version :small_square, if: :create_versions?,

                     from_version: :medium_square do
process resize_to_fill: [75, 75]

end version :medium_square, if: :create_versions? do

process resize_to_fill: [200, 200]

end

In case we decide to support the squared versions we have to update all existing images with the following snippet: Card.search(type_id: Card::ImageID) do |card|

card.image.cache_stored_file!
card.image.recreate_versions!

end



38
39
40
# File 'mod/05_standard/lib/image_uploader.rb', line 38

def identifier
  full_filename(super())
end

#path(version = nil) ⇒ Object



6
7
8
# File 'mod/05_standard/lib/image_uploader.rb', line 6

def path version=nil
  (version && version != :original) ? versions[version].path : super()
end