jmcnevin-paperclip 2.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/LICENSE +26 -0
  2. data/README.md +414 -0
  3. data/Rakefile +86 -0
  4. data/generators/paperclip/USAGE +5 -0
  5. data/generators/paperclip/paperclip_generator.rb +27 -0
  6. data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  7. data/init.rb +4 -0
  8. data/lib/generators/paperclip/USAGE +8 -0
  9. data/lib/generators/paperclip/paperclip_generator.rb +33 -0
  10. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  11. data/lib/paperclip.rb +480 -0
  12. data/lib/paperclip/attachment.rb +520 -0
  13. data/lib/paperclip/callback_compatibility.rb +61 -0
  14. data/lib/paperclip/geometry.rb +155 -0
  15. data/lib/paperclip/interpolations.rb +171 -0
  16. data/lib/paperclip/iostream.rb +45 -0
  17. data/lib/paperclip/matchers.rb +33 -0
  18. data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  19. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
  20. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  21. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  22. data/lib/paperclip/missing_attachment_styles.rb +87 -0
  23. data/lib/paperclip/options.rb +78 -0
  24. data/lib/paperclip/processor.rb +58 -0
  25. data/lib/paperclip/railtie.rb +26 -0
  26. data/lib/paperclip/storage.rb +3 -0
  27. data/lib/paperclip/storage/filesystem.rb +81 -0
  28. data/lib/paperclip/storage/fog.rb +163 -0
  29. data/lib/paperclip/storage/s3.rb +270 -0
  30. data/lib/paperclip/style.rb +95 -0
  31. data/lib/paperclip/thumbnail.rb +105 -0
  32. data/lib/paperclip/upfile.rb +62 -0
  33. data/lib/paperclip/version.rb +3 -0
  34. data/lib/tasks/paperclip.rake +101 -0
  35. data/rails/init.rb +2 -0
  36. data/shoulda_macros/paperclip.rb +124 -0
  37. data/test/attachment_test.rb +1161 -0
  38. data/test/database.yml +4 -0
  39. data/test/fixtures/12k.png +0 -0
  40. data/test/fixtures/50x50.png +0 -0
  41. data/test/fixtures/5k.png +0 -0
  42. data/test/fixtures/animated.gif +0 -0
  43. data/test/fixtures/bad.png +1 -0
  44. data/test/fixtures/double spaces in name.png +0 -0
  45. data/test/fixtures/fog.yml +8 -0
  46. data/test/fixtures/s3.yml +8 -0
  47. data/test/fixtures/spaced file.png +0 -0
  48. data/test/fixtures/text.txt +1 -0
  49. data/test/fixtures/twopage.pdf +0 -0
  50. data/test/fixtures/uppercase.PNG +0 -0
  51. data/test/fog_test.rb +192 -0
  52. data/test/geometry_test.rb +206 -0
  53. data/test/helper.rb +158 -0
  54. data/test/integration_test.rb +781 -0
  55. data/test/interpolations_test.rb +202 -0
  56. data/test/iostream_test.rb +71 -0
  57. data/test/matchers/have_attached_file_matcher_test.rb +24 -0
  58. data/test/matchers/validate_attachment_content_type_matcher_test.rb +87 -0
  59. data/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
  60. data/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
  61. data/test/options_test.rb +75 -0
  62. data/test/paperclip_missing_attachment_styles_test.rb +80 -0
  63. data/test/paperclip_test.rb +340 -0
  64. data/test/processor_test.rb +10 -0
  65. data/test/storage/filesystem_test.rb +56 -0
  66. data/test/storage/s3_live_test.rb +88 -0
  67. data/test/storage/s3_test.rb +689 -0
  68. data/test/style_test.rb +180 -0
  69. data/test/thumbnail_test.rb +383 -0
  70. data/test/upfile_test.rb +53 -0
  71. metadata +294 -0
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+
2
+ LICENSE
3
+
4
+ The MIT License
5
+
6
+ Copyright (c) 2008 Jon Yurek and thoughtbot, inc.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+
26
+
@@ -0,0 +1,414 @@
1
+ # Paperclip [![Build Status](https://secure.travis-ci.org/thoughtbot/paperclip.png?branch=master)](http://travis-ci.org/thoughtbot/paperclip)
2
+
3
+ Paperclip is intended as an easy file attachment library for ActiveRecord. The
4
+ intent behind it was to keep setup as easy as possible and to treat files as
5
+ much like other attributes as possible. This means they aren't saved to their
6
+ final locations on disk, nor are they deleted if set to nil, until
7
+ ActiveRecord::Base#save is called. It manages validations based on size and
8
+ presence, if required. It can transform its assigned image into thumbnails if
9
+ needed, and the prerequisites are as simple as installing ImageMagick (which,
10
+ for most modern Unix-based systems, is as easy as installing the right
11
+ packages). Attached files are saved to the filesystem and referenced in the
12
+ browser by an easily understandable specification, which has sensible and
13
+ useful defaults.
14
+
15
+ See the documentation for `has_attached_file` in Paperclip::ClassMethods for
16
+ more detailed options.
17
+
18
+ The complete [RDoc](http://rdoc.info/gems/paperclip) is online.
19
+
20
+ Requirements
21
+ ------------
22
+
23
+ ImageMagick must be installed and Paperclip must have access to it. To ensure
24
+ that it does, on your command line, run `which convert` (one of the ImageMagick
25
+ utilities). This will give you the path where that utility is installed. For
26
+ example, it might return `/usr/local/bin/convert`.
27
+
28
+ Then, in your environment config file, let Paperclip know to look there by adding that
29
+ directory to its path.
30
+
31
+ In development mode, you might add this line to `config/environments/development.rb)`:
32
+
33
+ Paperclip.options[:command_path] = "/usr/local/bin/"
34
+
35
+ If you're on Mac OSX, you'll want to run the following with Homebrew:
36
+
37
+ brew install imagemagick
38
+
39
+ If you are dealing with pdf uploads or running the test suite, also run:
40
+
41
+ brew install gs
42
+
43
+ Installation
44
+ ------------
45
+
46
+ Paperclip is distributed as a gem, which is how it should be used in your app. It's
47
+ technically still installable as a plugin, but that's discouraged, as Rails plays
48
+ well with gems.
49
+
50
+ Include the gem in your Gemfile:
51
+
52
+ gem "paperclip", "~> 2.4"
53
+
54
+ Or, if you don't use Bundler (though you probably should, even in Rails 2), with config.gem
55
+
56
+ # In config/environment.rb
57
+ ...
58
+ Rails::Initializer.run do |config|
59
+ ...
60
+ config.gem "paperclip", :version => "~> 2.4"
61
+ ...
62
+ end
63
+ For Non-Rails usage:
64
+
65
+ class ModuleName < ActiveRecord::Base
66
+ include Paperclip::Glue
67
+ ...
68
+ end
69
+
70
+ Quick Start
71
+ -----------
72
+
73
+ In your model:
74
+
75
+ class User < ActiveRecord::Base
76
+ has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
77
+ end
78
+
79
+ In your migrations:
80
+
81
+ class AddAvatarColumnsToUser < ActiveRecord::Migration
82
+ def self.up
83
+ add_column :users, :avatar_file_name, :string
84
+ add_column :users, :avatar_content_type, :string
85
+ add_column :users, :avatar_file_size, :integer
86
+ add_column :users, :avatar_updated_at, :datetime
87
+ end
88
+
89
+ def self.down
90
+ remove_column :users, :avatar_file_name
91
+ remove_column :users, :avatar_content_type
92
+ remove_column :users, :avatar_file_size
93
+ remove_column :users, :avatar_updated_at
94
+ end
95
+ end
96
+
97
+ In your edit and new views:
98
+
99
+ <%= form_for :user, @user, :url => user_path, :html => { :multipart => true } do |form| %>
100
+ <%= form.file_field :avatar %>
101
+ <% end %>
102
+
103
+ In your controller:
104
+
105
+ def create
106
+ @user = User.create( params[:user] )
107
+ end
108
+
109
+ In your show view:
110
+
111
+ <%= image_tag @user.avatar.url %>
112
+ <%= image_tag @user.avatar.url(:medium) %>
113
+ <%= image_tag @user.avatar.url(:thumb) %>
114
+
115
+ To detach a file, simply set the attribute to `nil`:
116
+
117
+ @user.avatar = nil
118
+ @user.save
119
+
120
+ Usage
121
+ -----
122
+
123
+ The basics of paperclip are quite simple: Declare that your model has an
124
+ attachment with the has_attached_file method, and give it a name. Paperclip
125
+ will wrap up up to four attributes (all prefixed with that attachment's name,
126
+ so you can have multiple attachments per model if you wish) and give them a
127
+ friendly front end. The attributes are `<attachment>_file_name`,
128
+ `<attachment>_file_size`, `<attachment>_content_type`, and `<attachment>_updated_at`.
129
+ Only `<attachment>_file_name` is required for paperclip to operate. More
130
+ information about the options to has_attached_file is available in the
131
+ documentation of Paperclip::ClassMethods.
132
+
133
+ Attachments can be validated with Paperclip's validation methods,
134
+ validates_attachment_presence, validates_attachment_content_type, and
135
+ validates_attachment_size.
136
+
137
+ Storage
138
+ -------
139
+
140
+ The files that are assigned as attachments are, by default, placed in the
141
+ directory specified by the :path option to has_attached_file. By default, this
142
+ location is ":rails_root/public/system/:attachment/:id/:style/:filename". This
143
+ location was chosen because on standard Capistrano deployments, the
144
+ public/system directory is symlinked to the app's shared directory, meaning it
145
+ will survive between deployments. For example, using that :path, you may have a
146
+ file at
147
+
148
+ /data/myapp/releases/20081229172410/public/system/avatars/13/small/my_pic.png
149
+
150
+ _NOTE: This is a change from previous versions of Paperclip, but is overall a
151
+ safer choice for the default file store._
152
+
153
+ You may also choose to store your files using Amazon's S3 service. You can find
154
+ more information about S3 storage at the description for
155
+ Paperclip::Storage::S3.
156
+
157
+ Files on the local filesystem (and in the Rails app's public directory) will be
158
+ available to the internet at large. If you require access control, it's
159
+ possible to place your files in a different location. You will need to change
160
+ both the :path and :url options in order to make sure the files are unavailable
161
+ to the public. Both :path and :url allow the same set of interpolated
162
+ variables.
163
+
164
+ Post Processing
165
+ ---------------
166
+
167
+ Paperclip supports an extensible selection of post-processors. When you define
168
+ a set of styles for an attachment, by default it is expected that those
169
+ "styles" are actually "thumbnails". However, you can do much more than just
170
+ thumbnail images. By defining a subclass of Paperclip::Processor, you can
171
+ perform any processing you want on the files that are attached. Any file in
172
+ your Rails app's lib/paperclip_processors directory is automatically loaded by
173
+ paperclip, allowing you to easily define custom processors. You can specify a
174
+ processor with the :processors option to has_attached_file:
175
+
176
+ has_attached_file :scan, :styles => { :text => { :quality => :better } },
177
+ :processors => [:ocr]
178
+
179
+ This would load the hypothetical class Paperclip::Ocr, which would have the
180
+ hash "{ :quality => :better }" passed to it along with the uploaded file. For
181
+ more information about defining processors, see Paperclip::Processor.
182
+
183
+ The default processor is Paperclip::Thumbnail. For backwards compatability
184
+ reasons, you can pass a single geometry string or an array containing a
185
+ geometry and a format, which the file will be converted to, like so:
186
+
187
+ has_attached_file :avatar, :styles => { :thumb => ["32x32#", :png] }
188
+
189
+ This will convert the "thumb" style to a 32x32 square in png format, regardless
190
+ of what was uploaded. If the format is not specified, it is kept the same (i.e.
191
+ jpgs will remain jpgs).
192
+
193
+ Multiple processors can be specified, and they will be invoked in the order
194
+ they are defined in the :processors array. Each successive processor will
195
+ be given the result of the previous processor's execution. All processors will
196
+ receive the same parameters, which are what you define in the :styles hash.
197
+ For example, assuming we had this definition:
198
+
199
+ has_attached_file :scan, :styles => { :text => { :quality => :better } },
200
+ :processors => [:rotator, :ocr]
201
+
202
+ then both the :rotator processor and the :ocr processor would receive the
203
+ options "{ :quality => :better }". This parameter may not mean anything to one
204
+ or more or the processors, and they are expected to ignore it.
205
+
206
+ _NOTE: Because processors operate by turning the original attachment into the
207
+ styles, no processors will be run if there are no styles defined._
208
+
209
+ If you're interested in caching your thumbnail's width, height and size in the
210
+ database, take a look at the [paperclip-meta](https://github.com/y8/paperclip-meta) gem.
211
+
212
+ Also, if you're interested in generating the thumbnail on-the-fly, you might want
213
+ to look into the [attachment_on_the_fly](https://github.com/drpentode/Attachment-on-the-Fly) gem.
214
+
215
+ Events
216
+ ------
217
+
218
+ Before and after the Post Processing step, Paperclip calls back to the model
219
+ with a few callbacks, allowing the model to change or cancel the processing
220
+ step. The callbacks are `before_post_process` and `after_post_process` (which
221
+ are called before and after the processing of each attachment), and the
222
+ attachment-specific `before_<attachment>_post_process` and
223
+ `after_<attachment>_post_process`. The callbacks are intended to be as close to
224
+ normal ActiveRecord callbacks as possible, so if you return false (specifically
225
+ - returning nil is not the same) in a before_ filter, the post processing step
226
+ will halt. Returning false in an after_ filter will not halt anything, but you
227
+ can access the model and the attachment if necessary.
228
+
229
+ _NOTE: Post processing will not even *start* if the attachment is not valid
230
+ according to the validations. Your callbacks and processors will *only* be
231
+ called with valid attachments._
232
+
233
+ URI Obfuscation
234
+ ---------------
235
+
236
+ Paperclip has an interpolation called `:hash` for obfuscating filenames of
237
+ publicly-available files.
238
+
239
+ Example Usage:
240
+
241
+ has_attached_file :avatar, {
242
+ :url => "/system/:hash.:extension",
243
+ :hash_secret => "longSecretString"
244
+ }
245
+
246
+
247
+ The `:hash` interpolation will be replaced with a unique hash made up of whatever
248
+ is specified in `:hash_data`. The default value for `:hash_data` is `":class/:attachment/:id/:style/:updated_at"`.
249
+
250
+ `:hash_secret` is required, an exception will be raised if `:hash` is used without `:hash_secret` present.
251
+
252
+ For more on this feature read the author's own explanation. [https://github.com/thoughtbot/paperclip/pull/416](https://github.com/thoughtbot/paperclip/pull/416)
253
+
254
+ MD5 Checksum / Fingerprint
255
+ -------
256
+
257
+ A MD5 checksum of the original file assigned will be placed in the model if it
258
+ has an attribute named fingerprint. Following the user model migration example
259
+ above, the migration would look like the following.
260
+
261
+ class AddAvatarFingerprintColumnToUser < ActiveRecord::Migration
262
+ def self.up
263
+ add_column :users, :avatar_fingerprint, :string
264
+ end
265
+
266
+ def self.down
267
+ remove_column :users, :avatar_fingerprint
268
+ end
269
+ end
270
+
271
+ Custom Attachment Processors
272
+ -------
273
+
274
+ Custom attachment processors can be implemented and their only requirement is
275
+ to inherit from `Paperclip::Processor` (see `lib/paperclip/processor.rb`).
276
+ For example, when `:styles` are specified for an image attachment, the
277
+ thumbnail processor (see `lib/paperclip/thumbnail.rb`) is loaded without having
278
+ to specify it as a `:processor` parameter to `has_attached_file`. When any
279
+ other processor is defined it must be called out in the `:processors`
280
+ parameter if it is to be applied to the attachment. The thumbnail processor
281
+ uses the imagemagick `convert` command to do the work of resizing image
282
+ thumbnails. It would be easy to create a custom processor that watermarks
283
+ an image using imagemagick's `composite` command. Following the
284
+ implementation pattern of the thumbnail processor would be a way to implement a
285
+ watermark processor. All kinds of attachment processors can be created;
286
+ a few utility examples would be compression and encryption processors.
287
+
288
+
289
+ Dynamic Configuration
290
+ ---------------------
291
+
292
+ Callable objects (lambdas, Procs) can be used in a number of places for dynamic
293
+ configuration throughout Paperclip. This strategy exists in a number of
294
+ components of the library but is most significant in the possibilities for
295
+ allowing custom styles and processors to be applied for specific model
296
+ instances, rather than applying defined styles and processors across all
297
+ instances.
298
+
299
+ Dynamic Styles:
300
+
301
+ Imagine a user model that had different styles based on the role of the user.
302
+ Perhaps some users are bosses (e.g. a User model instance responds to #boss?)
303
+ and merit a bigger avatar thumbnail than regular users. The configuration to
304
+ determine what style parameters are to be used based on the user role might
305
+ look as follows where a boss will receive a `300x300` thumbnail otherwise a
306
+ `100x100` thumbnail will be created.
307
+
308
+ class User < ActiveRecord::Base
309
+ has_attached_file :avatar, :styles => lambda { |attachment| { :thumb => (attachment.instance.boss? ? "300x300>" : "100x100>") }
310
+ end
311
+
312
+ Dynamic Processors:
313
+
314
+ Another contrived example is a user model that is aware of which file processors
315
+ should be applied to it (beyond the implied `thumbnail` processor invoked when
316
+ `:styles` are defined). Perhaps we have a watermark processor available and it is
317
+ only used on the avatars of certain models. The configuration for this might be
318
+ where the instance is queried for which processors should be applied to it.
319
+ Presumably some users might return `[:thumbnail, :watermark]` for its
320
+ processors, where a defined `watermark` processor is invoked after the
321
+ `thumbnail` processor already defined by Paperclip.
322
+
323
+ class User < ActiveRecord::Base
324
+ has_attached_file :avatar, :processors => lambda { |instance| instance.processors }
325
+ attr_accessor :watermark
326
+ end
327
+
328
+ Deploy
329
+ ------
330
+
331
+ Paperclip is aware of new attachment styles you have added in previous deploy. The only thing you should do after each deployment is to call
332
+ `rake paperclip:refresh:missing_styles`. It will store current attachment styles in `RAILS_ROOT/public/system/paperclip_attachments.yml`
333
+ by default. You can change it by:
334
+
335
+ Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachments.yml'
336
+
337
+ Here is an example for Capistrano:
338
+
339
+ namespace :deploy do
340
+ desc "build missing paperclip styles"
341
+ task :build_missing_paperclip_styles, :roles => :app do
342
+ run "cd #{release_path}; RAILS_ENV=production bundle exec rake paperclip:refresh:missing_styles"
343
+ end
344
+ end
345
+
346
+ after("deploy:update_code", "deploy:build_missing_paperclip_styles")
347
+
348
+ Now you don't have to remember to refresh thumbnails in production everytime you add new style.
349
+ Unfortunately it does not work with dynamic styles - it just ignores them.
350
+
351
+ If you already have working app and don't want `rake paperclip:refresh:missing_styles` to refresh old pictures, you need to tell
352
+ Paperclip about existing styles. Simply create paperclip_attachments.yml file by hand. For example:
353
+
354
+ class User < ActiveRecord::Base
355
+ has_attached_file :avatar, :styles => {:thumb => 'x100', :croppable => '600x600>', :big => '1000x1000>'}
356
+ end
357
+
358
+ class Book < ActiveRecord::Base
359
+ has_attached_file :cover, :styles => {:small => 'x100', :large => '1000x1000>'}
360
+ has_attached_file :sample, :styles => {:thumb => 'x100'}
361
+ end
362
+
363
+ Then in `RAILS_ROOT/public/system/paperclip_attachments.yml`:
364
+
365
+ ---
366
+ :User:
367
+ :avatar:
368
+ - :thumb
369
+ - :croppable
370
+ - :big
371
+ :Book:
372
+ :cover:
373
+ - :small
374
+ - :large
375
+ :sample:
376
+ - :thumb
377
+
378
+ Testing
379
+ -------
380
+
381
+ Paperclip provides rspec-compatible matchers for testing attachments. See the
382
+ documentation on [Paperclip::Shoulda::Matchers](http://rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
383
+ for more information.
384
+
385
+ Contributing
386
+ ------------
387
+
388
+ If you'd like to contribute a feature or bugfix: Thanks! To make sure your
389
+ fix/feature has a high chance of being included, please read the following
390
+ guidelines:
391
+
392
+ 1. Ask on the mailing list[http://groups.google.com/group/paperclip-plugin], or
393
+ post a new GitHub Issue[http://github.com/thoughtbot/paperclip/issues].
394
+ 2. Make sure there are tests! We will not accept any patch that is not tested.
395
+ It's a rare time when explicit tests aren't needed. If you have questions
396
+ about writing tests for paperclip, please ask the mailing list.
397
+
398
+ Please see CONTRIBUTING.md for details.
399
+
400
+ Credits
401
+ -------
402
+
403
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
404
+
405
+ Paperclip is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
406
+
407
+ Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/contributors)!
408
+
409
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
410
+
411
+ License
412
+ -------
413
+
414
+ Paperclip is Copyright © 2008-2011 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -0,0 +1,86 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'appraisal'
4
+
5
+ require 'rake'
6
+ require 'rake/testtask'
7
+ require 'rdoc/task'
8
+ require 'cucumber/rake/task'
9
+
10
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
11
+ require 'paperclip'
12
+
13
+ desc 'Default: run unit tests.'
14
+ task :default => [:clean, 'appraisal:install', :all]
15
+
16
+ desc 'Test the paperclip plugin under all supported Rails versions.'
17
+ task :all do |t|
18
+ exec('rake appraisal test cucumber')
19
+ end
20
+
21
+ desc 'Test the paperclip plugin.'
22
+ Rake::TestTask.new(:test) do |t|
23
+ t.libs << 'lib' << 'profile'
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.verbose = true
26
+ end
27
+
28
+ desc 'Run integration test'
29
+ Cucumber::Rake::Task.new do |t|
30
+ t.cucumber_opts = %w{--format progress}
31
+ end
32
+
33
+ desc 'Start an IRB session with all necessary files required.'
34
+ task :shell do |t|
35
+ chdir File.dirname(__FILE__)
36
+ exec 'irb -I lib/ -I lib/paperclip -r rubygems -r active_record -r tempfile -r init'
37
+ end
38
+
39
+ desc 'Generate documentation for the paperclip plugin.'
40
+ RDoc::Task.new(:rdoc) do |rdoc|
41
+ rdoc.rdoc_dir = 'doc'
42
+ rdoc.title = 'Paperclip'
43
+ rdoc.options << '--line-numbers' << '--inline-source'
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
47
+
48
+ desc 'Update documentation on website'
49
+ task :sync_docs => 'rdoc' do
50
+ `rsync -ave ssh doc/ dev@dev.thoughtbot.com:/home/dev/www/dev.thoughtbot.com/paperclip`
51
+ end
52
+
53
+ desc 'Clean up files.'
54
+ task :clean do |t|
55
+ FileUtils.rm_rf "doc"
56
+ FileUtils.rm_rf "tmp"
57
+ FileUtils.rm_rf "pkg"
58
+ FileUtils.rm_rf "public"
59
+ FileUtils.rm "test/debug.log" rescue nil
60
+ FileUtils.rm "test/paperclip.db" rescue nil
61
+ Dir.glob("paperclip-*.gem").each{|f| FileUtils.rm f }
62
+ end
63
+
64
+ desc 'Build the gemspec.'
65
+ task :gemspec do |t|
66
+ exec 'gem build paperclip.gemspec'
67
+ end
68
+
69
+ desc "Print a list of the files to be put into the gem"
70
+ task :manifest => :clean do
71
+ spec.files.each do |file|
72
+ puts file
73
+ end
74
+ end
75
+
76
+ desc "Generate a gemspec file for GitHub"
77
+ task :gemspec => :clean do
78
+ File.open("#{spec.name}.gemspec", 'w') do |f|
79
+ f.write spec.to_ruby
80
+ end
81
+ end
82
+
83
+ desc "Build the gem into the current directory"
84
+ task :gem => :gemspec do
85
+ `gem build #{spec.name}.gemspec`
86
+ end