Permalink
Browse files

Initial commit

  • Loading branch information...
1 parent 95569c0 commit cc0d5a70e322d66605feac86d144e497644b3aac @pk committed Nov 11, 2008
View
26 LICENSE
@@ -0,0 +1,26 @@
+
+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.
+
+
View
59 README
@@ -0,0 +1,59 @@
+=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 the +has_attached_file+ method for options.
+
+==Usage
+
+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) %>
+
+==Contributing
+
+If you'd like to contribute a feature or bugfix, thanks! To make sure your fix/feature
+has a high chance of being added, please read the following guidelines:
+
+1. Ask on the mailing list, or post a ticket in Lighthouse.
+2. Make sure there are tests! I 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.
View
@@ -0,0 +1,96 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require 'rake/gempackagetask'
+
+$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
+require 'sequel_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/sequel_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 = 'SequelPaperclip'
+ 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.rubygems_version = "1.2.0"
+ s.name = "sequel_paperclip"
+ s.version = Paperclip::VERSION
+ s.author = "Jon Yurek, Pavel Kunc"
+ s.email = "jyurek@thoughtbot.com, pavel.kunc@gmail.com"
+ s.homepage = "http://www.thoughtbot.com/, http://www.merboutpost.com"
+ s.platform = Gem::Platform::RUBY
+ s.summary = "File attachments as attributes for Merb + Sequel"
+ s.files = FileList["README",
+ "LICENSE",
+ "Rakefile",
+ "init.rb",
+ "{generators,lib,tasks,test}/**/*"].to_a
+ s.require_path = "lib"
+ s.test_files = FileList["test/**/test_*.rb"].to_a
+ s.rubyforge_project = "sequel_paperclip"
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README"]
+ s.rdoc_options << '--line-numbers' << '--inline-source'
+ s.requirements << "ImageMagick"
+ s.add_runtime_dependency 'right_aws'
+ s.add_development_dependency 'Shoulda'
+ s.add_development_dependency 'mocha'
+end
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_tar = true
+end
+
+desc "Release new version"
+task :release => [:test, :sync_docs, :gem] do
+ require 'rubygems'
+ require 'rubyforge'
+ r = RubyForge.new
+ r.login
+ r.add_release spec.rubyforge_project,
+ spec.name,
+ spec.version,
+ File.join("pkg", "#{spec.name}-#{spec.version}.gem")
+end
+
+WIN32 = (PLATFORM =~ /win32|cygwin/) rescue nil
+SUDO = WIN32 ? '' : ('sudo' unless ENV['SUDOLESS'])
+
+desc "Install #{spec.name} #{spec.version}"
+task :install => [ :package ] do
+ sh "#{SUDO} gem install pkg/#{spec.name}-#{spec.version} --no-update-sources", :verbose => false
+end
@@ -0,0 +1,5 @@
+Usage:
+
+ script/generate paperclip Class attachment1 (attachment2 ...)
+
+This will create a migration that will add the proper columns to your class's table.
@@ -0,0 +1,27 @@
+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
@@ -0,0 +1,19 @@
+class <%= migration_name %> < ActiveRecord::Migration
+ def self.up
+<% attachments.each do |attachment| -%>
+ add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name, :string
+ add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type, :string
+ add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size, :integer
+ add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at, :datetime
+<% end -%>
+ end
+
+ def self.down
+<% attachments.each do |attachment| -%>
+ remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name
+ remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type
+ remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size
+ remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at
+<% end -%>
+ end
+end
View
@@ -0,0 +1 @@
+require File.join(File.dirname(__FILE__), 'lib', 'sequel_paperclip')
Oops, something went wrong.

0 comments on commit cc0d5a7

Please sign in to comment.