card 1.19.3 → 1.19.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/VERSION +1 -1
  4. data/card.gemspec +1 -3
  5. data/db/migrate_core_cards/20160914132636_fix_mod_files.rb +25 -0
  6. data/lib/card.rb +0 -2
  7. data/lib/card/content/diff.rb +3 -4
  8. data/lib/card/format/error.rb +1 -1
  9. data/mod/admin/set/self/admin.rb +2 -2
  10. data/mod/admin/set/self/trash.rb +9 -3
  11. data/mod/basic_types/set/type/html.rb +1 -1
  12. data/mod/bootstrap/set/all/bootstrap/layout.rb +58 -0
  13. data/mod/bootstrap/spec/set/all/bootstrap/layout_spec.rb +32 -0
  14. data/mod/carrierwave/lib/carrier_wave/cardmount.rb +0 -2
  15. data/mod/carrierwave/set/abstract/attachment/upload_cache.rb +2 -1
  16. data/mod/core/set/all/stages.rb +6 -4
  17. data/mod/history/lib/card/act.rb +8 -7
  18. data/mod/history/set/all/history.rb +10 -8
  19. data/mod/machines/set/abstract/script.rb +1 -1
  20. data/mod/machines/set/type/css.rb +1 -1
  21. data/mod/pointer/set/abstract/01_pointer.rb +1 -1
  22. data/mod/standard/file/credit_image/image-icon.png +0 -0
  23. data/mod/standard/file/credit_image/image-large.png +0 -0
  24. data/mod/standard/file/credit_image/image-medium.png +0 -0
  25. data/mod/standard/file/credit_image/image-small.png +0 -0
  26. data/mod/standard/file/favicon/image-icon.png +0 -0
  27. data/mod/standard/file/favicon/image-large.png +0 -0
  28. data/mod/standard/file/favicon/image-medium.png +0 -0
  29. data/mod/standard/file/favicon/image-small.png +0 -0
  30. data/mod/standard/file/logo/image-icon.png +0 -0
  31. data/mod/standard/file/logo/image-large.png +0 -0
  32. data/mod/standard/file/logo/image-medium.png +0 -0
  33. data/mod/standard/file/logo/image-small.png +0 -0
  34. data/mod/standard/set/self/recent.rb +2 -2
  35. data/spec/lib/card/diff_spec.rb +9 -9
  36. metadata +19 -156
  37. data/vendor/carrierwave/.gitignore +0 -19
  38. data/vendor/carrierwave/.rubocop.yml +0 -262
  39. data/vendor/carrierwave/.travis.yml +0 -58
  40. data/vendor/carrierwave/CHANGELOG.md +0 -81
  41. data/vendor/carrierwave/CONTRIBUTING.md +0 -37
  42. data/vendor/carrierwave/Gemfile +0 -5
  43. data/vendor/carrierwave/README.md +0 -995
  44. data/vendor/carrierwave/Rakefile +0 -26
  45. data/vendor/carrierwave/carrierwave.gemspec +0 -45
  46. data/vendor/carrierwave/cucumber.yml +0 -2
  47. data/vendor/carrierwave/features/caching.feature +0 -28
  48. data/vendor/carrierwave/features/download.feature +0 -20
  49. data/vendor/carrierwave/features/file_storage.feature +0 -37
  50. data/vendor/carrierwave/features/file_storage_overridden_filename.feature +0 -38
  51. data/vendor/carrierwave/features/file_storage_overridden_store_dir.feature +0 -38
  52. data/vendor/carrierwave/features/file_storage_reversing_processor.feature +0 -43
  53. data/vendor/carrierwave/features/fixtures/bork.txt +0 -1
  54. data/vendor/carrierwave/features/fixtures/monkey.txt +0 -1
  55. data/vendor/carrierwave/features/fixtures/upcased_bork.txt +0 -1
  56. data/vendor/carrierwave/features/mount_activerecord.feature +0 -46
  57. data/vendor/carrierwave/features/step_definitions/activerecord_steps.rb +0 -20
  58. data/vendor/carrierwave/features/step_definitions/caching_steps.rb +0 -12
  59. data/vendor/carrierwave/features/step_definitions/datamapper_steps.rb +0 -27
  60. data/vendor/carrierwave/features/step_definitions/download_steps.rb +0 -8
  61. data/vendor/carrierwave/features/step_definitions/file_steps.rb +0 -51
  62. data/vendor/carrierwave/features/step_definitions/general_steps.rb +0 -102
  63. data/vendor/carrierwave/features/step_definitions/mount_steps.rb +0 -17
  64. data/vendor/carrierwave/features/step_definitions/store_steps.rb +0 -16
  65. data/vendor/carrierwave/features/support/activerecord.rb +0 -18
  66. data/vendor/carrierwave/features/support/env.rb +0 -19
  67. data/vendor/carrierwave/features/versions_basics.feature +0 -50
  68. data/vendor/carrierwave/features/versions_caching_from_versions.feature +0 -32
  69. data/vendor/carrierwave/features/versions_nested_versions.feature +0 -70
  70. data/vendor/carrierwave/features/versions_overridden_filename.feature +0 -51
  71. data/vendor/carrierwave/features/versions_overriden_store_dir.feature +0 -41
  72. data/vendor/carrierwave/gemfiles/rails-4-0-stable.gemfile +0 -5
  73. data/vendor/carrierwave/gemfiles/rails-4-1-stable.gemfile +0 -5
  74. data/vendor/carrierwave/gemfiles/rails-4-2-stable.gemfile +0 -5
  75. data/vendor/carrierwave/gemfiles/rails-master.gemfile +0 -11
  76. data/vendor/carrierwave/lib/carrierwave.rb +0 -93
  77. data/vendor/carrierwave/lib/carrierwave/compatibility/paperclip.rb +0 -103
  78. data/vendor/carrierwave/lib/carrierwave/error.rb +0 -8
  79. data/vendor/carrierwave/lib/carrierwave/locale/cs.yml +0 -14
  80. data/vendor/carrierwave/lib/carrierwave/locale/de.yml +0 -14
  81. data/vendor/carrierwave/lib/carrierwave/locale/el.yml +0 -14
  82. data/vendor/carrierwave/lib/carrierwave/locale/en.yml +0 -14
  83. data/vendor/carrierwave/lib/carrierwave/locale/es.yml +0 -14
  84. data/vendor/carrierwave/lib/carrierwave/locale/fr-CA.yml +0 -14
  85. data/vendor/carrierwave/lib/carrierwave/locale/fr.yml +0 -14
  86. data/vendor/carrierwave/lib/carrierwave/locale/id.yml +0 -14
  87. data/vendor/carrierwave/lib/carrierwave/locale/ja.yml +0 -14
  88. data/vendor/carrierwave/lib/carrierwave/locale/nb.yml +0 -14
  89. data/vendor/carrierwave/lib/carrierwave/locale/nl.yml +0 -14
  90. data/vendor/carrierwave/lib/carrierwave/locale/pl.yml +0 -14
  91. data/vendor/carrierwave/lib/carrierwave/locale/pt-BR.yml +0 -14
  92. data/vendor/carrierwave/lib/carrierwave/locale/pt-PT.yml +0 -14
  93. data/vendor/carrierwave/lib/carrierwave/locale/ru.yml +0 -14
  94. data/vendor/carrierwave/lib/carrierwave/locale/sk.yml +0 -14
  95. data/vendor/carrierwave/lib/carrierwave/locale/tr.yml +0 -14
  96. data/vendor/carrierwave/lib/carrierwave/locale/zh-CN.yml +0 -14
  97. data/vendor/carrierwave/lib/carrierwave/locale/zh-TW.yml +0 -14
  98. data/vendor/carrierwave/lib/carrierwave/mount.rb +0 -444
  99. data/vendor/carrierwave/lib/carrierwave/mounter.rb +0 -163
  100. data/vendor/carrierwave/lib/carrierwave/orm/activerecord.rb +0 -103
  101. data/vendor/carrierwave/lib/carrierwave/processing.rb +0 -2
  102. data/vendor/carrierwave/lib/carrierwave/processing/mini_magick.rb +0 -328
  103. data/vendor/carrierwave/lib/carrierwave/processing/rmagick.rb +0 -379
  104. data/vendor/carrierwave/lib/carrierwave/sanitized_file.rb +0 -348
  105. data/vendor/carrierwave/lib/carrierwave/storage.rb +0 -2
  106. data/vendor/carrierwave/lib/carrierwave/storage/abstract.rb +0 -43
  107. data/vendor/carrierwave/lib/carrierwave/storage/file.rb +0 -118
  108. data/vendor/carrierwave/lib/carrierwave/storage/fog.rb +0 -462
  109. data/vendor/carrierwave/lib/carrierwave/test/matchers.rb +0 -394
  110. data/vendor/carrierwave/lib/carrierwave/uploader.rb +0 -67
  111. data/vendor/carrierwave/lib/carrierwave/uploader/cache.rb +0 -207
  112. data/vendor/carrierwave/lib/carrierwave/uploader/callbacks.rb +0 -33
  113. data/vendor/carrierwave/lib/carrierwave/uploader/configuration.rb +0 -203
  114. data/vendor/carrierwave/lib/carrierwave/uploader/content_type_blacklist.rb +0 -48
  115. data/vendor/carrierwave/lib/carrierwave/uploader/content_type_whitelist.rb +0 -48
  116. data/vendor/carrierwave/lib/carrierwave/uploader/default_url.rb +0 -17
  117. data/vendor/carrierwave/lib/carrierwave/uploader/download.rb +0 -92
  118. data/vendor/carrierwave/lib/carrierwave/uploader/extension_blacklist.rb +0 -51
  119. data/vendor/carrierwave/lib/carrierwave/uploader/extension_whitelist.rb +0 -51
  120. data/vendor/carrierwave/lib/carrierwave/uploader/file_size.rb +0 -41
  121. data/vendor/carrierwave/lib/carrierwave/uploader/magic_mime_blacklist.rb +0 -94
  122. data/vendor/carrierwave/lib/carrierwave/uploader/magic_mime_whitelist.rb +0 -94
  123. data/vendor/carrierwave/lib/carrierwave/uploader/mountable.rb +0 -38
  124. data/vendor/carrierwave/lib/carrierwave/uploader/processing.rb +0 -88
  125. data/vendor/carrierwave/lib/carrierwave/uploader/proxy.rb +0 -86
  126. data/vendor/carrierwave/lib/carrierwave/uploader/remove.rb +0 -21
  127. data/vendor/carrierwave/lib/carrierwave/uploader/serialization.rb +0 -28
  128. data/vendor/carrierwave/lib/carrierwave/uploader/store.rb +0 -93
  129. data/vendor/carrierwave/lib/carrierwave/uploader/url.rb +0 -41
  130. data/vendor/carrierwave/lib/carrierwave/uploader/versions.rb +0 -295
  131. data/vendor/carrierwave/lib/carrierwave/utilities.rb +0 -6
  132. data/vendor/carrierwave/lib/carrierwave/utilities/uri.rb +0 -21
  133. data/vendor/carrierwave/lib/carrierwave/validations/active_model.rb +0 -78
  134. data/vendor/carrierwave/lib/carrierwave/version.rb +0 -3
  135. data/vendor/carrierwave/lib/generators/templates/uploader.rb +0 -49
  136. data/vendor/carrierwave/lib/generators/uploader_generator.rb +0 -7
  137. data/vendor/carrierwave/script/console +0 -10
  138. data/vendor/carrierwave/script/destroy +0 -14
  139. data/vendor/carrierwave/script/generate +0 -14
  140. data/vendor/carrierwave/spec/compatibility/paperclip_spec.rb +0 -138
  141. data/vendor/carrierwave/spec/fixtures/Uppercase.jpg +0 -1
  142. data/vendor/carrierwave/spec/fixtures/bork.ttxt +0 -1
  143. data/vendor/carrierwave/spec/fixtures/bork.txt +0 -1
  144. data/vendor/carrierwave/spec/fixtures/bork.txtt +0 -1
  145. data/vendor/carrierwave/spec/fixtures/case.JPG +0 -1
  146. data/vendor/carrierwave/spec/fixtures/landscape.jpg +0 -0
  147. data/vendor/carrierwave/spec/fixtures/multi_page.pdf +0 -0
  148. data/vendor/carrierwave/spec/fixtures/new.jpeg +0 -1
  149. data/vendor/carrierwave/spec/fixtures/new.txt +0 -1
  150. data/vendor/carrierwave/spec/fixtures/old.jpeg +0 -1
  151. data/vendor/carrierwave/spec/fixtures/old.txt +0 -1
  152. data/vendor/carrierwave/spec/fixtures/portrait.jpg +0 -0
  153. data/vendor/carrierwave/spec/fixtures/ruby.gif +0 -0
  154. data/vendor/carrierwave/spec/fixtures/sponsored.doc +0 -1
  155. data/vendor/carrierwave/spec/fixtures/test+.jpg +0 -1
  156. data/vendor/carrierwave/spec/fixtures/test.jpeg +0 -1
  157. data/vendor/carrierwave/spec/fixtures/test.jpg +0 -1
  158. data/vendor/carrierwave/spec/generators/uploader_generator_spec.rb +0 -19
  159. data/vendor/carrierwave/spec/mount_multiple_spec.rb +0 -913
  160. data/vendor/carrierwave/spec/mount_single_spec.rb +0 -793
  161. data/vendor/carrierwave/spec/orm/activerecord_spec.rb +0 -1556
  162. data/vendor/carrierwave/spec/processing/mini_magick_spec.rb +0 -210
  163. data/vendor/carrierwave/spec/processing/rmagick_spec.rb +0 -250
  164. data/vendor/carrierwave/spec/sanitized_file_spec.rb +0 -805
  165. data/vendor/carrierwave/spec/spec_helper.rb +0 -105
  166. data/vendor/carrierwave/spec/storage/file_spec.rb +0 -82
  167. data/vendor/carrierwave/spec/storage/fog_credentials.rb +0 -46
  168. data/vendor/carrierwave/spec/storage/fog_helper.rb +0 -428
  169. data/vendor/carrierwave/spec/storage/fog_spec.rb +0 -48
  170. data/vendor/carrierwave/spec/support/activerecord.rb +0 -31
  171. data/vendor/carrierwave/spec/support/file_utils_helper.rb +0 -15
  172. data/vendor/carrierwave/spec/uploader/cache_spec.rb +0 -324
  173. data/vendor/carrierwave/spec/uploader/callback_spec.rb +0 -30
  174. data/vendor/carrierwave/spec/uploader/configuration_spec.rb +0 -133
  175. data/vendor/carrierwave/spec/uploader/content_type_blacklist_spec.rb +0 -61
  176. data/vendor/carrierwave/spec/uploader/content_type_whitelist_spec.rb +0 -63
  177. data/vendor/carrierwave/spec/uploader/default_url_spec.rb +0 -77
  178. data/vendor/carrierwave/spec/uploader/download_spec.rb +0 -204
  179. data/vendor/carrierwave/spec/uploader/extension_blacklist_spec.rb +0 -112
  180. data/vendor/carrierwave/spec/uploader/extension_whitelist_spec.rb +0 -102
  181. data/vendor/carrierwave/spec/uploader/file_size_spec.rb +0 -52
  182. data/vendor/carrierwave/spec/uploader/mountable_spec.rb +0 -26
  183. data/vendor/carrierwave/spec/uploader/overrides_spec.rb +0 -71
  184. data/vendor/carrierwave/spec/uploader/paths_spec.rb +0 -18
  185. data/vendor/carrierwave/spec/uploader/processing_spec.rb +0 -159
  186. data/vendor/carrierwave/spec/uploader/proxy_spec.rb +0 -79
  187. data/vendor/carrierwave/spec/uploader/remove_spec.rb +0 -71
  188. data/vendor/carrierwave/spec/uploader/store_spec.rb +0 -400
  189. data/vendor/carrierwave/spec/uploader/url_spec.rb +0 -273
  190. data/vendor/carrierwave/spec/uploader/versions_spec.rb +0 -633
@@ -1,379 +0,0 @@
1
- module CarrierWave
2
-
3
- ##
4
- # This module simplifies manipulation with RMagick 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/rmagick'
9
- #
10
- # And then include it in your uploader:
11
- #
12
- # class MyUploader < CarrierWave::Uploader::Base
13
- # include CarrierWave::RMagick
14
- # end
15
- #
16
- # You can now use the provided helpers:
17
- #
18
- # class MyUploader < CarrierWave::Uploader::Base
19
- # include CarrierWave::RMagick
20
- #
21
- # process :resize_to_fit => [200, 200]
22
- # end
23
- #
24
- # Or create your own helpers with the powerful manipulate! method. Check
25
- # out the RMagick docs at http://www.imagemagick.org/RMagick/doc/ for more
26
- # info
27
- #
28
- # class MyUploader < CarrierWave::Uploader::Base
29
- # include CarrierWave::RMagick
30
- #
31
- # process :do_stuff => 10.0
32
- #
33
- # def do_stuff(blur_factor)
34
- # manipulate! do |img|
35
- # img = img.sepiatone
36
- # img = img.auto_orient
37
- # img = img.radial_blur(blur_factor)
38
- # end
39
- # end
40
- # end
41
- #
42
- # === Note
43
- #
44
- # You should be aware how RMagick handles memory. manipulate! takes care
45
- # of freeing up memory for you, but for optimum memory usage you should
46
- # use destructive operations as much as possible:
47
- #
48
- # DON'T DO THIS:
49
- # img = img.resize_to_fit
50
- #
51
- # DO THIS INSTEAD:
52
- # img.resize_to_fit!
53
- #
54
- # Read this for more information why:
55
- #
56
- # http://rubyforge.org/forum/forum.php?thread_id=1374&forum_id=1618
57
- #
58
- module RMagick
59
- extend ActiveSupport::Concern
60
-
61
- included do
62
- begin
63
- require "rmagick"
64
- rescue LoadError
65
- require "RMagick"
66
- rescue LoadError => e
67
- e.message << " (You may need to install the rmagick gem)"
68
- raise e
69
- end
70
- end
71
-
72
- module ClassMethods
73
- def convert(format)
74
- process :convert => format
75
- end
76
-
77
- def resize_to_limit(width, height)
78
- process :resize_to_limit => [width, height]
79
- end
80
-
81
- def resize_to_fit(width, height)
82
- process :resize_to_fit => [width, height]
83
- end
84
-
85
- def resize_to_fill(width, height, gravity=::Magick::CenterGravity)
86
- process :resize_to_fill => [width, height, gravity]
87
- end
88
-
89
- def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
90
- process :resize_and_pad => [width, height, background, gravity]
91
- end
92
-
93
- def resize_to_geometry_string(geometry_string)
94
- process :resize_to_geometry_string => [geometry_string]
95
- end
96
- end
97
-
98
- ##
99
- # Changes the image encoding format to the given format
100
- #
101
- # See even http://www.imagemagick.org/RMagick/doc/magick.html#formats
102
- #
103
- # === Parameters
104
- #
105
- # [format (#to_s)] an abreviation of the format
106
- #
107
- # === Yields
108
- #
109
- # [Magick::Image] additional manipulations to perform
110
- #
111
- # === Examples
112
- #
113
- # image.convert(:png)
114
- #
115
- def convert(format)
116
- manipulate!(:format => format)
117
- @format = format
118
- end
119
-
120
- ##
121
- # Resize the image to fit within the specified dimensions while retaining
122
- # the original aspect ratio. Will only resize the image if it is larger than the
123
- # specified dimensions. The resulting image may be shorter or narrower than specified
124
- # in the smaller dimension but will not be larger than the specified values.
125
- #
126
- # === Parameters
127
- #
128
- # [width (Integer)] the width to scale the image to
129
- # [height (Integer)] the height to scale the image to
130
- #
131
- # === Yields
132
- #
133
- # [Magick::Image] additional manipulations to perform
134
- #
135
- def resize_to_limit(width, height)
136
- manipulate! do |img|
137
- geometry = Magick::Geometry.new(width, height, 0, 0, Magick::GreaterGeometry)
138
- new_img = img.change_geometry(geometry) do |new_width, new_height|
139
- img.resize(new_width, new_height)
140
- end
141
- destroy_image(img)
142
- new_img = yield(new_img) if block_given?
143
- new_img
144
- end
145
- end
146
-
147
- ##
148
- # From the RMagick documentation: "Resize the image to fit within the
149
- # specified dimensions while retaining the original aspect ratio. The
150
- # image may be shorter or narrower than specified in the smaller dimension
151
- # but will not be larger than the specified values."
152
- #
153
- # See even http://www.imagemagick.org/RMagick/doc/image3.html#resize_to_fit
154
- #
155
- # === Parameters
156
- #
157
- # [width (Integer)] the width to scale the image to
158
- # [height (Integer)] the height to scale the image to
159
- #
160
- # === Yields
161
- #
162
- # [Magick::Image] additional manipulations to perform
163
- #
164
- def resize_to_fit(width, height)
165
- manipulate! do |img|
166
- img.resize_to_fit!(width, height)
167
- img = yield(img) if block_given?
168
- img
169
- end
170
- end
171
-
172
- ##
173
- # From the RMagick documentation: "Resize the image to fit within the
174
- # specified dimensions while retaining the aspect ratio of the original
175
- # image. If necessary, crop the image in the larger dimension."
176
- #
177
- # See even http://www.imagemagick.org/RMagick/doc/image3.html#resize_to_fill
178
- #
179
- # === Parameters
180
- #
181
- # [width (Integer)] the width to scale the image to
182
- # [height (Integer)] the height to scale the image to
183
- #
184
- # === Yields
185
- #
186
- # [Magick::Image] additional manipulations to perform
187
- #
188
- def resize_to_fill(width, height, gravity=::Magick::CenterGravity)
189
- manipulate! do |img|
190
- img.crop_resized!(width, height, gravity)
191
- img = yield(img) if block_given?
192
- img
193
- end
194
- end
195
-
196
- ##
197
- # Resize the image to fit within the specified dimensions while retaining
198
- # the original aspect ratio. If necessary, will pad the remaining area
199
- # with the given color, which defaults to transparent (for gif and png,
200
- # white for jpeg).
201
- #
202
- # === Parameters
203
- #
204
- # [width (Integer)] the width to scale the image to
205
- # [height (Integer)] the height to scale the image to
206
- # [background (String, :transparent)] the color of the background as a hexcode, like "#ff45de"
207
- # [gravity (Magick::GravityType)] how to position the image
208
- #
209
- # === Yields
210
- #
211
- # [Magick::Image] additional manipulations to perform
212
- #
213
- def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
214
- manipulate! do |img|
215
- img.resize_to_fit!(width, height)
216
- new_img = ::Magick::Image.new(width, height) { self.background_color = background == :transparent ? 'rgba(255,255,255,0)' : background.to_s }
217
- if background == :transparent
218
- filled = new_img.matte_floodfill(1, 1)
219
- else
220
- filled = new_img.color_floodfill(1, 1, ::Magick::Pixel.from_color(background))
221
- end
222
- destroy_image(new_img)
223
- filled.composite!(img, gravity, ::Magick::OverCompositeOp)
224
- destroy_image(img)
225
- filled = yield(filled) if block_given?
226
- filled
227
- end
228
- end
229
-
230
- ##
231
- # Resize the image per the provided geometry string.
232
- #
233
- # === Parameters
234
- #
235
- # [geometry_string (String)] the proportions in which to scale image
236
- #
237
- # === Yields
238
- #
239
- # [Magick::Image] additional manipulations to perform
240
- #
241
- def resize_to_geometry_string(geometry_string)
242
- manipulate! do |img|
243
- new_img = img.change_geometry(geometry_string) do |new_width, new_height|
244
- img.resize(new_width, new_height)
245
- end
246
- destroy_image(img)
247
- new_img = yield(new_img) if block_given?
248
- new_img
249
- end
250
- end
251
-
252
- ##
253
- # Returns the width of the image.
254
- #
255
- # === Returns
256
- #
257
- # [Integer] the image's width in pixels
258
- #
259
- def width
260
- rmagick_image.columns
261
- end
262
-
263
- ##
264
- # Returns the height of the image.
265
- #
266
- # === Returns
267
- #
268
- # [Integer] the image's height in pixels
269
- #
270
- def height
271
- rmagick_image.rows
272
- end
273
-
274
- ##
275
- # Manipulate the image with RMagick. This method will load up an image
276
- # and then pass each of its frames to the supplied block. It will then
277
- # save the image to disk.
278
- #
279
- # === Gotcha
280
- #
281
- # This method assumes that the object responds to +current_path+.
282
- # Any class that this module is mixed into must have a +current_path+ method.
283
- # CarrierWave::Uploader does, so you won't need to worry about this in
284
- # most cases.
285
- #
286
- # === Yields
287
- #
288
- # [Magick::Image] manipulations to perform
289
- # [Integer] Frame index if the image contains multiple frames
290
- # [Hash] options, see below
291
- #
292
- # === Options
293
- #
294
- # The options argument to this method is also yielded as the third
295
- # block argument.
296
- #
297
- # Currently, the following options are defined:
298
- #
299
- # ==== :write
300
- # A hash of assignments to be evaluated in the block given to the RMagick write call.
301
- #
302
- # An example:
303
- #
304
- # manipulate! do |img, index, options|
305
- # options[:write] = {
306
- # :quality => 50,
307
- # :depth => 8
308
- # }
309
- # img
310
- # end
311
- #
312
- # This will translate to the following RMagick::Image#write call:
313
- #
314
- # image.write do |img|
315
- # self.quality = 50
316
- # self.depth = 8
317
- # end
318
- #
319
- # ==== :read
320
- # A hash of assignments to be given to the RMagick read call.
321
- #
322
- # The options available are identical to those for write, but are passed in directly, like this:
323
- #
324
- # manipulate! :read => { :density => 300 }
325
- #
326
- # ==== :format
327
- # Specify the output format. If unset, the filename extension is used to determine the format.
328
- #
329
- # === Raises
330
- #
331
- # [CarrierWave::ProcessingError] if manipulation failed.
332
- #
333
- def manipulate!(options={}, &block)
334
- cache_stored_file! if !cached?
335
-
336
- read_block = create_info_block(options[:read])
337
- image = ::Magick::Image.read(current_path, &read_block)
338
- frames = ::Magick::ImageList.new
339
-
340
- image.each_with_index do |frame, index|
341
- frame = yield *[frame, index, options].take(block.arity) if block_given?
342
- frames << frame if frame
343
- end
344
- frames.append(true) if block_given?
345
-
346
- write_block = create_info_block(options[:write])
347
-
348
- if options[:format] || @format
349
- frames.write("#{options[:format] || @format}:#{current_path}", &write_block)
350
- move_to = current_path.chomp(File.extname(current_path)) + ".#{options[:format] || @format}"
351
- file.move_to(move_to, permissions, directory_permissions)
352
- else
353
- frames.write(current_path, &write_block)
354
- end
355
-
356
- destroy_image(frames)
357
- rescue ::Magick::ImageMagickError => e
358
- raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.rmagick_processing_error", :e => e, :default => I18n.translate(:"errors.messages.rmagick_processing_error", :e => e, :locale => :en))
359
- end
360
-
361
- private
362
-
363
- def create_info_block(options)
364
- return nil unless options
365
- assignments = options.map { |k, v| "self.#{k} = #{v}" }
366
- code = "lambda { |img| " + assignments.join(";") + "}"
367
- eval code
368
- end
369
-
370
- def destroy_image(image)
371
- image.try(:destroy!)
372
- end
373
-
374
- def rmagick_image
375
- ::Magick::Image.read(current_path).first
376
- end
377
-
378
- end # RMagick
379
- end # CarrierWave
@@ -1,348 +0,0 @@
1
- require 'pathname'
2
- require 'active_support/core_ext/string/multibyte'
3
-
4
- begin
5
- # Use mime/types/columnar if available, for reduced memory usage
6
- require 'mime/types/columnar'
7
- rescue LoadError
8
- require 'mime/types'
9
- end
10
-
11
- module CarrierWave
12
-
13
- ##
14
- # SanitizedFile is a base class which provides a common API around all
15
- # the different quirky Ruby File libraries. It has support for Tempfile,
16
- # File, StringIO, Merb-style upload Hashes, as well as paths given as
17
- # Strings and Pathnames.
18
- #
19
- # It's probably needlessly comprehensive and complex. Help is appreciated.
20
- #
21
- class SanitizedFile
22
-
23
- attr_accessor :file
24
-
25
- class << self
26
- attr_writer :sanitize_regexp
27
-
28
- def sanitize_regexp
29
- @sanitize_regexp ||= /[^[:word:]\.\-\+]/
30
- end
31
- end
32
-
33
- def initialize(file)
34
- self.file = file
35
- end
36
-
37
- ##
38
- # Returns the filename as is, without sanitizing it.
39
- #
40
- # === Returns
41
- #
42
- # [String] the unsanitized filename
43
- #
44
- def original_filename
45
- return @original_filename if @original_filename
46
- if @file and @file.respond_to?(:original_filename)
47
- @file.original_filename
48
- elsif path
49
- File.basename(path)
50
- end
51
- end
52
-
53
- ##
54
- # Returns the filename, sanitized to strip out any evil characters.
55
- #
56
- # === Returns
57
- #
58
- # [String] the sanitized filename
59
- #
60
- def filename
61
- sanitize(original_filename) if original_filename
62
- end
63
-
64
- alias_method :identifier, :filename
65
-
66
- ##
67
- # Returns the part of the filename before the extension. So if a file is called 'test.jpeg'
68
- # this would return 'test'
69
- #
70
- # === Returns
71
- #
72
- # [String] the first part of the filename
73
- #
74
- def basename
75
- split_extension(filename)[0] if filename
76
- end
77
-
78
- ##
79
- # Returns the file extension
80
- #
81
- # === Returns
82
- #
83
- # [String] the extension
84
- #
85
- def extension
86
- split_extension(filename)[1] if filename
87
- end
88
-
89
- ##
90
- # Returns the file's size.
91
- #
92
- # === Returns
93
- #
94
- # [Integer] the file's size in bytes.
95
- #
96
- def size
97
- if is_path?
98
- exists? ? File.size(path) : 0
99
- elsif @file.respond_to?(:size)
100
- @file.size
101
- elsif path
102
- exists? ? File.size(path) : 0
103
- else
104
- 0
105
- end
106
- end
107
-
108
- ##
109
- # Returns the full path to the file. If the file has no path, it will return nil.
110
- #
111
- # === Returns
112
- #
113
- # [String, nil] the path where the file is located.
114
- #
115
- def path
116
- unless @file.blank?
117
- if is_path?
118
- File.expand_path(@file)
119
- elsif @file.respond_to?(:path) and not @file.path.blank?
120
- File.expand_path(@file.path)
121
- end
122
- end
123
- end
124
-
125
- ##
126
- # === Returns
127
- #
128
- # [Boolean] whether the file is supplied as a pathname or string.
129
- #
130
- def is_path?
131
- !!((@file.is_a?(String) || @file.is_a?(Pathname)) && !@file.blank?)
132
- end
133
-
134
- ##
135
- # === Returns
136
- #
137
- # [Boolean] whether the file is valid and has a non-zero size
138
- #
139
- def empty?
140
- @file.nil? || self.size.nil? || (self.size.zero? && ! self.exists?)
141
- end
142
-
143
- ##
144
- # === Returns
145
- #
146
- # [Boolean] Whether the file exists
147
- #
148
- def exists?
149
- self.path.present? && File.exist?(self.path)
150
- end
151
-
152
- ##
153
- # Returns the contents of the file.
154
- #
155
- # === Returns
156
- #
157
- # [String] contents of the file
158
- #
159
- def read
160
- if @content
161
- @content
162
- elsif is_path?
163
- File.open(@file, "rb") {|file| file.read}
164
- else
165
- @file.try(:rewind)
166
- @content = @file.read
167
- @file.try(:close) unless @file.try(:closed?)
168
- @content
169
- end
170
- end
171
-
172
- ##
173
- # Moves the file to the given path
174
- #
175
- # === Parameters
176
- #
177
- # [new_path (String)] The path where the file should be moved.
178
- # [permissions (Integer)] permissions to set on the file in its new location.
179
- # [directory_permissions (Integer)] permissions to set on created directories.
180
- #
181
- def move_to(new_path, permissions=nil, directory_permissions=nil, keep_filename=false)
182
- return if self.empty?
183
- new_path = File.expand_path(new_path)
184
-
185
- mkdir!(new_path, directory_permissions)
186
- move!(new_path)
187
- chmod!(new_path, permissions)
188
- if keep_filename
189
- self.file = {:tempfile => new_path, :filename => original_filename}
190
- else
191
- self.file = new_path
192
- end
193
- self
194
- end
195
- ##
196
- # Helper to move file to new path.
197
- #
198
- def move!(new_path)
199
- if exists?
200
- FileUtils.mv(path, new_path) unless new_path == path
201
- else
202
- File.open(new_path, "wb") { |f| f.write(read) }
203
- end
204
- end
205
-
206
- ##
207
- # Creates a copy of this file and moves it to the given path. Returns the copy.
208
- #
209
- # === Parameters
210
- #
211
- # [new_path (String)] The path where the file should be copied to.
212
- # [permissions (Integer)] permissions to set on the copy
213
- # [directory_permissions (Integer)] permissions to set on created directories.
214
- #
215
- # === Returns
216
- #
217
- # @return [CarrierWave::SanitizedFile] the location where the file will be stored.
218
- #
219
- def copy_to(new_path, permissions=nil, directory_permissions=nil)
220
- return if self.empty?
221
- new_path = File.expand_path(new_path)
222
-
223
- mkdir!(new_path, directory_permissions)
224
- copy!(new_path)
225
- chmod!(new_path, permissions)
226
- self.class.new({:tempfile => new_path, :content_type => content_type})
227
- end
228
-
229
- ##
230
- # Helper to create copy of file in new path.
231
- #
232
- def copy!(new_path)
233
- if exists?
234
- FileUtils.cp(path, new_path) unless new_path == path
235
- else
236
- File.open(new_path, "wb") { |f| f.write(read) }
237
- end
238
- end
239
-
240
- ##
241
- # Removes the file from the filesystem.
242
- #
243
- def delete
244
- FileUtils.rm(self.path) if exists?
245
- end
246
-
247
- ##
248
- # Returns a File object, or nil if it does not exist.
249
- #
250
- # === Returns
251
- #
252
- # [File] a File object representing the SanitizedFile
253
- #
254
- def to_file
255
- return @file if @file.is_a?(File)
256
- File.open(path, "rb") if exists?
257
- end
258
-
259
- ##
260
- # Returns the content type of the file.
261
- #
262
- # === Returns
263
- #
264
- # [String] the content type of the file
265
- #
266
- def content_type
267
- return @content_type if @content_type
268
- if @file.respond_to?(:content_type) and @file.content_type
269
- @content_type = @file.content_type.to_s.chomp
270
- elsif path
271
- @content_type = ::MIME::Types.type_for(path).first.to_s
272
- end
273
- end
274
-
275
- ##
276
- # Sets the content type of the file.
277
- #
278
- # === Returns
279
- #
280
- # [String] the content type of the file
281
- #
282
- def content_type=(type)
283
- @content_type = type
284
- end
285
-
286
- ##
287
- # Used to sanitize the file name. Public to allow overriding for non-latin characters.
288
- #
289
- # === Returns
290
- #
291
- # [Regexp] the regexp for sanitizing the file name
292
- #
293
- def sanitize_regexp
294
- CarrierWave::SanitizedFile.sanitize_regexp
295
- end
296
-
297
- private
298
-
299
- def file=(file)
300
- if file.is_a?(Hash)
301
- @file = file["tempfile"] || file[:tempfile]
302
- @original_filename = file["filename"] || file[:filename]
303
- @content_type = file["content_type"] || file[:content_type] || file["type"] || file[:type]
304
- else
305
- @file = file
306
- @original_filename = nil
307
- @content_type = nil
308
- end
309
- end
310
-
311
- # create the directory if it doesn't exist
312
- def mkdir!(path, directory_permissions)
313
- options = {}
314
- options[:mode] = directory_permissions if directory_permissions
315
- FileUtils.mkdir_p(File.dirname(path), options) unless File.exist?(File.dirname(path))
316
- end
317
-
318
- def chmod!(path, permissions)
319
- File.chmod(permissions, path) if permissions
320
- end
321
-
322
- # Sanitize the filename, to prevent hacking
323
- def sanitize(name)
324
- name = name.tr("\\", "/") # work-around for IE
325
- name = File.basename(name)
326
- name = name.gsub(sanitize_regexp,"_")
327
- name = "_#{name}" if name =~ /\A\.+\z/
328
- name = "unnamed" if name.size == 0
329
- return name.mb_chars.to_s
330
- end
331
-
332
- def split_extension(filename)
333
- # regular expressions to try for identifying extensions
334
- extension_matchers = [
335
- /\A(.+)\.(tar\.([glx]?z|bz2))\z/, # matches "something.tar.gz"
336
- /\A(.+)\.([^\.]+)\z/ # matches "something.jpg"
337
- ]
338
-
339
- extension_matchers.each do |regexp|
340
- if filename =~ regexp
341
- return $1, $2
342
- end
343
- end
344
- return filename, "" # In case we weren't able to split the extension
345
- end
346
-
347
- end # SanitizedFile
348
- end # CarrierWave