Permalink
Browse files

Merge branch 'rails3'

  • Loading branch information...
2 parents a4d1b0e + c334c98 commit 6f8b31f47753f43100e5739c947cb5a83d9b2844 @jyurek jyurek committed Jun 7, 2010
View
@@ -3,3 +3,4 @@
tmp
test/s3.yml
public
+paperclip*.gem
@@ -0,0 +1,8 @@
+Description:
+ Explain the generator
+
+Example:
+ rails generate paperclip Thing
+
+ This will create:
+ what/will/it/create
@@ -0,0 +1,31 @@
+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
@@ -0,0 +1,19 @@
+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
View
@@ -37,6 +37,7 @@
require 'paperclip/style'
require 'paperclip/attachment'
require 'paperclip/callback_compatability'
+require 'paperclip/railtie'
if defined?(Rails.root) && Rails.root
Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor|
require processor
@@ -47,7 +48,7 @@
# documentation for Paperclip::ClassMethods for more useful information.
module Paperclip
- VERSION = "2.3.2"
+ VERSION = "2.3.2.beta1"
class << self
# Provides configurability to Paperclip. There are a number of options available, such as:
@@ -70,6 +71,10 @@ def options
}
end
+ def configure
+ yield(self) if block_given?
+ end
+
def path_for_command command #:nodoc:
if options[:image_magick_path]
warn("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead")
@@ -130,8 +135,6 @@ def included base #:nodoc:
base.extend ClassMethods
if base.respond_to?("set_callback")
base.send :include, Paperclip::CallbackCompatability::Rails3
- elsif !base.respond_to?("define_callbacks")
- base.send :include, Paperclip::CallbackCompatability::Rails20
else
base.send :include, Paperclip::CallbackCompatability::Rails21
end
@@ -358,7 +361,7 @@ def attachment_for name
@_paperclip_attachments ||= {}
@_paperclip_attachments[name] ||= Attachment.new(name, self, self.class.attachment_definitions[name])
end
-
+
def each_attachment
self.class.attachment_definitions.each do |name, definition|
yield(name, attachment_for(name))
@@ -382,9 +385,3 @@ def destroy_attached_files
end
end
-
-# Set it all up.
-if Object.const_defined?("ActiveRecord")
- ActiveRecord::Base.send(:include, Paperclip)
- File.send(:include, Paperclip::Upfile)
-end
View
@@ -0,0 +1,22 @@
+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
File renamed without changes.
View
@@ -1,7 +1,7 @@
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
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]
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|
@@ -25,11 +25,11 @@ spec = Gem::Specification.new do |s|
s.extra_rdoc_files = Dir["README*"]
s.rdoc_options << '--line-numbers' << '--inline-source'
s.requirements << "ImageMagick"
+ s.add_dependency 'activerecord'
+ s.add_dependency 'activesupport'
s.add_development_dependency 'shoulda'
s.add_development_dependency 'mocha'
s.add_development_dependency 'aws-s3'
s.add_development_dependency 'sqlite3-ruby'
- s.add_development_dependency 'active_record'
- s.add_development_dependency 'active_support'
end
View
@@ -0,0 +1,3 @@
+puts "THIS IS THE RAILS/INIT.RB FILE"
+require 'paperclip/railtie'
+Paperclip::Railtie.insert

0 comments on commit 6f8b31f

Please sign in to comment.