jswanner-carrierwave 0.5.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/README.rdoc +553 -0
  2. data/lib/carrierwave.rb +101 -0
  3. data/lib/carrierwave/compatibility/paperclip.rb +95 -0
  4. data/lib/carrierwave/mount.rb +359 -0
  5. data/lib/carrierwave/orm/activerecord.rb +79 -0
  6. data/lib/carrierwave/orm/datamapper.rb +37 -0
  7. data/lib/carrierwave/orm/mongoid.rb +23 -0
  8. data/lib/carrierwave/orm/sequel.rb +45 -0
  9. data/lib/carrierwave/processing/image_science.rb +116 -0
  10. data/lib/carrierwave/processing/mini_magick.rb +261 -0
  11. data/lib/carrierwave/processing/rmagick.rb +278 -0
  12. data/lib/carrierwave/sanitized_file.rb +273 -0
  13. data/lib/carrierwave/storage/abstract.rb +30 -0
  14. data/lib/carrierwave/storage/cloud_files.rb +168 -0
  15. data/lib/carrierwave/storage/file.rb +48 -0
  16. data/lib/carrierwave/storage/grid_fs.rb +108 -0
  17. data/lib/carrierwave/storage/right_s3.rb +3 -0
  18. data/lib/carrierwave/storage/s3.rb +206 -0
  19. data/lib/carrierwave/test/matchers.rb +164 -0
  20. data/lib/carrierwave/uploader.rb +44 -0
  21. data/lib/carrierwave/uploader/cache.rb +146 -0
  22. data/lib/carrierwave/uploader/callbacks.rb +41 -0
  23. data/lib/carrierwave/uploader/configuration.rb +135 -0
  24. data/lib/carrierwave/uploader/default_url.rb +19 -0
  25. data/lib/carrierwave/uploader/download.rb +75 -0
  26. data/lib/carrierwave/uploader/extension_whitelist.rb +38 -0
  27. data/lib/carrierwave/uploader/mountable.rb +39 -0
  28. data/lib/carrierwave/uploader/processing.rb +85 -0
  29. data/lib/carrierwave/uploader/proxy.rb +62 -0
  30. data/lib/carrierwave/uploader/remove.rb +23 -0
  31. data/lib/carrierwave/uploader/store.rb +90 -0
  32. data/lib/carrierwave/uploader/url.rb +33 -0
  33. data/lib/carrierwave/uploader/versions.rb +157 -0
  34. data/lib/generators/templates/uploader.rb +47 -0
  35. data/lib/generators/uploader_generator.rb +13 -0
  36. metadata +374 -0
@@ -0,0 +1,157 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Versions
6
+ extend ActiveSupport::Concern
7
+
8
+ include CarrierWave::Uploader::Callbacks
9
+
10
+ included do
11
+ after :cache, :cache_versions!
12
+ after :store, :store_versions!
13
+ after :remove, :remove_versions!
14
+ after :retrieve_from_cache, :retrieve_versions_from_cache!
15
+ after :retrieve_from_store, :retrieve_versions_from_store!
16
+ end
17
+
18
+ module ClassMethods
19
+
20
+ def version_names
21
+ @version_names ||= []
22
+ end
23
+
24
+ ##
25
+ # Adds a new version to this uploader
26
+ #
27
+ # === Parameters
28
+ #
29
+ # [name (#to_sym)] name of the version
30
+ # [&block (Proc)] a block to eval on this version of the uploader
31
+ #
32
+ def version(name, &block)
33
+ name = name.to_sym
34
+ unless versions[name]
35
+ versions[name] = Class.new(self)
36
+ versions[name].version_names.push(*version_names)
37
+ versions[name].version_names.push(name)
38
+ class_eval <<-RUBY
39
+ def #{name}
40
+ versions[:#{name}]
41
+ end
42
+ RUBY
43
+ end
44
+ versions[name].class_eval(&block) if block
45
+ versions[name]
46
+ end
47
+
48
+ ##
49
+ # === Returns
50
+ #
51
+ # [Hash{Symbol => Class}] a list of versions available for this uploader
52
+ #
53
+ def versions
54
+ @versions ||= {}
55
+ end
56
+
57
+ end # ClassMethods
58
+
59
+ ##
60
+ # Returns a hash mapping the name of each version of the uploader to an instance of it
61
+ #
62
+ # === Returns
63
+ #
64
+ # [Hash{Symbol => CarrierWave::Uploader}] a list of uploader instances
65
+ #
66
+ def versions
67
+ return @versions if @versions
68
+ @versions = {}
69
+ self.class.versions.each do |name, klass|
70
+ @versions[name] = klass.new(model, mounted_as)
71
+ end
72
+ @versions
73
+ end
74
+
75
+ ##
76
+ # === Returns
77
+ #
78
+ # [String] the name of this version of the uploader
79
+ #
80
+ def version_name
81
+ self.class.version_names.join('_').to_sym unless self.class.version_names.blank?
82
+ end
83
+
84
+ ##
85
+ # When given a version name as a parameter, will return the url for that version
86
+ # This also works with nested versions.
87
+ #
88
+ # === Example
89
+ #
90
+ # my_uploader.url # => /path/to/my/uploader.gif
91
+ # my_uploader.url(:thumb) # => /path/to/my/thumb_uploader.gif
92
+ # my_uploader.url(:thumb, :small) # => /path/to/my/thumb_small_uploader.gif
93
+ #
94
+ # === Parameters
95
+ #
96
+ # [*args (Symbol)] any number of versions
97
+ #
98
+ # === Returns
99
+ #
100
+ # [String] the location where this file is accessible via a url
101
+ #
102
+ def url(*args)
103
+ if(args.first)
104
+ raise ArgumentError, "Version #{args.first} doesn't exist!" if versions[args.first.to_sym].nil?
105
+ # recursively proxy to version
106
+ versions[args.first.to_sym].url(*args[1..-1])
107
+ else
108
+ super()
109
+ end
110
+ end
111
+
112
+ ##
113
+ # Recreate versions and reprocess them. This can be used to recreate
114
+ # versions if their parameters somehow have changed.
115
+ #
116
+ def recreate_versions!
117
+ with_callbacks(:recreate_versions, file) do
118
+ versions.each { |name, v| v.store!(file) }
119
+ end
120
+ end
121
+
122
+ private
123
+
124
+ def full_filename(for_file)
125
+ [version_name, super(for_file)].compact.join('_')
126
+ end
127
+
128
+ def full_original_filename
129
+ [version_name, super].compact.join('_')
130
+ end
131
+
132
+ def cache_versions!(new_file)
133
+ versions.each do |name, v|
134
+ v.send(:cache_id=, cache_id)
135
+ v.cache!(new_file)
136
+ end
137
+ end
138
+
139
+ def store_versions!(new_file)
140
+ versions.each { |name, v| v.store!(new_file) }
141
+ end
142
+
143
+ def remove_versions!
144
+ versions.each { |name, v| v.remove! }
145
+ end
146
+
147
+ def retrieve_versions_from_cache!(cache_name)
148
+ versions.each { |name, v| v.retrieve_from_cache!(cache_name) }
149
+ end
150
+
151
+ def retrieve_versions_from_store!(identifier)
152
+ versions.each { |name, v| v.retrieve_from_store!(identifier) }
153
+ end
154
+
155
+ end # Versions
156
+ end # Uploader
157
+ end # CarrierWave
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
4
+
5
+ # Include RMagick or ImageScience support
6
+ # include CarrierWave::RMagick
7
+ # include CarrierWave::ImageScience
8
+
9
+ # Choose what kind of storage to use for this uploader
10
+ storage :file
11
+ # storage :s3
12
+
13
+ # Override the directory where uploaded files will be stored
14
+ # This is a sensible default for uploaders that are meant to be mounted:
15
+ def store_dir
16
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
17
+ end
18
+
19
+ # Provide a default URL as a default if there hasn't been a file uploaded
20
+ # def default_url
21
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
22
+ # end
23
+
24
+ # Process files as they are uploaded.
25
+ # process :scale => [200, 300]
26
+ #
27
+ # def scale(width, height)
28
+ # # do something
29
+ # end
30
+
31
+ # Create different versions of your uploaded files
32
+ # version :thumb do
33
+ # process :scale => [50, 50]
34
+ # end
35
+
36
+ # Add a white list of extensions which are allowed to be uploaded,
37
+ # for images you might use something like this:
38
+ # def extension_white_list
39
+ # %w(jpg jpeg gif png)
40
+ # end
41
+
42
+ # Override the filename of the uploaded files
43
+ # def filename
44
+ # "something.jpg" if original_filename
45
+ # end
46
+
47
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/named_base'
3
+
4
+ class UploaderGenerator < Rails::Generators::NamedBase
5
+ def create_uploader_file
6
+ template 'uploader.rb', File.join('app/uploaders', class_path, "#{file_name}.rb")
7
+ end
8
+
9
+ def self.source_root
10
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
11
+ end
12
+ end
13
+
metadata ADDED
@@ -0,0 +1,374 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jswanner-carrierwave
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 0
9
+ - beta3
10
+ version: 0.5.0.beta3
11
+ platform: ruby
12
+ authors:
13
+ - Jonas Nicklas
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-28 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 0
33
+ - beta4
34
+ version: 3.0.0.beta4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rails
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 3
47
+ - 0
48
+ - 0
49
+ - beta4
50
+ version: 3.0.0.beta4
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - <=
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 2
63
+ - 0
64
+ - 0
65
+ version: 2.0.0
66
+ type: :development
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: aws
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: cucumber
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ type: :development
93
+ version_requirements: *id005
94
+ - !ruby/object:Gem::Dependency
95
+ name: sqlite3-ruby
96
+ prerelease: false
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ type: :development
106
+ version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: dm-core
109
+ prerelease: false
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ type: :development
119
+ version_requirements: *id007
120
+ - !ruby/object:Gem::Dependency
121
+ name: dm-validations
122
+ prerelease: false
123
+ requirement: &id008 !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ type: :development
132
+ version_requirements: *id008
133
+ - !ruby/object:Gem::Dependency
134
+ name: dm-migrations
135
+ prerelease: false
136
+ requirement: &id009 !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ type: :development
145
+ version_requirements: *id009
146
+ - !ruby/object:Gem::Dependency
147
+ name: dm-sqlite-adapter
148
+ prerelease: false
149
+ requirement: &id010 !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ segments:
155
+ - 0
156
+ version: "0"
157
+ type: :development
158
+ version_requirements: *id010
159
+ - !ruby/object:Gem::Dependency
160
+ name: sequel
161
+ prerelease: false
162
+ requirement: &id011 !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ segments:
168
+ - 0
169
+ version: "0"
170
+ type: :development
171
+ version_requirements: *id011
172
+ - !ruby/object:Gem::Dependency
173
+ name: rmagick
174
+ prerelease: false
175
+ requirement: &id012 !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ segments:
181
+ - 0
182
+ version: "0"
183
+ type: :development
184
+ version_requirements: *id012
185
+ - !ruby/object:Gem::Dependency
186
+ name: RubyInline
187
+ prerelease: false
188
+ requirement: &id013 !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ segments:
194
+ - 0
195
+ version: "0"
196
+ type: :development
197
+ version_requirements: *id013
198
+ - !ruby/object:Gem::Dependency
199
+ name: image_science
200
+ prerelease: false
201
+ requirement: &id014 !ruby/object:Gem::Requirement
202
+ none: false
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ segments:
207
+ - 0
208
+ version: "0"
209
+ type: :development
210
+ version_requirements: *id014
211
+ - !ruby/object:Gem::Dependency
212
+ name: mini_magick
213
+ prerelease: false
214
+ requirement: &id015 !ruby/object:Gem::Requirement
215
+ none: false
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ segments:
220
+ - 0
221
+ version: "0"
222
+ type: :development
223
+ version_requirements: *id015
224
+ - !ruby/object:Gem::Dependency
225
+ name: mongoid
226
+ prerelease: false
227
+ requirement: &id016 !ruby/object:Gem::Requirement
228
+ none: false
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ segments:
233
+ - 2
234
+ - 0
235
+ - 0
236
+ - beta
237
+ - 6
238
+ version: 2.0.0.beta.6
239
+ type: :development
240
+ version_requirements: *id016
241
+ - !ruby/object:Gem::Dependency
242
+ name: bson_ext
243
+ prerelease: false
244
+ requirement: &id017 !ruby/object:Gem::Requirement
245
+ none: false
246
+ requirements:
247
+ - - ">="
248
+ - !ruby/object:Gem::Version
249
+ segments:
250
+ - 0
251
+ version: "0"
252
+ type: :development
253
+ version_requirements: *id017
254
+ - !ruby/object:Gem::Dependency
255
+ name: aws-s3
256
+ prerelease: false
257
+ requirement: &id018 !ruby/object:Gem::Requirement
258
+ none: false
259
+ requirements:
260
+ - - ">="
261
+ - !ruby/object:Gem::Version
262
+ segments:
263
+ - 0
264
+ version: "0"
265
+ type: :development
266
+ version_requirements: *id018
267
+ - !ruby/object:Gem::Dependency
268
+ name: timecop
269
+ prerelease: false
270
+ requirement: &id019 !ruby/object:Gem::Requirement
271
+ none: false
272
+ requirements:
273
+ - - ">="
274
+ - !ruby/object:Gem::Version
275
+ segments:
276
+ - 0
277
+ version: "0"
278
+ type: :development
279
+ version_requirements: *id019
280
+ - !ruby/object:Gem::Dependency
281
+ name: json
282
+ prerelease: false
283
+ requirement: &id020 !ruby/object:Gem::Requirement
284
+ none: false
285
+ requirements:
286
+ - - ">="
287
+ - !ruby/object:Gem::Version
288
+ segments:
289
+ - 0
290
+ version: "0"
291
+ type: :development
292
+ version_requirements: *id020
293
+ description: Upload files in your Ruby applications, map them to a range of ORMs, store them on different backends.
294
+ email:
295
+ - jonas.nicklas@gmail.com
296
+ executables: []
297
+
298
+ extensions: []
299
+
300
+ extra_rdoc_files:
301
+ - README.rdoc
302
+ files:
303
+ - lib/carrierwave/compatibility/paperclip.rb
304
+ - lib/carrierwave/mount.rb
305
+ - lib/carrierwave/orm/activerecord.rb
306
+ - lib/carrierwave/orm/datamapper.rb
307
+ - lib/carrierwave/orm/mongoid.rb
308
+ - lib/carrierwave/orm/sequel.rb
309
+ - lib/carrierwave/processing/image_science.rb
310
+ - lib/carrierwave/processing/mini_magick.rb
311
+ - lib/carrierwave/processing/rmagick.rb
312
+ - lib/carrierwave/sanitized_file.rb
313
+ - lib/carrierwave/storage/abstract.rb
314
+ - lib/carrierwave/storage/cloud_files.rb
315
+ - lib/carrierwave/storage/file.rb
316
+ - lib/carrierwave/storage/grid_fs.rb
317
+ - lib/carrierwave/storage/right_s3.rb
318
+ - lib/carrierwave/storage/s3.rb
319
+ - lib/carrierwave/test/matchers.rb
320
+ - lib/carrierwave/uploader/cache.rb
321
+ - lib/carrierwave/uploader/callbacks.rb
322
+ - lib/carrierwave/uploader/configuration.rb
323
+ - lib/carrierwave/uploader/default_url.rb
324
+ - lib/carrierwave/uploader/download.rb
325
+ - lib/carrierwave/uploader/extension_whitelist.rb
326
+ - lib/carrierwave/uploader/mountable.rb
327
+ - lib/carrierwave/uploader/processing.rb
328
+ - lib/carrierwave/uploader/proxy.rb
329
+ - lib/carrierwave/uploader/remove.rb
330
+ - lib/carrierwave/uploader/store.rb
331
+ - lib/carrierwave/uploader/url.rb
332
+ - lib/carrierwave/uploader/versions.rb
333
+ - lib/carrierwave/uploader.rb
334
+ - lib/carrierwave.rb
335
+ - lib/generators/templates/uploader.rb
336
+ - lib/generators/uploader_generator.rb
337
+ - README.rdoc
338
+ has_rdoc: true
339
+ homepage: http://carrierwave.rubyforge.org
340
+ licenses: []
341
+
342
+ post_install_message:
343
+ rdoc_options:
344
+ - --main
345
+ - README.rdoc
346
+ require_paths:
347
+ - lib
348
+ required_ruby_version: !ruby/object:Gem::Requirement
349
+ none: false
350
+ requirements:
351
+ - - ">="
352
+ - !ruby/object:Gem::Version
353
+ segments:
354
+ - 0
355
+ version: "0"
356
+ required_rubygems_version: !ruby/object:Gem::Requirement
357
+ none: false
358
+ requirements:
359
+ - - ">"
360
+ - !ruby/object:Gem::Version
361
+ segments:
362
+ - 1
363
+ - 3
364
+ - 1
365
+ version: 1.3.1
366
+ requirements: []
367
+
368
+ rubyforge_project: carrierwave
369
+ rubygems_version: 1.3.7
370
+ signing_key:
371
+ specification_version: 3
372
+ summary: Ruby file upload library
373
+ test_files: []
374
+