Permalink
Browse files

Paperclip as a submodule

  • Loading branch information...
1 parent 61c246f commit 4436148411ed33c55091c9d046b25f220b409cce @jschwindt committed Apr 14, 2009
Showing with 29 additions and 4,288 deletions.
  1. 0 app/controllers/{application.rb → application_controller.rb}
  2. +1 −4 app/models/user.rb
  3. +1 −1 config/environment.rb
  4. +10 −1 db/schema.rb
  5. +17 −5 lib/paperclip_processors/jcropper.rb
  6. +0 −26 vendor/plugins/paperclip/LICENSE
  7. +0 −172 vendor/plugins/paperclip/README.rdoc
  8. +0 −77 vendor/plugins/paperclip/Rakefile
  9. +0 −5 vendor/plugins/paperclip/generators/paperclip/USAGE
  10. +0 −27 vendor/plugins/paperclip/generators/paperclip/paperclip_generator.rb
  11. +0 −19 vendor/plugins/paperclip/generators/paperclip/templates/paperclip_migration.rb.erb
  12. +0 −1 vendor/plugins/paperclip/init.rb
  13. +0 −318 vendor/plugins/paperclip/lib/paperclip.rb
  14. +0 −396 vendor/plugins/paperclip/lib/paperclip/attachment.rb
  15. +0 −33 vendor/plugins/paperclip/lib/paperclip/callback_compatability.rb
  16. +0 −115 vendor/plugins/paperclip/lib/paperclip/geometry.rb
  17. +0 −58 vendor/plugins/paperclip/lib/paperclip/iostream.rb
  18. +0 −47 vendor/plugins/paperclip/lib/paperclip/processor.rb
  19. +0 −220 vendor/plugins/paperclip/lib/paperclip/storage.rb
  20. +0 −70 vendor/plugins/paperclip/lib/paperclip/thumbnail.rb
  21. +0 −48 vendor/plugins/paperclip/lib/paperclip/upfile.rb
  22. +0 −40 vendor/plugins/paperclip/paperclip.gemspec
  23. +0 −4 vendor/plugins/paperclip/shoulda_macros/matchers.rb
  24. +0 −49 vendor/plugins/paperclip/shoulda_macros/matchers/have_attached_file_matcher.rb
  25. +0 −66 vendor/plugins/paperclip/shoulda_macros/matchers/validate_attachment_content_type_matcher.rb
  26. +0 −48 vendor/plugins/paperclip/shoulda_macros/matchers/validate_attachment_presence_matcher.rb
  27. +0 −83 vendor/plugins/paperclip/shoulda_macros/matchers/validate_attachment_size_matcher.rb
  28. +0 −68 vendor/plugins/paperclip/shoulda_macros/paperclip.rb
  29. +0 −79 vendor/plugins/paperclip/tasks/paperclip_tasks.rake
  30. +0 −1 vendor/plugins/paperclip/test/.gitignore
  31. +0 −627 vendor/plugins/paperclip/test/attachment_test.rb
  32. +0 −4 vendor/plugins/paperclip/test/database.yml
  33. BIN vendor/plugins/paperclip/test/fixtures/12k.png
  34. BIN vendor/plugins/paperclip/test/fixtures/50x50.png
  35. BIN vendor/plugins/paperclip/test/fixtures/5k.png
  36. +0 −1 vendor/plugins/paperclip/test/fixtures/bad.png
  37. 0 vendor/plugins/paperclip/test/fixtures/text.txt
  38. BIN vendor/plugins/paperclip/test/fixtures/twopage.pdf
  39. +0 −168 vendor/plugins/paperclip/test/geometry_test.rb
  40. +0 −82 vendor/plugins/paperclip/test/helper.rb
  41. +0 −493 vendor/plugins/paperclip/test/integration_test.rb
  42. +0 −71 vendor/plugins/paperclip/test/iostream_test.rb
  43. +0 −21 vendor/plugins/paperclip/test/matchers/have_attached_file_matcher_test.rb
  44. +0 −30 vendor/plugins/paperclip/test/matchers/validate_attachment_content_type_matcher_test.rb
  45. +0 −21 vendor/plugins/paperclip/test/matchers/validate_attachment_presence_matcher_test.rb
  46. +0 −50 vendor/plugins/paperclip/test/matchers/validate_attachment_size_matcher_test.rb
  47. +0 −237 vendor/plugins/paperclip/test/paperclip_test.rb
  48. +0 −10 vendor/plugins/paperclip/test/processor_test.rb
  49. +0 −215 vendor/plugins/paperclip/test/storage_test.rb
  50. +0 −177 vendor/plugins/paperclip/test/thumbnail_test.rb
View
@@ -6,10 +6,7 @@ class User < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :normal => ["#{AVATAR_NW}x#{AVATAR_NH}>", :jpg],
- :small => ["#{AVATAR_SW}x#{AVATAR_SH}", :jpg] },
- :convert_options => { :all => "-strip",
- :normal => proc { |m| m.avatar_crop_str },
- :small => proc { |m| m.avatar_crop_str } },
+ :small => ["#{AVATAR_SW}x#{AVATAR_SH}#", :jpg] },
:processors => [:jcropper],
:default_url => "/images/default_avatar.png"
View
@@ -5,7 +5,7 @@
# ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
-RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION
+RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
View
@@ -9,6 +9,15 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 0) do
+ActiveRecord::Schema.define(:version => 20090208152022) do
+
+ create_table "users", :force => true do |t|
+ t.string "name"
+ t.string "avatar_file_name"
+ t.string "avatar_content_type"
+ t.integer "avatar_file_size"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
end
@@ -7,15 +7,27 @@ module Paperclip
# Handles thumbnailing images that are uploaded.
class Jcropper < Thumbnail
- # Returns the command ImageMagick's +convert+ needs to transform the image
- # into the thumbnail.
def transformation_command
scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
trans = ''
- trans << " #{convert_options}" if convert_options?
- trans << " -resize \"#{scale}\""
- trans << " -crop \"#{crop}\" +repage" if crop
+ if crop_string?
+ trans << " #{image_crop_string}"
+ trans << " -resize \"#{scale}\""
+ else
+ trans << " -resize \"#{scale}\""
+ trans << " -crop \"#{crop}\" +repage" if crop
+ end
trans
end
+
+ def crop_string
+ @attachment.instance.crop_str
+ end
+
+ def crop_string?
+ not crop_string.blank?
+ end
+
end
+
end
@@ -1,26 +0,0 @@
-
-LICENSE
-
-The MIT License
-
-Copyright (c) 2008 Jon Yurek and thoughtbot, inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
-
@@ -1,172 +0,0 @@
-=Paperclip
-
-Paperclip is intended as an easy file attachment library for ActiveRecord. The
-intent behind it was to keep setup as easy as possible and to treat files as
-much like other attributes as possible. This means they aren't saved to their
-final locations on disk, nor are they deleted if set to nil, until
-ActiveRecord::Base#save is called. It manages validations based on size and
-presence, if required. It can transform its assigned image into thumbnails if
-needed, and the prerequisites are as simple as installing ImageMagick (which,
-for most modern Unix-based systems, is as easy as installing the right
-packages). Attached files are saved to the filesystem and referenced in the
-browser by an easily understandable specification, which has sensible and
-useful defaults.
-
-See the documentation for +has_attached_file+ in Paperclip::ClassMethods for
-more detailed options.
-
-==Quick Start
-
-In your model:
-
- class User < ActiveRecord::Base
- has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
- end
-
-In your migrations:
-
- class AddAvatarColumnsToUser < ActiveRecord::Migration
- def self.up
- add_column :users, :avatar_file_name, :string
- add_column :users, :avatar_content_type, :string
- add_column :users, :avatar_file_size, :integer
- add_column :users, :avatar_updated_at, :datetime
- end
-
- def self.down
- remove_column :users, :avatar_file_name
- remove_column :users, :avatar_content_type
- remove_column :users, :avatar_file_size
- remove_column :users, :avatar_updated_at
- end
- end
-
-In your edit and new views:
-
- <% form_for :user, @user, :url => user_path, :html => { :multipart => true } do |form| %>
- <%= form.file_field :avatar %>
- <% end %>
-
-In your controller:
-
- def create
- @user = User.create( params[:user] )
- end
-
-In your show view:
-
- <%= image_tag @user.avatar.url %>
- <%= image_tag @user.avatar.url(:medium) %>
- <%= image_tag @user.avatar.url(:thumb) %>
-
-==Usage
-
-The basics of paperclip are quite simple: Declare that your model has an
-attachment with the has_attached_file method, and give it a name. Paperclip
-will wrap up up to four attributes (all prefixed with that attachment's name,
-so you can have multiple attachments per model if you wish) and give the a
-friendly front end. The attributes are <attachment>_file_name,
-<attachment>_file_size, <attachment>_content_type, and <attachment>_updated_at.
-Only <attachment>_file_name is required for paperclip to operate. More
-information about the options to has_attached_file is available in the
-documentation of Paperclip::ClassMethods.
-
-Attachments can be validated with Paperclip's validation methods,
-validates_attachment_presence, validates_attachment_content_type, and
-validates_attachment_size.
-
-==Storage
-
-The files that are assigned as attachments are, by default, placed in the
-directory specified by the :path option to has_attached_file. By default, this
-location is
-":rails_root/public/system/:attachment/:id/:style/:basename.:extension". This
-location was chosen because on standard Capistrano deployments, the
-public/system directory is symlinked to the app's shared directory, meaning it
-will survive between deployments. For example, using that :path, you may have a
-file at
-
- /data/myapp/releases/20081229172410/public/system/avatars/13/small/my_pic.png
-
-NOTE: This is a change from previous versions of Paperclip, but is overall a
-safer choice for the defaul file store.
-
-You may also choose to store your files using Amazon's S3 service. You can find
-more information about S3 storage at the description for
-Paperclip::Storage::S3.
-
-Files on the local filesystem (and in the Rails app's public directory) will be
-available to the internet at large. If you require access control, it's
-possible to place your files in a different location. You will need to change
-both the :path and :url options in order to make sure the files are unavailable
-to the public. Both :path and :url allow the same set of interpolated
-variables.
-
-==Post Processing
-
-Paperclip supports an extendible selection of post-processors. When you define
-a set of styles for an attachment, by default it is expected that those
-"styles" are actually "thumbnails". However, you can do more than just
-thumbnail images. By defining a subclass of Paperclip::Processor, you can
-perform any processing you want on the files that are attached. Any file in
-your Rails app's lib/paperclip_processors directory is automatically loaded by
-paperclip, allowing you to easily define custom processors. You can specify a
-processor with the :processors option to has_attached_file:
-
- has_attached_file :scan, :styles => { :text => { :quality => :better } },
- :processors => [:ocr]
-
-This would load the hypothetical class Paperclip::Ocr, which would have the
-hash "{ :quality => :better }" passed to it along with the uploaded file. For
-more information about defining processors, see Paperclip::Processor.
-
-The default processor is Paperclip::Thumbnail. For backwards compatability
-reasons, you can pass a single geometry string or an array containing a
-geometry and a format, which the file will be converted to, like so:
-
- has_attached_file :avatar, :styles => { :thumb => ["32x32#", :png] }
-
-This will convert the "thumb" style to a 32x32 square in png format, regardless
-of what was uploaded. If the format is not specified, it is kept the same (i.e.
-jpgs will remain jpgs).
-
-Multiple processors can be specified, and they will be invoked in the order
-they are defined in the :processors array. Each successive processor will
-be given the result of the previous processor's execution. All processors will
-receive the same parameters, which are what you define in the :styles hash.
-For example, assuming we had this definition:
-
- has_attached_file :scan, :styles => { :text => { :quality => :better } },
- :processors => [:rotator, :ocr]
-
-then both the :rotator processor and the :ocr processor would receive the
-options "{ :quality => :better }". This parameter may not mean anything to one
-or more or the processors, and they are free to ignore it.
-
-==Events
-
-Before and after the Post Processing step, Paperclip calls back to the model
-with a few callbacks, allowing the model to change or cancel the processing
-step. The callbacks are "before_post_process" and "after_post_process" (which
-are called before and after the processing of each attachment), and the
-attachment-specific "before_<attachment>_post_process" and
-"after_<attachment>_post_process". The callbacks are intended to be as close to
-normal ActiveRecord callbacks as possible, so if you return false (specifically
-- returning nil is not the same) in a before_ filter, the post processing step
-will halt. Returning false in an after_ filter will not halt anything, but you
-can access the model and the attachment if necessary.
-
-NOTE: Post processing will not even *start* if the attachment is not valid
-according to the validations. Your callbacks (and processors) will only be
-called with valid attachments.
-
-==Contributing
-
-If you'd like to contribute a feature or bugfix: Thanks! To make sure your
-fix/feature has a high chance of being included, please read the following
-guidelines:
-
-1. Ask on the mailing list, or post a ticket in Lighthouse.
-2. Make sure there are tests! We will not accept any patch that is not tested.
- It's a rare time when explicit tests aren't needed. If you have questions
- about writing tests for paperclip, please ask the mailing list.
@@ -1,77 +0,0 @@
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-
-$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
-require 'paperclip'
-
-desc 'Default: run unit tests.'
-task :default => [:clean, :test]
-
-desc 'Test the paperclip plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib' << 'profile'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
-
-desc 'Start an IRB session with all necessary files required.'
-task :shell do |t|
- chdir File.dirname(__FILE__)
- exec 'irb -I lib/ -I lib/paperclip -r rubygems -r active_record -r tempfile -r init'
-end
-
-desc 'Generate documentation for the paperclip plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'doc'
- rdoc.title = 'Paperclip'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
-
-desc 'Update documentation on website'
-task :sync_docs => 'rdoc' do
- `rsync -ave ssh doc/ dev@dev.thoughtbot.com:/home/dev/www/dev.thoughtbot.com/paperclip`
-end
-
-desc 'Clean up files.'
-task :clean do |t|
- FileUtils.rm_rf "doc"
- FileUtils.rm_rf "tmp"
- FileUtils.rm_rf "pkg"
- FileUtils.rm "test/debug.log" rescue nil
- FileUtils.rm "test/paperclip.db" rescue nil
-end
-
-spec = Gem::Specification.new do |s|
- s.name = "paperclip"
- s.version = Paperclip::VERSION
- s.author = "Jon Yurek"
- s.email = "jyurek@thoughtbot.com"
- s.homepage = "http://www.thoughtbot.com/projects/paperclip"
- s.platform = Gem::Platform::RUBY
- s.summary = "File attachments as attributes for ActiveRecord"
- s.files = FileList["README*",
- "LICENSE",
- "Rakefile",
- "init.rb",
- "{generators,lib,tasks,test,shoulda_macros}/**/*"].to_a
- s.require_path = "lib"
- s.test_files = FileList["test/**/test_*.rb"].to_a
- s.rubyforge_project = "paperclip"
- s.has_rdoc = true
- s.extra_rdoc_files = FileList["README*"].to_a
- s.rdoc_options << '--line-numbers' << '--inline-source'
- s.requirements << "ImageMagick"
- s.add_runtime_dependency 'right_aws'
- s.add_development_dependency 'thoughtbot-shoulda'
- s.add_development_dependency 'mocha'
-end
-
-desc "Generate a gemspec file for GitHub"
-task :gemspec do
- File.open("#{spec.name}.gemspec", 'w') do |f|
- f.write spec.to_ruby
- end
-end
@@ -1,5 +0,0 @@
-Usage:
-
- script/generate paperclip Class attachment1 (attachment2 ...)
-
-This will create a migration that will add the proper columns to your class's table.
@@ -1,27 +0,0 @@
-class PaperclipGenerator < Rails::Generator::NamedBase
- attr_accessor :attachments, :migration_name
-
- def initialize(args, options = {})
- super
- @class_name, @attachments = args[0], args[1..-1]
- end
-
- def manifest
- file_name = generate_file_name
- @migration_name = file_name.camelize
- record do |m|
- m.migration_template "paperclip_migration.rb.erb",
- File.join('db', 'migrate'),
- :migration_file_name => file_name
- end
- end
-
- private
-
- def generate_file_name
- names = attachments.map{|a| a.underscore }
- names = names[0..-2] + ["and", names[-1]] if names.length > 1
- "add_attachments_#{names.join("_")}_to_#{@class_name.underscore}"
- end
-
-end
Oops, something went wrong.

0 comments on commit 4436148

Please sign in to comment.