mini-smart-pkg 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/carrierwave-3.1.3/README.md +1214 -0
  3. data/carrierwave-3.1.3/lib/carrierwave/compatibility/paperclip.rb +105 -0
  4. data/carrierwave-3.1.3/lib/carrierwave/downloader/base.rb +101 -0
  5. data/carrierwave-3.1.3/lib/carrierwave/downloader/remote_file.rb +68 -0
  6. data/carrierwave-3.1.3/lib/carrierwave/error.rb +8 -0
  7. data/carrierwave-3.1.3/lib/carrierwave/locale/en.yml +17 -0
  8. data/carrierwave-3.1.3/lib/carrierwave/mount.rb +446 -0
  9. data/carrierwave-3.1.3/lib/carrierwave/mounter.rb +257 -0
  10. data/carrierwave-3.1.3/lib/carrierwave/orm/activerecord.rb +68 -0
  11. data/carrierwave-3.1.3/lib/carrierwave/processing/mini_magick.rb +362 -0
  12. data/carrierwave-3.1.3/lib/carrierwave/processing/rmagick.rb +433 -0
  13. data/carrierwave-3.1.3/lib/carrierwave/processing/vips.rb +315 -0
  14. data/carrierwave-3.1.3/lib/carrierwave/processing.rb +3 -0
  15. data/carrierwave-3.1.3/lib/carrierwave/sanitized_file.rb +361 -0
  16. data/carrierwave-3.1.3/lib/carrierwave/storage/abstract.rb +43 -0
  17. data/carrierwave-3.1.3/lib/carrierwave/storage/file.rb +124 -0
  18. data/carrierwave-3.1.3/lib/carrierwave/storage/fog.rb +560 -0
  19. data/carrierwave-3.1.3/lib/carrierwave/storage.rb +3 -0
  20. data/carrierwave-3.1.3/lib/carrierwave/test/matchers.rb +398 -0
  21. data/carrierwave-3.1.3/lib/carrierwave/uploader/cache.rb +223 -0
  22. data/carrierwave-3.1.3/lib/carrierwave/uploader/callbacks.rb +33 -0
  23. data/carrierwave-3.1.3/lib/carrierwave/uploader/configuration.rb +229 -0
  24. data/carrierwave-3.1.3/lib/carrierwave/uploader/content_type_allowlist.rb +62 -0
  25. data/carrierwave-3.1.3/lib/carrierwave/uploader/content_type_denylist.rb +65 -0
  26. data/carrierwave-3.1.3/lib/carrierwave/uploader/default_url.rb +17 -0
  27. data/carrierwave-3.1.3/lib/carrierwave/uploader/dimension.rb +66 -0
  28. data/carrierwave-3.1.3/lib/carrierwave/uploader/download.rb +24 -0
  29. data/carrierwave-3.1.3/lib/carrierwave/uploader/extension_allowlist.rb +63 -0
  30. data/carrierwave-3.1.3/lib/carrierwave/uploader/extension_denylist.rb +64 -0
  31. data/carrierwave-3.1.3/lib/carrierwave/uploader/file_size.rb +43 -0
  32. data/carrierwave-3.1.3/lib/carrierwave/uploader/mountable.rb +44 -0
  33. data/carrierwave-3.1.3/lib/carrierwave/uploader/processing.rb +128 -0
  34. data/carrierwave-3.1.3/lib/carrierwave/uploader/proxy.rb +99 -0
  35. data/carrierwave-3.1.3/lib/carrierwave/uploader/remove.rb +21 -0
  36. data/carrierwave-3.1.3/lib/carrierwave/uploader/serialization.rb +28 -0
  37. data/carrierwave-3.1.3/lib/carrierwave/uploader/store.rb +168 -0
  38. data/carrierwave-3.1.3/lib/carrierwave/uploader/url.rb +44 -0
  39. data/carrierwave-3.1.3/lib/carrierwave/uploader/versions.rb +352 -0
  40. data/carrierwave-3.1.3/lib/carrierwave/uploader.rb +69 -0
  41. data/carrierwave-3.1.3/lib/carrierwave/utilities/file_name.rb +47 -0
  42. data/carrierwave-3.1.3/lib/carrierwave/utilities/uri.rb +26 -0
  43. data/carrierwave-3.1.3/lib/carrierwave/utilities.rb +7 -0
  44. data/carrierwave-3.1.3/lib/carrierwave/validations/active_model.rb +76 -0
  45. data/carrierwave-3.1.3/lib/carrierwave/version.rb +3 -0
  46. data/carrierwave-3.1.3/lib/carrierwave.rb +108 -0
  47. data/carrierwave-3.1.3/lib/generators/templates/uploader.rb.erb +56 -0
  48. data/carrierwave-3.1.3/lib/generators/uploader_generator.rb +7 -0
  49. data/mini-smart-pkg.gemspec +12 -0
  50. metadata +89 -0
@@ -0,0 +1,68 @@
1
+ require 'active_record'
2
+ require 'carrierwave/validations/active_model'
3
+
4
+ module CarrierWave
5
+ module ActiveRecord
6
+
7
+ include CarrierWave::Mount
8
+
9
+ private
10
+
11
+ def mount_base(column, uploader=nil, options={}, &block)
12
+ super
13
+
14
+ alias_method :read_uploader, :read_attribute
15
+ alias_method :write_uploader, :write_attribute
16
+ public :read_uploader
17
+ public :write_uploader
18
+
19
+ include CarrierWave::Validations::ActiveModel
20
+
21
+ validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity)
22
+ validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
23
+ validates_download_of column if uploader_option(column.to_sym, :validate_download)
24
+
25
+ after_save :"store_#{column}!"
26
+ before_save :"write_#{column}_identifier"
27
+ if ::ActiveRecord.try(:run_after_transaction_callbacks_in_order_defined)
28
+ after_commit :"remove_previously_stored_#{column}", :on => :update
29
+ after_commit :"reset_previous_changes_for_#{column}"
30
+ after_commit :"mark_remove_#{column}_false", :on => :update
31
+ else
32
+ after_commit :"mark_remove_#{column}_false", :on => :update
33
+ after_commit :"reset_previous_changes_for_#{column}"
34
+ after_commit :"remove_previously_stored_#{column}", :on => :update
35
+ end
36
+ after_commit :"remove_#{column}!", :on => :destroy
37
+ after_rollback :"remove_rolled_back_#{column}"
38
+
39
+ mod = Module.new
40
+ prepend mod
41
+ mod.class_eval <<-RUBY, __FILE__, __LINE__+1
42
+ # Reset cached mounter on record reload
43
+ def reload(*)
44
+ @_mounters = nil
45
+ super
46
+ end
47
+
48
+ # Reset cached mounter on record dup
49
+ def initialize_dup(other)
50
+ old_uploaders = _mounter(:"#{column}").uploaders
51
+ super
52
+ @_mounters[:"#{column}"] = nil
53
+ # The attribute needs to be cleared to prevent it from picked up as identifier
54
+ write_uploader(_mounter(:#{column}).serialization_column, nil)
55
+ _mounter(:"#{column}").cache(old_uploaders)
56
+ end
57
+
58
+ def write_#{column}_identifier
59
+ return unless has_attribute?(_mounter(:#{column}).serialization_column)
60
+ super
61
+ end
62
+ RUBY
63
+ end
64
+
65
+ end # ActiveRecord
66
+ end # CarrierWave
67
+
68
+ ActiveRecord::Base.extend CarrierWave::ActiveRecord
@@ -0,0 +1,362 @@
1
+ module CarrierWave
2
+
3
+ ##
4
+ # This module simplifies manipulation with MiniMagick by providing a set
5
+ # of convenient helper methods. If you want to use them, you'll need to
6
+ # require this file:
7
+ #
8
+ # require 'carrierwave/processing/mini_magick'
9
+ #
10
+ # And then include it in your uploader:
11
+ #
12
+ # class MyUploader < CarrierWave::Uploader::Base
13
+ # include CarrierWave::MiniMagick
14
+ # end
15
+ #
16
+ # You can now use the provided helpers:
17
+ #
18
+ # class MyUploader < CarrierWave::Uploader::Base
19
+ # include CarrierWave::MiniMagick
20
+ #
21
+ # process :resize_to_fit => [200, 200]
22
+ # end
23
+ #
24
+ # Or create your own helpers with the powerful minimagick! method, which
25
+ # yields an ImageProcessing::Builder object. Check out the ImageProcessing
26
+ # docs at http://github.com/janko-m/image_processing and the list of all
27
+ # available ImageMagick options at
28
+ # http://www.imagemagick.org/script/command-line-options.php for more info.
29
+ #
30
+ # class MyUploader < CarrierWave::Uploader::Base
31
+ # include CarrierWave::MiniMagick
32
+ #
33
+ # process :radial_blur => 10
34
+ #
35
+ # def radial_blur(amount)
36
+ # minimagick! do |builder|
37
+ # builder.radial_blur(amount)
38
+ # builder = yield(builder) if block_given?
39
+ # builder
40
+ # end
41
+ # end
42
+ # end
43
+ #
44
+ # === Note
45
+ #
46
+ # The ImageProcessing gem uses MiniMagick, a mini replacement for RMagick
47
+ # that uses ImageMagick command-line tools, to build a "convert" command that
48
+ # performs the processing.
49
+ #
50
+ # You can find more information here:
51
+ #
52
+ # https://github.com/minimagick/minimagick/
53
+ #
54
+ #
55
+ module MiniMagick
56
+ extend ActiveSupport::Concern
57
+
58
+ included do
59
+ require "image_processing/mini_magick"
60
+ end
61
+
62
+ module ClassMethods
63
+ def convert(format)
64
+ process :convert => format
65
+ end
66
+
67
+ def resize_to_limit(width, height)
68
+ process :resize_to_limit => [width, height]
69
+ end
70
+
71
+ def resize_to_fit(width, height)
72
+ process :resize_to_fit => [width, height]
73
+ end
74
+
75
+ def resize_to_fill(width, height, gravity='Center')
76
+ process :resize_to_fill => [width, height, gravity]
77
+ end
78
+
79
+ def resize_and_pad(width, height, background=:transparent, gravity='Center')
80
+ process :resize_and_pad => [width, height, background, gravity]
81
+ end
82
+
83
+ def crop(left, top, width, height)
84
+ process :crop => [left, top, width, height]
85
+ end
86
+ end
87
+
88
+ ##
89
+ # Changes the image encoding format to the given format
90
+ #
91
+ # See http://www.imagemagick.org/script/command-line-options.php#format
92
+ #
93
+ # === Parameters
94
+ #
95
+ # [format (#to_s)] an abbreviation of the format
96
+ #
97
+ # === Yields
98
+ #
99
+ # [MiniMagick::Image] additional manipulations to perform
100
+ #
101
+ # === Examples
102
+ #
103
+ # image.convert(:png)
104
+ #
105
+ def convert(format, page=nil, &block)
106
+ minimagick!(block) do |builder|
107
+ builder = builder.convert(format)
108
+ builder = builder.loader(page: page) if page
109
+ builder
110
+ end
111
+ end
112
+
113
+ ##
114
+ # Resize the image to fit within the specified dimensions while retaining
115
+ # the original aspect ratio. Will only resize the image if it is larger than the
116
+ # specified dimensions. The resulting image may be shorter or narrower than specified
117
+ # in the smaller dimension but will not be larger than the specified values.
118
+ #
119
+ # === Parameters
120
+ #
121
+ # [width (Integer)] the width to scale the image to
122
+ # [height (Integer)] the height to scale the image to
123
+ # [combine_options (Hash)] additional ImageMagick options to apply before resizing
124
+ #
125
+ # === Yields
126
+ #
127
+ # [MiniMagick::Image] additional manipulations to perform
128
+ #
129
+ def resize_to_limit(width, height, combine_options: {}, &block)
130
+ width, height = resolve_dimensions(width, height)
131
+
132
+ minimagick!(block) do |builder|
133
+ builder.resize_to_limit(width, height)
134
+ .apply(combine_options)
135
+ end
136
+ end
137
+
138
+ ##
139
+ # Resize the image to fit within the specified dimensions while retaining
140
+ # the original aspect ratio. The image may be shorter or narrower than
141
+ # specified in the smaller dimension but will not be larger than the specified values.
142
+ #
143
+ # === Parameters
144
+ #
145
+ # [width (Integer)] the width to scale the image to
146
+ # [height (Integer)] the height to scale the image to
147
+ # [combine_options (Hash)] additional ImageMagick options to apply before resizing
148
+ #
149
+ # === Yields
150
+ #
151
+ # [MiniMagick::Image] additional manipulations to perform
152
+ #
153
+ def resize_to_fit(width, height, combine_options: {}, &block)
154
+ width, height = resolve_dimensions(width, height)
155
+
156
+ minimagick!(block) do |builder|
157
+ builder.resize_to_fit(width, height)
158
+ .apply(combine_options)
159
+ end
160
+ end
161
+
162
+ ##
163
+ # Resize the image to fit within the specified dimensions while retaining
164
+ # the aspect ratio of the original image. If necessary, crop the image in the
165
+ # larger dimension.
166
+ #
167
+ # === Parameters
168
+ #
169
+ # [width (Integer)] the width to scale the image to
170
+ # [height (Integer)] the height to scale the image to
171
+ # [gravity (String)] the current gravity suggestion (default: 'Center'; options: 'NorthWest', 'North', 'NorthEast', 'West', 'Center', 'East', 'SouthWest', 'South', 'SouthEast')
172
+ # [combine_options (Hash)] additional ImageMagick options to apply before resizing
173
+ #
174
+ # === Yields
175
+ #
176
+ # [MiniMagick::Image] additional manipulations to perform
177
+ #
178
+ def resize_to_fill(width, height, gravity = 'Center', combine_options: {}, &block)
179
+ width, height = resolve_dimensions(width, height)
180
+
181
+ minimagick!(block) do |builder|
182
+ builder.resize_to_fill(width, height, gravity: gravity)
183
+ .apply(combine_options)
184
+ end
185
+ end
186
+
187
+ ##
188
+ # Resize the image to fit within the specified dimensions while retaining
189
+ # the original aspect ratio. If necessary, will pad the remaining area
190
+ # with the given color, which defaults to transparent (for gif and png,
191
+ # white for jpeg).
192
+ #
193
+ # See http://www.imagemagick.org/script/command-line-options.php#gravity
194
+ # for gravity options.
195
+ #
196
+ # === Parameters
197
+ #
198
+ # [width (Integer)] the width to scale the image to
199
+ # [height (Integer)] the height to scale the image to
200
+ # [background (String, :transparent)] the color of the background as a hexcode, like "#ff45de"
201
+ # [gravity (String)] how to position the image
202
+ # [combine_options (Hash)] additional ImageMagick options to apply before resizing
203
+ #
204
+ # === Yields
205
+ #
206
+ # [MiniMagick::Image] additional manipulations to perform
207
+ #
208
+ def resize_and_pad(width, height, background=:transparent, gravity='Center', combine_options: {}, &block)
209
+ width, height = resolve_dimensions(width, height)
210
+
211
+ minimagick!(block) do |builder|
212
+ builder.resize_and_pad(width, height, background: background, gravity: gravity)
213
+ .apply(combine_options)
214
+ end
215
+ end
216
+
217
+ ##
218
+ # Crop the image to the contents of a box positioned at [left] and [top], with the dimensions given
219
+ # by [width] and [height]. The original image bottom/right edge is preserved if the cropping box falls
220
+ # outside the image bounds.
221
+ #
222
+ # === Parameters
223
+ #
224
+ # [left (integer)] left edge of area to extract
225
+ # [top (integer)] top edge of area to extract
226
+ # [width (Integer)] width of area to extract
227
+ # [height (Integer)] height of area to extract
228
+ #
229
+ # === Yields
230
+ #
231
+ # [MiniMagick::Image] additional manipulations to perform
232
+ #
233
+ def crop(left, top, width, height, combine_options: {}, &block)
234
+ width, height = resolve_dimensions(width, height)
235
+
236
+ minimagick!(block) do |builder|
237
+ builder.crop(left, top, width, height)
238
+ .apply(combine_options)
239
+ end
240
+ end
241
+
242
+ ##
243
+ # Returns the width of the image in pixels.
244
+ #
245
+ # === Returns
246
+ #
247
+ # [Integer] the image's width in pixels
248
+ #
249
+ def width
250
+ mini_magick_image[:width]
251
+ end
252
+
253
+ ##
254
+ # Returns the height of the image in pixels.
255
+ #
256
+ # === Returns
257
+ #
258
+ # [Integer] the image's height in pixels
259
+ #
260
+ def height
261
+ mini_magick_image[:height]
262
+ end
263
+
264
+ ##
265
+ # Manipulate the image with MiniMagick. This method will load up an image
266
+ # and then pass each of its frames to the supplied block. It will then
267
+ # save the image to disk.
268
+ #
269
+ # NOTE: This method exists mostly for backwards compatibility, you should
270
+ # probably use #minimagick!.
271
+ #
272
+ # === Gotcha
273
+ #
274
+ # This method assumes that the object responds to +current_path+.
275
+ # Any class that this module is mixed into must have a +current_path+ method.
276
+ # CarrierWave::Uploader does, so you won't need to worry about this in
277
+ # most cases.
278
+ #
279
+ # === Yields
280
+ #
281
+ # [MiniMagick::Image] manipulations to perform
282
+ #
283
+ # === Raises
284
+ #
285
+ # [CarrierWave::ProcessingError] if manipulation failed.
286
+ #
287
+ def manipulate!
288
+ cache_stored_file! if !cached?
289
+ image = ::MiniMagick::Image.open(current_path)
290
+
291
+ image = yield(image)
292
+ FileUtils.mv image.path, current_path
293
+
294
+ ::MiniMagick::Image.new(current_path).identify
295
+ rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
296
+ raise e if e.message =~ /(You must have .+ installed|is not installed|executable not found|delegate failed)/
297
+ message = I18n.translate(:"errors.messages.processing_error")
298
+ raise CarrierWave::ProcessingError, message
299
+ ensure
300
+ image.destroy! if image
301
+ end
302
+
303
+ # Process the image with MiniMagick, using the ImageProcessing gem. This
304
+ # method will build a "convert" ImageMagick command and execute it on the
305
+ # current image.
306
+ #
307
+ # === Gotcha
308
+ #
309
+ # This method assumes that the object responds to +current_path+.
310
+ # Any class that this module is mixed into must have a +current_path+ method.
311
+ # CarrierWave::Uploader does, so you won't need to worry about this in
312
+ # most cases.
313
+ #
314
+ # === Yields
315
+ #
316
+ # [ImageProcessing::Builder] use it to define processing to be performed
317
+ #
318
+ # === Raises
319
+ #
320
+ # [CarrierWave::ProcessingError] if processing failed.
321
+ def minimagick!(block = nil)
322
+ builder = ImageProcessing::MiniMagick.source(current_path)
323
+ builder = yield(builder)
324
+
325
+ result = builder.call
326
+ result.close
327
+
328
+ # backwards compatibility (we want to eventually move away from MiniMagick::Image)
329
+ if block
330
+ image = ::MiniMagick::Image.new(result.path, result)
331
+ image = block.call(image)
332
+ result = image.instance_variable_get(:@tempfile)
333
+ end
334
+
335
+ FileUtils.mv result.path, current_path
336
+
337
+ if File.extname(result.path) != File.extname(current_path)
338
+ move_to = current_path.chomp(File.extname(current_path)) + File.extname(result.path)
339
+ file.content_type = Marcel::Magic.by_path(move_to).try(:type)
340
+ file.move_to(move_to, permissions, directory_permissions)
341
+ end
342
+ rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
343
+ raise e if e.message =~ /(You must have .+ installed|is not installed|executable not found)/
344
+ message = I18n.translate(:"errors.messages.processing_error")
345
+ raise CarrierWave::ProcessingError, message
346
+ end
347
+
348
+ private
349
+
350
+ def resolve_dimensions(*dimensions)
351
+ dimensions.map do |value|
352
+ next value unless value.instance_of?(Proc)
353
+ value.arity >= 1 ? value.call(self) : value.call
354
+ end
355
+ end
356
+
357
+ def mini_magick_image
358
+ ::MiniMagick::Image.read(read)
359
+ end
360
+
361
+ end # MiniMagick
362
+ end # CarrierWave