Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
43cbf829
Commit
43cbf829
authored
May 17, 2010
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved generators to lib/generators which is picked up by rails3
parent
08f837f5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
52 deletions
+64
-52
generators/paperclip/USAGE
+0
-6
generators/paperclip/paperclip_generator.rb
+0
-27
generators/paperclip/templates/paperclip_migration.rb.erb
+0
-19
lib/generators/paperclip/USAGE
+8
-0
lib/generators/paperclip/paperclip_generator.rb
+37
-0
lib/generators/paperclip/templates/paperclip_migration.rb.erb
+19
-0
No files found.
generators/paperclip/USAGE
deleted
100644 → 0
View file @
08f837f5
Usage:
script/generate paperclip Class attachment1 (attachment2 ...)
This will create a migration that will add the proper columns to your class's table.
\ No newline at end of file
generators/paperclip/paperclip_generator.rb
deleted
100644 → 0
View file @
08f837f5
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
generators/paperclip/templates/paperclip_migration.rb.erb
deleted
100644 → 0
View file @
08f837f5
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
lib/generators/paperclip/USAGE
0 → 100644
View file @
43cbf829
Description:
Explain the generator
Example:
rails generate paperclip Thing
This will create:
what/will/it/create
lib/generators/paperclip/paperclip_generator.rb
0 → 100644
View file @
43cbf829
class
PaperclipGenerator
<
Rails
::
Generators
::
Base
include
Rails
::
Generators
::
Migration
desc
"Create a migration to add paperclip-specific fields to your model."
argument
:attachment_class
,
:required
=>
true
,
:type
=>
:string
,
:desc
=>
"The class to migrate."
,
:banner
=>
"ClassName"
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_
#{
attachment_class
.
underscore
}
"
end
def
migration_file_name
"
#{
migration_name
}
.rb"
end
def
migration_class_name
migration_name
.
camelize
end
def
self
.
next_migration_number
(
dirname
)
#:nodoc:
Time
.
now
.
strftime
(
"%Y%m%d%H%M%S"
)
end
end
lib/generators/paperclip/templates/paperclip_migration.rb.erb
0 → 100644
View file @
43cbf829
class
<%=
migration_class_name
%>
<
ActiveRecord::Migration
def
self
.
up
<%
attachment_names
.
each
do
|
attachment
|
-%>
add_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
,
:string
add_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_content_type
,
:string
add_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_size
,
:integer
add_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_updated_at
,
:datetime
<%
end
-%>
end
def
self
.
down
<%
attachment_names
.
each
do
|
attachment
|
-%>
remove_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
remove_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_content_type
remove_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_size
remove_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_updated_at
<%
end
-%>
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment