locomotive_carrierwave 0.5.4.beta2 → 0.5.4.beta3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -569,6 +569,8 @@ The RMagick module gives you a few methods, like
569
569
  `CarrierWave::RMagick#resize_to_fill` which manipulate the image file in some
570
570
  way. You can set a `process` callback, which will call that method any time a
571
571
  file is uploaded.
572
+ There is a demonstration of convert here.
573
+ Convert will only work if the file has the same file extension, thus the use of the filename method.
572
574
 
573
575
  ``` ruby
574
576
  class AvatarUploader < CarrierWave::Uploader::Base
@@ -578,7 +580,7 @@ class AvatarUploader < CarrierWave::Uploader::Base
578
580
  process :convert => 'png'
579
581
 
580
582
  def filename
581
- super + '.png'
583
+ super.chomp(File.extname(super)) + '.png'
582
584
  end
583
585
  end
584
586
  ```
@@ -3,7 +3,12 @@
3
3
  require 'fileutils'
4
4
  require 'active_support/core_ext/object/blank'
5
5
  require 'active_support/core_ext/class/attribute'
6
- require 'active_support/core_ext/class/inheritable_attributes'
6
+
7
+ begin
8
+ require 'active_support/core_ext/class/inheritable_attributes'
9
+ rescue LoadError
10
+ end
11
+
7
12
  require 'active_support/concern'
8
13
  require 'active_support/memoizable'
9
14
 
@@ -32,6 +37,7 @@ module CarrierWave
32
37
  autoload :RMagick, 'carrierwave/processing/rmagick'
33
38
  autoload :ImageScience, 'carrierwave/processing/image_science'
34
39
  autoload :MiniMagick, 'carrierwave/processing/mini_magick'
40
+ autoload :MimeTypes, 'carrierwave/processing/mime_types'
35
41
  autoload :VERSION, 'carrierwave/version'
36
42
 
37
43
  module Storage
@@ -39,9 +39,11 @@ module CarrierWave
39
39
  value = value.duplicable? ? value.clone : value
40
40
  rescue TypeError, NoMethodError
41
41
  end
42
- @modifications[column] = value
42
+ setup_modifications
43
43
 
44
- super
44
+ super.tap do
45
+ @modifications[column] = [value, __send__(column)]
46
+ end
45
47
  end
46
48
 
47
49
  def #{column}_changed?
@@ -26,8 +26,6 @@ module CarrierWave
26
26
  # specified in the smaller dimension but will not be larger than the
27
27
  # specified values.
28
28
  #
29
- # See even http://www.imagemagick.org/RMagick/doc/image3.html#resize_to_fit
30
- #
31
29
  # === Parameters
32
30
  #
33
31
  # [width (Integer)] the width to scale the image to
@@ -49,8 +47,6 @@ module CarrierWave
49
47
  # the aspect ratio of the original image. If necessary, crop the image in
50
48
  # the larger dimension.
51
49
  #
52
- # See even http://www.imagemagick.org/RMagick/doc/image3.html#resize_to_fill
53
- #
54
50
  # === Parameters
55
51
  #
56
52
  # [width (Integer)] the width to scale the image to
@@ -0,0 +1,58 @@
1
+ require 'mime/types'
2
+
3
+ module CarrierWave
4
+
5
+ ##
6
+ # This module simplifies the use of the mime-types gem to intelligently
7
+ # guess and set the content-type of a file. If you want to use this, you'll
8
+ # need to require this file:
9
+ #
10
+ # require 'carrierwave/processing/mime_types'
11
+ #
12
+ # And then include it in your uploader:
13
+ #
14
+ # class MyUploader < CarrierWave::Uploader::Base
15
+ # include CarrierWave::MimeTypes
16
+ # end
17
+ #
18
+ # You can now use the provided helper:
19
+ #
20
+ # class MyUploader < CarrierWave::Uploader::Base
21
+ # include CarrierWave::MimeTypes
22
+ #
23
+ # process :set_content_type
24
+ # end
25
+ #
26
+ module MimeTypes
27
+ extend ActiveSupport::Concern
28
+
29
+ module ClassMethods
30
+ def set_content_type(override=false)
31
+ process :set_content_type => override
32
+ end
33
+ end
34
+
35
+ ##
36
+ # Changes the file content_type using the mime-types gem
37
+ #
38
+ # === Parameters
39
+ #
40
+ # [override (Boolean)] whether or not to override the file's content_type
41
+ # if it is already set and not a generic content-type,
42
+ # false by default
43
+ #
44
+ def set_content_type(override=false)
45
+ if override || file.content_type.blank? || file.content_type == 'application/octet-stream'
46
+ new_content_type = ::MIME::Types.type_for(file.original_filename).first.to_s
47
+ if file.respond_to?(:content_type=)
48
+ file.content_type = new_content_type
49
+ else
50
+ file.set_instance_variable(:@content_type, new_content_type)
51
+ end
52
+ end
53
+ rescue ::MIME::InvalidContentType => e
54
+ raise CarrierWave::ProcessingError.new("Failed to process file with MIME::Types, maybe not valid content-type? Original Error: #{e}")
55
+ end
56
+
57
+ end # MimeTypes
58
+ end # CarrierWave
@@ -129,12 +129,9 @@ module CarrierWave
129
129
  end
130
130
 
131
131
  ##
132
- # From the RMagick documentation: "Resize the image to fit within the
133
- # specified dimensions while retaining the original aspect ratio. The
134
- # image may be shorter or narrower than specified in the smaller dimension
135
- # but will not be larger than the specified values."
136
- #
137
- # See even http://www.imagemagick.org/RMagick/doc/image3.html#resize_to_fit
132
+ # Resize the image to fit within the specified dimensions while retaining
133
+ # the original aspect ratio. The image may be shorter or narrower than
134
+ # specified in the smaller dimension but will not be larger than the specified values.
138
135
  #
139
136
  # === Parameters
140
137
  #
@@ -154,15 +151,9 @@ module CarrierWave
154
151
  end
155
152
 
156
153
  ##
157
- # From the RMagick documentation: "Resize the image to fit within the
158
- # specified dimensions while retaining the aspect ratio of the original
159
- # image. If necessary, crop the image in the larger dimension."
160
- #
161
- # See even http://www.imagemagick.org/RMagick/doc/image3.html#resize_to_fill
162
- #
163
- # and
164
- #
165
- # http://www.clipclip.org/clips/detail/4365/jerrett-net-»-crop_resized-in-rmagick
154
+ # Resize the image to fit within the specified dimensions while retaining
155
+ # the aspect ratio of the original image. If necessary, crop the image in the
156
+ # larger dimension.
166
157
  #
167
158
  # === Parameters
168
159
  #
@@ -229,7 +220,7 @@ module CarrierWave
229
220
  end
230
221
 
231
222
  ##
232
- # Manipulate the image with RMagick. This method will load up an image
223
+ # Manipulate the image with MiniMagick. This method will load up an image
233
224
  # and then pass each of its frames to the supplied block. It will then
234
225
  # save the image to disk.
235
226
  #
@@ -16,10 +16,10 @@ module CarrierWave
16
16
  class SanitizedFile
17
17
 
18
18
  attr_accessor :file
19
-
19
+
20
20
  class << self
21
21
  attr_writer :sanitize_regexp
22
-
22
+
23
23
  def sanitize_regexp
24
24
  @sanitize_regexp ||= /[^a-zA-Z0-9\.\-\+_]/
25
25
  end
@@ -228,6 +228,17 @@ module CarrierWave
228
228
  @file.content_type.chomp if @file.respond_to?(:content_type) and @file.content_type
229
229
  end
230
230
 
231
+ ##
232
+ # Sets the content type of the file.
233
+ #
234
+ # === Returns
235
+ #
236
+ # [String] the content type of the file
237
+ #
238
+ def content_type=(type)
239
+ @content_type = type
240
+ end
241
+
231
242
  ##
232
243
  # Used to sanitize the file name. Public to allow overriding for non-latin characters.
233
244
  #
@@ -5,7 +5,7 @@ module CarrierWave
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- class_inheritable_accessor :_storage, :instance_reader => false, :instance_writer => false
8
+ class_attribute :_storage, :instance_writer => false
9
9
 
10
10
  add_config :root
11
11
  add_config :permissions
@@ -37,6 +37,7 @@ module CarrierWave
37
37
  add_config :enable_processing
38
38
  add_config :ensure_multipart_form
39
39
  add_config :delete_tmp_file_after_storage
40
+ add_config :delete_cache_id_after_storage
40
41
  add_config :remove_previously_stored_files_after_update
41
42
 
42
43
  # fog
@@ -144,6 +145,7 @@ module CarrierWave
144
145
  config.store_dir = 'uploads'
145
146
  config.cache_dir = 'uploads/tmp'
146
147
  config.delete_tmp_file_after_storage = true
148
+ config.delete_cache_id_after_storage = true
147
149
  config.remove_previously_stored_files_after_update = true
148
150
  config.ignore_integrity_errors = true
149
151
  config.ignore_processing_errors = true
@@ -8,7 +8,7 @@ module CarrierWave
8
8
  include CarrierWave::Uploader::Callbacks
9
9
 
10
10
  included do
11
- class_inheritable_accessor :processors, :instance_reader => false, :instance_writer => false
11
+ class_attribute :processors, :instance_writer => false
12
12
  self.processors = []
13
13
 
14
14
  after :cache, :process!
@@ -63,10 +63,10 @@ module CarrierWave
63
63
  if arg.is_a?(Hash)
64
64
  condition = arg.delete(:if)
65
65
  arg.each do |method, args|
66
- processors.push([method, args, condition])
66
+ self.processors += [[method, args, condition]]
67
67
  end
68
68
  else
69
- processors.push([arg, [], nil])
69
+ self.processors += [[arg, [], nil]]
70
70
  end
71
71
  end
72
72
  end
@@ -58,11 +58,22 @@ module CarrierWave
58
58
  with_callbacks(:store, new_file) do
59
59
  new_file = storage.store!(@file)
60
60
  @file.delete if delete_tmp_file_after_storage
61
+ delete_cache_id if delete_cache_id_after_storage
61
62
  @file = new_file
62
63
  @cache_id = nil
63
64
  end
64
65
  end
65
66
  end
67
+
68
+ ##
69
+ # Deletes a cache id (tmp dir in cache)
70
+ #
71
+ def delete_cache_id
72
+ if @cache_id
73
+ path = File.join(cache_dir, @cache_id)
74
+ FileUtils.rm_rf(path) if File.exists?(path) && File.directory?(path)
75
+ end
76
+ end
66
77
 
67
78
  ##
68
79
  # Retrieves the file from the storage.
@@ -8,10 +8,20 @@ module CarrierWave
8
8
  include CarrierWave::Uploader::Callbacks
9
9
 
10
10
  included do
11
- class_inheritable_accessor :versions, :instance_reader => false, :instance_writer => false
12
- self.versions = {}
11
+ ##
12
+ # Add configuration options for versions
13
+ # class_inheritable_accessor was deprecated in Rails 3.1 and removed for 3.2.
14
+ # class_attribute was added in 3.0, but doesn't support omitting the instance_reader until 3.0.10
15
+ # For max compatibility, always use class_inheritable_accessor when possible
16
+ if respond_to?(:class_inheritable_accessor)
17
+ ActiveSupport::Deprecation.silence do
18
+ class_inheritable_accessor :versions, :version_names, :instance_reader => false, :instance_writer => false
19
+ end
20
+ else
21
+ class_attribute :versions, :version_names, :instance_reader => false, :instance_writer => false
22
+ end
13
23
 
14
- class_inheritable_accessor :version_names, :instance_reader => false, :instance_writer => false
24
+ self.versions = {}
15
25
  self.version_names = []
16
26
 
17
27
  after :cache, :cache_versions!
@@ -50,6 +60,7 @@ module CarrierWave
50
60
  name = name.to_sym
51
61
  unless versions[name]
52
62
  uploader = Class.new(self)
63
+ uploader.versions = {}
53
64
 
54
65
  # Define the enable_processing method for versions so they get the
55
66
  # value from the parent class unless explicitly overwritten
@@ -64,11 +75,16 @@ module CarrierWave
64
75
  end
65
76
  RUBY
66
77
 
67
- versions[name] = {
78
+ # Add the current version hash to class attribute :versions
79
+ current_version = {}
80
+ current_version[name] = {
68
81
  :uploader => uploader,
69
- :options => options,
82
+ :options => options
70
83
  }
71
- versions[name][:uploader].version_names.push(name)
84
+ self.versions = versions.merge(current_version)
85
+
86
+ versions[name][:uploader].version_names += [name]
87
+
72
88
  class_eval <<-RUBY
73
89
  def #{name}
74
90
  versions[:#{name}]
@@ -76,6 +92,7 @@ module CarrierWave
76
92
  RUBY
77
93
  # as the processors get the output from the previous processors as their
78
94
  # input we must not stack the processors here
95
+ versions[name][:uploader].processors = versions[name][:uploader].processors.dup
79
96
  versions[name][:uploader].processors.clear
80
97
  end
81
98
  versions[name][:uploader].class_eval(&block) if block
@@ -1,3 +1,3 @@
1
1
  module CarrierWave
2
- VERSION = "0.5.4.beta2"
2
+ VERSION = "0.5.4.beta3"
3
3
  end
metadata CHANGED
@@ -1,24 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotive_carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196439
4
+ hash: 62196437
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
9
  - 4
10
10
  - beta
11
- - 2
12
- version: 0.5.4.beta2
11
+ - 3
12
+ version: 0.5.4.beta3
13
13
  platform: ruby
14
14
  authors:
15
15
  - Jonas Nicklas
16
- - Didier Lafforgue
17
16
  autorequire:
18
17
  bindir: bin
19
18
  cert_chain: []
20
19
 
21
- date: 2011-06-12 00:00:00 Z
20
+ date: 2011-06-27 00:00:00 Z
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency
24
23
  name: activesupport
@@ -264,7 +263,6 @@ dependencies:
264
263
  description: Upload files in your Ruby applications, map them to a range of ORMs, store them on different backends.
265
264
  email:
266
265
  - jonas.nicklas@gmail.com
267
- - didier@nocoffee.fr
268
266
  executables: []
269
267
 
270
268
  extensions: []
@@ -278,6 +276,7 @@ files:
278
276
  - lib/carrierwave/orm/activerecord.rb
279
277
  - lib/carrierwave/orm/mongoid.rb
280
278
  - lib/carrierwave/processing/image_science.rb
279
+ - lib/carrierwave/processing/mime_types.rb
281
280
  - lib/carrierwave/processing/mini_magick.rb
282
281
  - lib/carrierwave/processing/rmagick.rb
283
282
  - lib/carrierwave/sanitized_file.rb
@@ -315,7 +314,6 @@ licenses: []
315
314
  post_install_message:
316
315
  rdoc_options:
317
316
  - --main
318
- - README.md
319
317
  require_paths:
320
318
  - lib
321
319
  required_ruby_version: !ruby/object:Gem::Requirement