Module: Gluttonberg::Library::AttachmentMixin::InstanceMethods
- Defined in:
- lib/gluttonberg/library/attachment_mixin.rb
Instance Method Summary collapse
- #asset_directory_public_url ⇒ Object
- #asset_folder_path ⇒ Object
- #asset_processing ⇒ Object
-
#file ⇒ Object
Returns the file assigned by file=.
-
#file=(new_file) ⇒ Object
Setter for the file object.
- #file_extension ⇒ Object
- #generate_cropped_image(x, y, w, h, image_type) ⇒ Object
-
#location_on_disk ⇒ Object
Returns the full path to the file’s location on disk.
-
#original_file_on_disk ⇒ Object
asset path in actual assets directory.
-
#tmp_location_on_disk ⇒ Object
Returns the full path to the file’s location on disk in tmp directory.
-
#tmp_original_file_on_disk ⇒ Object
asset full path in tmp directory.
-
#url ⇒ Object
Returns the public URL to this asset, relative to the domain.
Instance Method Details
#asset_directory_public_url ⇒ Object
96 97 98 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 96 def asset_directory_public_url "#{assets_directory_public_url}/#{asset_hash}" end |
#asset_folder_path ⇒ Object
91 92 93 94 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 91 def asset_folder_path # "/user_assets/#{asset_hash}" directory end |
#asset_processing ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 137 def asset_processing asset_id_to_process = self.id asset = Asset.find(:first , :conditions => { :id => asset_id_to_process } ) if asset asset_processors = [Library::Processor::Image , Library::Processor::Audio] #Core processors asset_processors << Rails.configuration.asset_processors unless Rails.configuration.asset_processors.blank? #additional processors asset_processors = asset_processors.flatten unless asset_processors.blank? asset_processors.each do |processor| processor.process(asset) end end end end |
#file ⇒ Object
Returns the file assigned by file=
83 84 85 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 83 def file @file end |
#file=(new_file) ⇒ Object
Setter for the file object. It sanatises the file name and stores in the filename property. It also sets the mime-type and size.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 60 def file=(new_file) unless new_file.blank? logger.info("\nFILENAME: #{new_file.original_filename} \n\n") # Forgive me this naive sanitisation, I'm still a regex n00b clean_filename = new_file.original_filename.split(%r{[\\|/]}).last clean_filename = clean_filename.gsub(" ", "_").gsub(/[^A-Za-z0-9\-_.]/, "").downcase # _thumb.#{file_extension} is a reserved name for the thumbnailing system, so if the user # has a file with that name rename it. if (clean_filename == '_thumb_small.#{file_extension}') || (clean_filename == '_thumb_large.#{file_extension}') clean_filename = 'thumb.#{file_extension}' end self.mime_type = new_file.content_type self.file_name = clean_filename self.size = new_file.size @file = new_file self.file_dirty = true end end |
#file_extension ⇒ Object
87 88 89 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 87 def file_extension file_name.split(".").last end |
#generate_cropped_image(x, y, w, h, image_type) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 126 def generate_cropped_image(x , y , w , h, image_type) if !File.exist?(self.tmp_location_on_disk) && !File.exist?(self.tmp_original_file_on_disk) self.download_asset_to_tmp_file end processor = Library::Processor::Image.new processor.asset = self processor.generate_cropped_image(x , y , w , h, image_type) self.remove_file_from_tmp_storage end |
#location_on_disk ⇒ Object
Returns the full path to the file’s location on disk.
106 107 108 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 106 def location_on_disk directory + "/" + file_name end |
#original_file_on_disk ⇒ Object
asset path in actual assets directory
111 112 113 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 111 def original_file_on_disk directory + "/original_" + file_name end |
#tmp_location_on_disk ⇒ Object
Returns the full path to the file’s location on disk in tmp directory.
116 117 118 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 116 def tmp_location_on_disk tmp_directory + "/" + file_name end |
#tmp_original_file_on_disk ⇒ Object
asset full path in tmp directory
121 122 123 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 121 def tmp_original_file_on_disk tmp_directory + "/original_" + file_name end |
#url ⇒ Object
Returns the public URL to this asset, relative to the domain.
101 102 103 |
# File 'lib/gluttonberg/library/attachment_mixin.rb', line 101 def url "#{asset_directory_public_url}/#{file_name}" end |