Module | ActiveRecord::Acts::UploaderUpload::InstanceMethods |
In: |
lib/active_record/acts/uploader_upload.rb
|
All the methods available to a record that has had acts_as_uploader specified.
# File lib/active_record/acts/uploader_upload.rb, line 192 192: def calculate_sizes(style) 193: if image_ratio > 1 194: @image_width ||= width > max_dimension(style) ? max_dimension(style) : width 195: @image_height ||= (@image_width / image_ratio).round 196: else 197: @image_height ||= height > max_dimension(style) ? max_dimension(style) : height 198: @image_width ||= (@image_height * image_ratio).round 199: end 200: @image_size ||= "#{@image_width.to_i}x#{@image_height.to_i}" 201: end
# File lib/active_record/acts/uploader_upload.rb, line 156 156: def can_edit?(check_user) 157: return false if check_user.blank? 158: check_user == self.creator 159: end
# File lib/active_record/acts/uploader_upload.rb, line 152 152: def display_name 153: CGI::escapeHTML(self.local_file_name) 154: end
# File lib/active_record/acts/uploader_upload.rb, line 67 67: def file 68: local_file_name ? local : remote 69: end
# File lib/active_record/acts/uploader_upload.rb, line 71 71: def file_name 72: remote_file_name || local_file_name 73: end
# File lib/active_record/acts/uploader_upload.rb, line 170 170: def height(style = :default) 171: return nil unless self[:height] 172: return self[:height] if style == :default 173: calculate_sizes(style.to_sym) 174: return @image_height.to_i 175: end
# File lib/active_record/acts/uploader_upload.rb, line 134 134: def icon 135: if self.is_pdf? 136: '/images/file_icons/file_pdf.gif' 137: elsif self.is_word? 138: '/images/file_icons/file_doc.gif' 139: elsif self.is_image? 140: self.file.url(:icon) 141: elsif self.is_mp3? 142: '/images/file_icons/file_mp3.gif' 143: elsif self.is_excel? 144: '/images/file_icons/file_xls.gif' 145: elsif self.is_text? 146: '/images/file_icons/file_txt.gif' 147: else 148: '/images/file_icons/file_raw.gif' 149: end 150: end
# File lib/active_record/acts/uploader_upload.rb, line 188 188: def image_ratio 189: @image_ratio ||= width.to_f / height.to_f 190: end
# File lib/active_record/acts/uploader_upload.rb, line 100 100: def is_excel? 101: Uploader::MimeTypeGroups::EXCEL_TYPES.include?(self.local_content_type) 102: end
# File lib/active_record/acts/uploader_upload.rb, line 92 92: def is_image? 93: Uploader::MimeTypeGroups::IMAGE_TYPES.include?(self.local_content_type) 94: end
# File lib/active_record/acts/uploader_upload.rb, line 96 96: def is_mp3? 97: Uploader::MimeTypeGroups::MP3_TYPES.include?(self.local_content_type) 98: end
# File lib/active_record/acts/uploader_upload.rb, line 104 104: def is_pdf? 105: Uploader::MimeTypeGroups::PDF_TYPES.include?(self.local_content_type) 106: end
# File lib/active_record/acts/uploader_upload.rb, line 112 112: def is_text? 113: Uploader::MimeTypeGroups::TEXT_TYPES.include?(self.local_content_type) 114: end
# File lib/active_record/acts/uploader_upload.rb, line 108 108: def is_word? 109: Uploader::MimeTypeGroups::WORD_TYPES.include?(self.local_content_type) 110: end
# File lib/active_record/acts/uploader_upload.rb, line 184 184: def max_dimension(style) 185: @max_dimension ||= Paperclip::Geometry.parse(self.local.styles[style][:geometry]).width.to_f 186: end
# File lib/active_record/acts/uploader_upload.rb, line 75 75: def send_to_remote 76: if local_file_name 77: self.remote = local.to_file 78: if self.save and remote.original_filename and remote.exists? 79: self.local = nil 80: self.save 81: else 82: false 83: end 84: end 85: end
# File lib/active_record/acts/uploader_upload.rb, line 177 177: def size(style = :default) 178: return nil unless width || height 179: return "#{width}x#{height}" if style == :default 180: calculate_sizes(style.to_sym) 181: return @image_size 182: end
# File lib/active_record/acts/uploader_upload.rb, line 87 87: def swfupload_local=(filedata) 88: filedata.content_type = MIME::Types.type_for(filedata.original_filename)[0].to_s 89: self.local = filedata 90: end
# File lib/active_record/acts/uploader_upload.rb, line 116 116: def upload_type 117: if self.is_pdf? 118: 'Adobe pdf file' 119: elsif self.is_word? 120: 'Word document' 121: elsif self.is_image? 122: 'photo' 123: elsif self.is_mp3? 124: 'mp3' 125: elsif self.is_excel? 126: 'Excel document' 127: elsif self.is_text? 128: 'text file' 129: else 130: 'file' 131: end 132: end
Image dimension calculations
# File lib/active_record/acts/uploader_upload.rb, line 163 163: def width(style = :default) 164: return nil unless self[:width] 165: return self[:width] if style == :default 166: calculate_sizes(style.to_sym) 167: return @image_width.to_i 168: end
# File lib/active_record/acts/uploader_upload.rb, line 223 223: def add_width_and_height 224: return unless self.is_image? 225: if self.local.to_file 226: geometry = Paperclip::Geometry.from_file self.local.to_file 227: self[:width] = geometry.width.to_i 228: self[:height] = geometry.height.to_i 229: end 230: end
# File lib/active_record/acts/uploader_upload.rb, line 210 210: def transliterate(str) 211: # Lifted from permalink_fu by Rick Olsen 212: # Escape str by transliterating to UTF-8 with Iconv, 213: # downcasing, then removing illegal characters and replacing them with ’-’ 214: s = Iconv.iconv('ascii//ignore//translit', 'utf-8', str).to_s 215: s.downcase! 216: s.gsub!(/\'/, '') 217: s.gsub!(/[^A-Za-z0-9]+/, ' ') 218: s.strip! 219: s.gsub!(/\ +/, '-') # set single or multiple spaces to a single dash 220: return s 221: end
# File lib/active_record/acts/uploader_upload.rb, line 204 204: def transliterate_file_name 205: extension = File.extname(local_file_name).gsub(/^\.+/, '') 206: filename = local_file_name.gsub(/\.#{extension}$/, '') 207: self.local.instance_write(:file_name, "#{transliterate(filename)}.#{transliterate(extension)}") 208: end