Commit 6f8b31f4 by Jon Yurek

Merge branch 'rails3'

parents a4d1b0eb c334c989
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
tmp tmp
test/s3.yml test/s3.yml
public public
paperclip*.gem
Description:
Explain the generator
Example:
rails generate paperclip Thing
This will create:
what/will/it/create
require 'rails/generators/active_record'
class PaperclipGenerator < ActiveRecord::Generators::Base
desc "Create a migration to add paperclip-specific fields to your model."
argument :attachment_names, :required => true, :type => :array, :desc => "The names of the attachment(s) to add.",
:banner => "attachment_one attachment_two attachment_three ..."
def self.source_root
@source_root ||= File.expand_path('../templates', __FILE__)
end
def generate_migration
migration_template "paperclip_migration.rb.erb", "db/migrate/#{migration_file_name}"
end
protected
def migration_name
"add_attachment_#{attachment_names.join("_")}_to_#{name.underscore}"
end
def migration_file_name
"#{migration_name}.rb"
end
def migration_class_name
migration_name.camelize
end
end
class <%= migration_class_name %> < ActiveRecord::Migration
def self.up
<% attachment_names.each do |attachment| -%>
add_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_file_name, :string
add_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_content_type, :string
add_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_file_size, :integer
add_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at, :datetime
<% end -%>
end
def self.down
<% attachment_names.each do |attachment| -%>
remove_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_file_name
remove_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_content_type
remove_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_file_size
remove_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at
<% end -%>
end
end
...@@ -37,6 +37,7 @@ require 'paperclip/interpolations' ...@@ -37,6 +37,7 @@ require 'paperclip/interpolations'
require 'paperclip/style' require 'paperclip/style'
require 'paperclip/attachment' require 'paperclip/attachment'
require 'paperclip/callback_compatability' require 'paperclip/callback_compatability'
require 'paperclip/railtie'
if defined?(Rails.root) && Rails.root if defined?(Rails.root) && Rails.root
Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor| Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor|
require processor require processor
...@@ -47,7 +48,7 @@ end ...@@ -47,7 +48,7 @@ end
# documentation for Paperclip::ClassMethods for more useful information. # documentation for Paperclip::ClassMethods for more useful information.
module Paperclip module Paperclip
VERSION = "2.3.2" VERSION = "2.3.2.beta1"
class << self class << self
# Provides configurability to Paperclip. There are a number of options available, such as: # Provides configurability to Paperclip. There are a number of options available, such as:
...@@ -70,6 +71,10 @@ module Paperclip ...@@ -70,6 +71,10 @@ module Paperclip
} }
end end
def configure
yield(self) if block_given?
end
def path_for_command command #:nodoc: def path_for_command command #:nodoc:
if options[:image_magick_path] if options[:image_magick_path]
warn("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead") warn("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead")
...@@ -130,8 +135,6 @@ module Paperclip ...@@ -130,8 +135,6 @@ module Paperclip
base.extend ClassMethods base.extend ClassMethods
if base.respond_to?("set_callback") if base.respond_to?("set_callback")
base.send :include, Paperclip::CallbackCompatability::Rails3 base.send :include, Paperclip::CallbackCompatability::Rails3
elsif !base.respond_to?("define_callbacks")
base.send :include, Paperclip::CallbackCompatability::Rails20
else else
base.send :include, Paperclip::CallbackCompatability::Rails21 base.send :include, Paperclip::CallbackCompatability::Rails21
end end
...@@ -358,7 +361,7 @@ module Paperclip ...@@ -358,7 +361,7 @@ module Paperclip
@_paperclip_attachments ||= {} @_paperclip_attachments ||= {}
@_paperclip_attachments[name] ||= Attachment.new(name, self, self.class.attachment_definitions[name]) @_paperclip_attachments[name] ||= Attachment.new(name, self, self.class.attachment_definitions[name])
end end
def each_attachment def each_attachment
self.class.attachment_definitions.each do |name, definition| self.class.attachment_definitions.each do |name, definition|
yield(name, attachment_for(name)) yield(name, attachment_for(name))
...@@ -382,9 +385,3 @@ module Paperclip ...@@ -382,9 +385,3 @@ module Paperclip
end end
end end
# Set it all up.
if Object.const_defined?("ActiveRecord")
ActiveRecord::Base.send(:include, Paperclip)
File.send(:include, Paperclip::Upfile)
end
require 'paperclip'
module Paperclip
if defined? Rails::Railtie
require 'rails'
class Railtie < Rails::Railtie
initializer "paperclip.insert_into_active_record" do
Paperclip::Railtie.insert
end
rake_tasks do
load "tasks/paperclip.rake"
end
end
end
class Railtie
def self.insert
ActiveRecord::Base.send(:include, Paperclip)
File.send(:include, Paperclip::Upfile)
end
end
end
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib') $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require 'paperclip' require 'paperclip'
include_files = ["README*", "LICENSE", "Rakefile", "init.rb", "{generators,lib,tasks,test,shoulda_macros}/**/*"].map do |glob| include_files = ["README*", "LICENSE", "Rakefile", "init.rb", "{lib,tasks,test,rails,generators,shoulda_macros}/**/*"].map do |glob|
Dir[glob] Dir[glob]
end.flatten end.flatten
exclude_files = ["test/s3.yml", "test/debug.log", "test/paperclip.db", "test/doc", "test/doc/*", "test/pkg", "test/pkg/*", "test/tmp", "test/tmp/*"].map do |glob| exclude_files = ["test/s3.yml", "test/debug.log", "test/paperclip.db", "test/doc", "test/doc/*", "test/pkg", "test/pkg/*", "test/tmp", "test/tmp/*"].map do |glob|
...@@ -25,11 +25,11 @@ spec = Gem::Specification.new do |s| ...@@ -25,11 +25,11 @@ spec = Gem::Specification.new do |s|
s.extra_rdoc_files = Dir["README*"] s.extra_rdoc_files = Dir["README*"]
s.rdoc_options << '--line-numbers' << '--inline-source' s.rdoc_options << '--line-numbers' << '--inline-source'
s.requirements << "ImageMagick" s.requirements << "ImageMagick"
s.add_dependency 'activerecord'
s.add_dependency 'activesupport'
s.add_development_dependency 'shoulda' s.add_development_dependency 'shoulda'
s.add_development_dependency 'mocha' s.add_development_dependency 'mocha'
s.add_development_dependency 'aws-s3' s.add_development_dependency 'aws-s3'
s.add_development_dependency 'sqlite3-ruby' s.add_development_dependency 'sqlite3-ruby'
s.add_development_dependency 'active_record'
s.add_development_dependency 'active_support'
end end
puts "THIS IS THE RAILS/INIT.RB FILE"
require 'paperclip/railtie'
Paperclip::Railtie.insert
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment