Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
last-minute cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-burns committed Jul 27, 2012
1 parent 6d24f1a commit ab750eb
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 205 deletions.
52 changes: 11 additions & 41 deletions README.md
Expand Up @@ -482,52 +482,22 @@ processors, where a defined `watermark` processor is invoked after the
Deployment
----------

Paperclip is aware of new attachment styles you have added in previous deploys. The only thing you should do after each deployment is to call
`rake paperclip:refresh:missing_styles`. It will store current attachment styles in `RAILS_ROOT/public/system/paperclip_attachments.yml`
by default. You can change it by:
When you add a new style you can write a migration to ease the
deployment. Do this using the `add_style` and `remove_style` migration
schema helpers.

Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachments.yml'

Here is an example for Capistrano:

namespace :deploy do
desc "build missing paperclip styles"
task :build_missing_paperclip_styles, :roles => :app do
run "cd #{release_path}; RAILS_ENV=production bundle exec rake paperclip:refresh:missing_styles"
class AddThumbnailsToUser < ActiveRecord::Migration
def up
add_style :users, :avatar, thumbnail: '24x24#'
end
end

after("deploy:update_code", "deploy:build_missing_paperclip_styles")

Now you don't have to remember to refresh thumbnails in production every time you add a new style.
Unfortunately it does not work with dynamic styles - it just ignores them.

If you already have a working app and don't want `rake paperclip:refresh:missing_styles` to refresh old pictures, you need to tell
Paperclip about existing styles. Simply create a `paperclip_attachments.yml` file by hand. For example:

class User < ActiveRecord::Base
has_attached_file :avatar, :styles => {:thumb => 'x100', :croppable => '600x600>', :big => '1000x1000>'}
end

class Book < ActiveRecord::Base
has_attached_file :cover, :styles => {:small => 'x100', :large => '1000x1000>'}
has_attached_file :sample, :styles => {:thumb => 'x100'}
def down
remove_style :users, :avatar, :thumbnail
end
end

Then in `RAILS_ROOT/public/system/paperclip_attachments.yml`:

---
:User:
:avatar:
- :thumb
- :croppable
- :big
:Book:
:cover:
- :small
- :large
:sample:
- :thumb
The above migration will process just the `thumbnail` style when going
up, and will remove the `thumbnail` files when going down.

Testing
-------
Expand Down
63 changes: 0 additions & 63 deletions features/rake_tasks.feature

This file was deleted.

4 changes: 0 additions & 4 deletions lib/paperclip/attachment.rb
Expand Up @@ -31,10 +31,6 @@ def self.default_options
}
end

def self.reset
@default_options = nil
end

attr_reader :name, :instance, :default_style, :convert_options, :queued_for_write, :whiny,
:options, :interpolator, :source_file_options, :whiny
attr_accessor :post_processing
Expand Down
2 changes: 0 additions & 2 deletions lib/paperclip/railtie.rb
Expand Up @@ -14,8 +14,6 @@ class Railtie < Rails::Railtie
Paperclip::Attachment.default_options.merge!(app.config.paperclip_defaults)
end
end

rake_tasks { load "tasks/paperclip.rake" }
end

class Railtie
Expand Down
93 changes: 0 additions & 93 deletions lib/tasks/paperclip.rake

This file was deleted.

4 changes: 3 additions & 1 deletion test/style_adder_test.rb
Expand Up @@ -6,9 +6,11 @@ class StyleAdderTest < Test::Unit::TestCase
register_recording_processor

Dummy = rebuild_model styles: { thumbnail: '24x24' }, processors: [:recording]
file = File.new(fixture_file("50x50.png"), 'rb')
dummy = Dummy.new
dummy.avatar = File.new(fixture_file("50x50.png"), 'rb')
dummy.avatar = file
dummy.save
file.close

Dummy.class_eval do
has_attached_file :avatar, styles: { thumbnail: '24x24', large: '124x124' }, processors: [:recording]
Expand Down
4 changes: 3 additions & 1 deletion test/style_remover_test.rb
Expand Up @@ -6,9 +6,11 @@ class StyleRemoverTest < Test::Unit::TestCase
register_recording_processor

Dummy = rebuild_model styles: { large: '24x24' }, processors: [:recording]
file = File.new(fixture_file("50x50.png"), 'rb')
dummy = Dummy.new
dummy.avatar = File.new(fixture_file("50x50.png"), 'rb')
dummy.avatar = file
dummy.save
file.close

large_path = dummy.avatar.path(:large)
original_path = dummy.avatar.path(:original)
Expand Down

0 comments on commit ab750eb

Please sign in to comment.