diff options
| author | hukl <contact@smyck.org> | 2009-04-24 11:43:08 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-04-25 14:55:27 +0200 |
| commit | cf1b60e0cfa7d1a8f4a80d686649cc12e73a634e (patch) | |
| tree | b68bd845d290ce968892c4532bcff52083925834 /vendor/plugins/paperclip/generators | |
| parent | b2b78c06074046bd73cc3408a29386a976f0469c (diff) | |
Integrated basic Asset upload functionality. You can upload files now and use their url in pages.
Diffstat (limited to 'vendor/plugins/paperclip/generators')
3 files changed, 51 insertions, 0 deletions
diff --git a/vendor/plugins/paperclip/generators/paperclip/USAGE b/vendor/plugins/paperclip/generators/paperclip/USAGE new file mode 100644 index 0000000..2d611d7 --- /dev/null +++ b/vendor/plugins/paperclip/generators/paperclip/USAGE | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | Usage: | ||
| 2 | |||
| 3 | script/generate paperclip Class attachment1 (attachment2 ...) | ||
| 4 | |||
| 5 | This will create a migration that will add the proper columns to your class's table. \ No newline at end of file | ||
diff --git a/vendor/plugins/paperclip/generators/paperclip/paperclip_generator.rb b/vendor/plugins/paperclip/generators/paperclip/paperclip_generator.rb new file mode 100644 index 0000000..77ee5a2 --- /dev/null +++ b/vendor/plugins/paperclip/generators/paperclip/paperclip_generator.rb | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | class PaperclipGenerator < Rails::Generator::NamedBase | ||
| 2 | attr_accessor :attachments, :migration_name | ||
| 3 | |||
| 4 | def initialize(args, options = {}) | ||
| 5 | super | ||
| 6 | @class_name, @attachments = args[0], args[1..-1] | ||
| 7 | end | ||
| 8 | |||
| 9 | def manifest | ||
| 10 | file_name = generate_file_name | ||
| 11 | @migration_name = file_name.camelize | ||
| 12 | record do |m| | ||
| 13 | m.migration_template "paperclip_migration.rb.erb", | ||
| 14 | File.join('db', 'migrate'), | ||
| 15 | :migration_file_name => file_name | ||
| 16 | end | ||
| 17 | end | ||
| 18 | |||
| 19 | private | ||
| 20 | |||
| 21 | def generate_file_name | ||
| 22 | names = attachments.map{|a| a.underscore } | ||
| 23 | names = names[0..-2] + ["and", names[-1]] if names.length > 1 | ||
| 24 | "add_attachments_#{names.join("_")}_to_#{@class_name.underscore}" | ||
| 25 | end | ||
| 26 | |||
| 27 | end | ||
diff --git a/vendor/plugins/paperclip/generators/paperclip/templates/paperclip_migration.rb.erb b/vendor/plugins/paperclip/generators/paperclip/templates/paperclip_migration.rb.erb new file mode 100644 index 0000000..eebb0e5 --- /dev/null +++ b/vendor/plugins/paperclip/generators/paperclip/templates/paperclip_migration.rb.erb | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | class <%= migration_name %> < ActiveRecord::Migration | ||
| 2 | def self.up | ||
| 3 | <% attachments.each do |attachment| -%> | ||
| 4 | add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name, :string | ||
| 5 | add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type, :string | ||
| 6 | add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size, :integer | ||
| 7 | add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at, :datetime | ||
| 8 | <% end -%> | ||
| 9 | end | ||
| 10 | |||
| 11 | def self.down | ||
| 12 | <% attachments.each do |attachment| -%> | ||
| 13 | remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name | ||
| 14 | remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type | ||
| 15 | remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size | ||
| 16 | remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at | ||
| 17 | <% end -%> | ||
| 18 | end | ||
| 19 | end | ||
