Class: Kindeditor::AssetUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- Kindeditor::AssetUploader
- Defined in:
- app/uploaders/kindeditor/asset_uploader.rb
Overview
require ‘carrierwave/processing/mime_types’
Direct Known Subclasses
Constant Summary collapse
- EXT_NAMES =
{:image => RailsKindeditor.upload_image_ext, :flash => RailsKindeditor.upload_flash_ext, :media => RailsKindeditor.upload_media_ext, :file => RailsKindeditor.upload_file_ext}
Instance Attribute Summary collapse
-
#digest_filename ⇒ Object
use this to set the digest filename for a special upload.
-
#fixed_folder ⇒ Object
Returns the value of attribute fixed_folder.
-
#private_path ⇒ Object
for user private resource path.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #delete_tmp_dir(new_file) ⇒ Object
-
#filename ⇒ Object
if the folder is fixed and !digest_filename is true ,we use the opiginal_filename if set use_original_filename ,we use the opiginal_filename.
-
#remember_cache_id(new_file) ⇒ Object
store! nil’s the cache_id after it finishes so we need to remember it for deletition.
-
#store_dir ⇒ Object
Override the directory where uploaded files will be stored.
Instance Attribute Details
#digest_filename ⇒ Object
use this to set the digest filename for a special upload
25 26 27 |
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 25 def digest_filename @digest_filename end |
#fixed_folder ⇒ Object
Returns the value of attribute fixed_folder.
23 24 25 |
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 23 def fixed_folder @fixed_folder end |
#private_path ⇒ Object
for user private resource path
22 23 24 |
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 22 def private_path @private_path end |
Class Method Details
.save_upload_info? ⇒ Boolean
90 91 92 93 94 95 96 97 98 99 |
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 90 def self.save_upload_info? begin %w(asset file flash image media).each do |s| "Kindeditor::#{s.camelize}".constantize end return true rescue return false end end |
Instance Method Details
#cache_dir ⇒ Object
38 39 40 |
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 38 def cache_dir "#{Rails.root}/tmp/uploads" end |
#delete_tmp_dir(new_file) ⇒ Object
72 73 74 75 76 77 |
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 72 def delete_tmp_dir(new_file) # make sure we don't delete other things accidentally by checking the name pattern if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/ FileUtils.rm_rf(File.join(cache_dir, @cache_id_was)) end end |
#filename ⇒ Object
if the folder is fixed and !digest_filename is true ,we use the opiginal_filename if set use_original_filename ,we use the opiginal_filename
81 82 83 84 85 86 87 88 |
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 81 def filename if RailsKindeditor.use_original_filename || (fixed_folder && !digest_filename) super elsif original_filename @name ||= Digest::MD5.hexdigest(File.dirname(current_path)).slice(0, 12) "#{@name}.#{file.extension}" end end |
#remember_cache_id(new_file) ⇒ Object
store! nil’s the cache_id after it finishes so we need to remember it for deletition
68 69 70 |
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 68 def remember_cache_id(new_file) @cache_id_was = cache_id end |
#store_dir ⇒ Object
Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:
30 31 32 33 34 35 |
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 30 def store_dir @store_dir ||= [RailsKindeditor.upload_store_dir]. push(private_path). push(calcuate_object_folder). flatten.compact.join("/").gsub(/(kindeditor\/)|(_uploader)/, '') end |