fetty-generators 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.rdoc +69 -0
- data/Rakefile +3 -0
- data/lib/generators/fetty/layout/USAGE +26 -0
- data/lib/generators/fetty/layout/layout_generator.rb +44 -0
- data/lib/generators/fetty/layout/templates/application.js +55 -0
- data/lib/generators/fetty/layout/templates/error_messages_helper.rb +23 -0
- data/lib/generators/fetty/layout/templates/layout.html.erb +32 -0
- data/lib/generators/fetty/layout/templates/layout.html.haml +34 -0
- data/lib/generators/fetty/layout/templates/layout_helper.rb +22 -0
- data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.erb +23 -0
- data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.haml +23 -0
- data/lib/generators/fetty/layout/templates/stylesheet.css +166 -0
- data/lib/generators/fetty/layout/templates/stylesheet.sass +163 -0
- data/lib/generators/fetty/scaffold/USAGE +53 -0
- data/lib/generators/fetty/scaffold/scaffold_generator.rb +370 -0
- data/lib/generators/fetty/scaffold/templates/actions/create.rb +8 -0
- data/lib/generators/fetty/scaffold/templates/actions/destroy.rb +5 -0
- data/lib/generators/fetty/scaffold/templates/actions/edit.rb +3 -0
- data/lib/generators/fetty/scaffold/templates/actions/index.rb +10 -0
- data/lib/generators/fetty/scaffold/templates/actions/new.rb +3 -0
- data/lib/generators/fetty/scaffold/templates/actions/show.rb +3 -0
- data/lib/generators/fetty/scaffold/templates/actions/update.rb +8 -0
- data/lib/generators/fetty/scaffold/templates/controller.rb +7 -0
- data/lib/generators/fetty/scaffold/templates/fixtures.yml +9 -0
- data/lib/generators/fetty/scaffold/templates/helper.rb +2 -0
- data/lib/generators/fetty/scaffold/templates/migration.rb +16 -0
- data/lib/generators/fetty/scaffold/templates/model.rb +7 -0
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/fetty/scaffold/templates/tests/rspec/controller.rb +8 -0
- data/lib/generators/fetty/scaffold/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/fetty/scaffold/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/fetty/scaffold/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/fetty/scaffold/templates/views/erb/_form.html.erb +22 -0
- data/lib/generators/fetty/scaffold/templates/views/erb/_table.html.erb +50 -0
- data/lib/generators/fetty/scaffold/templates/views/erb/edit.html.erb +12 -0
- data/lib/generators/fetty/scaffold/templates/views/erb/index.html.erb +13 -0
- data/lib/generators/fetty/scaffold/templates/views/erb/index.js.erb +1 -0
- data/lib/generators/fetty/scaffold/templates/views/erb/new.html.erb +9 -0
- data/lib/generators/fetty/scaffold/templates/views/erb/show.html.erb +26 -0
- data/lib/generators/fetty/scaffold/templates/views/haml/_form.html.haml +8 -0
- data/lib/generators/fetty/scaffold/templates/views/haml/_table.html.haml +33 -0
- data/lib/generators/fetty/scaffold/templates/views/haml/edit.html.haml +14 -0
- data/lib/generators/fetty/scaffold/templates/views/haml/index.html.haml +12 -0
- data/lib/generators/fetty/scaffold/templates/views/haml/index.js.haml +1 -0
- data/lib/generators/fetty/scaffold/templates/views/haml/new.html.haml +8 -0
- data/lib/generators/fetty/scaffold/templates/views/haml/show.html.haml +23 -0
- data/lib/generators/fetty/setup/USAGE +22 -0
- data/lib/generators/fetty/setup/setup_generator.rb +80 -0
- data/lib/generators/fetty/setup/templates/ability.rb +29 -0
- data/lib/generators/fetty.rb +38 -0
- metadata +137 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
$primary_color: #D0D0D0
|
|
2
|
+
|
|
3
|
+
body
|
|
4
|
+
background-color: $primary_color
|
|
5
|
+
font:
|
|
6
|
+
family: Verdana, Helvetica, Arial
|
|
7
|
+
size: 14px
|
|
8
|
+
|
|
9
|
+
a
|
|
10
|
+
color: blue
|
|
11
|
+
img
|
|
12
|
+
border: none
|
|
13
|
+
|
|
14
|
+
.clear
|
|
15
|
+
clear: both
|
|
16
|
+
height: 0
|
|
17
|
+
overflow: hidden
|
|
18
|
+
|
|
19
|
+
#container
|
|
20
|
+
width: 75%
|
|
21
|
+
margin: 0 auto
|
|
22
|
+
background: white
|
|
23
|
+
padding: 20px 40px
|
|
24
|
+
border: solid 1px black
|
|
25
|
+
margin-top: 20px
|
|
26
|
+
|
|
27
|
+
#flash_notice
|
|
28
|
+
background-color: #CCEECC
|
|
29
|
+
color: #006600
|
|
30
|
+
text-shadow: 1px 1px 1px #FFFFFF
|
|
31
|
+
|
|
32
|
+
#flash_error
|
|
33
|
+
background-color: #FFFFD7
|
|
34
|
+
color: #555555
|
|
35
|
+
text-shadow: 1px 1px 1px #FFFFFF
|
|
36
|
+
|
|
37
|
+
#flash_alert
|
|
38
|
+
background-color: #F7E1DF
|
|
39
|
+
color: #B81010
|
|
40
|
+
text-shadow: 1px 1px 1px #FCF4F3
|
|
41
|
+
|
|
42
|
+
.flash
|
|
43
|
+
border: 1px solid #D5D5D5
|
|
44
|
+
color: #555555
|
|
45
|
+
margin: 10px 0
|
|
46
|
+
padding: 10px
|
|
47
|
+
font
|
|
48
|
+
size: 13px
|
|
49
|
+
weight: bold
|
|
50
|
+
|
|
51
|
+
.closable
|
|
52
|
+
height: 16px
|
|
53
|
+
margin-top: -4px
|
|
54
|
+
opacity: 0.8
|
|
55
|
+
right: 8px
|
|
56
|
+
top: 15px
|
|
57
|
+
|
|
58
|
+
.closelink
|
|
59
|
+
cursor: pointer
|
|
60
|
+
float: right
|
|
61
|
+
height: 16px
|
|
62
|
+
margin-top: -4px
|
|
63
|
+
opacity: 0.8
|
|
64
|
+
right: 8px
|
|
65
|
+
top: 15px
|
|
66
|
+
|
|
67
|
+
.closelink:hover
|
|
68
|
+
opacity: 1
|
|
69
|
+
|
|
70
|
+
.fieldWithErrors
|
|
71
|
+
display: inline
|
|
72
|
+
|
|
73
|
+
.error_messages
|
|
74
|
+
width: 400px
|
|
75
|
+
border: 2px solid #cf0000
|
|
76
|
+
padding: 0
|
|
77
|
+
padding-bottom: 12px
|
|
78
|
+
margin-bottom: 20px
|
|
79
|
+
background-color: #f0f0f0
|
|
80
|
+
font:
|
|
81
|
+
size: 12px
|
|
82
|
+
h2
|
|
83
|
+
text-align: left
|
|
84
|
+
padding: 5px 5px 5px 15px
|
|
85
|
+
margin: 0
|
|
86
|
+
font:
|
|
87
|
+
weight: bold
|
|
88
|
+
size: 12px
|
|
89
|
+
background-color: #cc0000
|
|
90
|
+
color: white
|
|
91
|
+
p
|
|
92
|
+
margin: 8px 10px
|
|
93
|
+
ul
|
|
94
|
+
margin: 0
|
|
95
|
+
|
|
96
|
+
input.hint
|
|
97
|
+
color: #999
|
|
98
|
+
font
|
|
99
|
+
style :italic
|
|
100
|
+
|
|
101
|
+
#loginbox
|
|
102
|
+
float: right
|
|
103
|
+
|
|
104
|
+
table.pretty
|
|
105
|
+
border-collapse: collapse
|
|
106
|
+
|
|
107
|
+
.pretty td,
|
|
108
|
+
.pretty th
|
|
109
|
+
padding: 4px 10px
|
|
110
|
+
border: solid 1px #AAA
|
|
111
|
+
|
|
112
|
+
.simple_form
|
|
113
|
+
label
|
|
114
|
+
float: left
|
|
115
|
+
width: 100px
|
|
116
|
+
text-align: right
|
|
117
|
+
margin: 2px 10px
|
|
118
|
+
|
|
119
|
+
.simple_form
|
|
120
|
+
div.input
|
|
121
|
+
margin-bottom: 10px
|
|
122
|
+
|
|
123
|
+
.simple_form
|
|
124
|
+
div.boolean
|
|
125
|
+
margin-left: 120px
|
|
126
|
+
|
|
127
|
+
.simple_form
|
|
128
|
+
input[type='submit']
|
|
129
|
+
margin-left: 120px
|
|
130
|
+
|
|
131
|
+
.simple_form
|
|
132
|
+
div.boolean label
|
|
133
|
+
float: none
|
|
134
|
+
margin: 0
|
|
135
|
+
|
|
136
|
+
.simple_form
|
|
137
|
+
label.collection_radio
|
|
138
|
+
float: none
|
|
139
|
+
margin: 0
|
|
140
|
+
|
|
141
|
+
.simple_form
|
|
142
|
+
label.collection_radio
|
|
143
|
+
margin-right: 10px
|
|
144
|
+
margin-left: 2px
|
|
145
|
+
|
|
146
|
+
.simple_form
|
|
147
|
+
.error
|
|
148
|
+
clear: left
|
|
149
|
+
margin-left: 120px
|
|
150
|
+
font
|
|
151
|
+
size: 12px
|
|
152
|
+
color: #D00
|
|
153
|
+
display: block
|
|
154
|
+
|
|
155
|
+
.simple_form
|
|
156
|
+
.hint
|
|
157
|
+
clear: left
|
|
158
|
+
margin-left: 120px
|
|
159
|
+
font
|
|
160
|
+
size: 12px
|
|
161
|
+
style: italic
|
|
162
|
+
color: #555
|
|
163
|
+
display: block
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Scaffolds an entire resource, from model and migration to controller and
|
|
3
|
+
views. The resource is ready to use as a starting point for your restful,
|
|
4
|
+
resource-oriented application. Tests or specs are also generated depending
|
|
5
|
+
on if you have a "spec" directory or not.
|
|
6
|
+
|
|
7
|
+
IMPORTANT: This generator uses the "title" helper method which is generated
|
|
8
|
+
by the fetty-layout generator. You may want to run that generator first.
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
Pass the name of the model, either CamelCased or under_scored, as the first
|
|
12
|
+
argument along with an optional list of attribute pairs and controller actions.
|
|
13
|
+
|
|
14
|
+
If no controller actions are specified, they will default to index, show,
|
|
15
|
+
new, create, edit, update, and destroy.
|
|
16
|
+
|
|
17
|
+
IMPORTANT: If no attribute pairs are specified, no model will be generated.
|
|
18
|
+
It will try to determine the attributes from an existing model.
|
|
19
|
+
|
|
20
|
+
Attribute pairs are column_name:sql_type arguments specifying the
|
|
21
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
|
22
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
|
23
|
+
|
|
24
|
+
For example, `fetty:scaffold post name:string content:text hidden:boolean`
|
|
25
|
+
gives you a model with those three attributes, a controller that handles
|
|
26
|
+
the create/show/update/destroy, forms to create and edit your posts, and
|
|
27
|
+
an index that lists them all, as well as a resources :posts
|
|
28
|
+
declaration in config/routes.rb.
|
|
29
|
+
|
|
30
|
+
Adding an "!" in the mix of arguments will invert the passed controller
|
|
31
|
+
actions. This will include all 7 controller actitons except the ones
|
|
32
|
+
mentioned. This option doesn't affect model attributes.
|
|
33
|
+
|
|
34
|
+
Examples:
|
|
35
|
+
rails generate fetty:scaffold post
|
|
36
|
+
|
|
37
|
+
Will create a controller called "posts" it will contain all seven
|
|
38
|
+
CRUD actions along with the views. A model will NOT be created,
|
|
39
|
+
instead it will look for an existing model and use those attributes.
|
|
40
|
+
this command will also generate the views using simple-form, meta_search
|
|
41
|
+
and will_paginate in the index.html.erb/haml as a default.
|
|
42
|
+
|
|
43
|
+
rails generate fetty:scaffold post name:string content:text index new edit
|
|
44
|
+
|
|
45
|
+
Will create a Post model and migration file with the name and content
|
|
46
|
+
attributes. It will also create a controller with index, new, create,
|
|
47
|
+
edit, and update actions. Notice the create and update actions are
|
|
48
|
+
added automatically with new and edit.
|
|
49
|
+
|
|
50
|
+
rails generate fetty:scaffold post ! show new
|
|
51
|
+
|
|
52
|
+
Creates a posts controller (no model) with index, edit, update, and
|
|
53
|
+
destroy actions.
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
require 'generators/fetty'
|
|
2
|
+
require 'rails/generators/migration'
|
|
3
|
+
require 'rails/generators/generated_attribute'
|
|
4
|
+
|
|
5
|
+
module Fetty
|
|
6
|
+
module Generators
|
|
7
|
+
class ScaffoldGenerator < Base
|
|
8
|
+
include Rails::Generators::Migration
|
|
9
|
+
no_tasks { attr_accessor :scaffold_name, :model_attributes, :controller_actions }
|
|
10
|
+
|
|
11
|
+
argument :scaffold_name, :type => :string, :required => true, :banner => 'ModelName'
|
|
12
|
+
argument :args_for_c_m, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
|
|
13
|
+
|
|
14
|
+
class_option :skip_model, :desc => 'Don\'t generate a model or migration file.', :type => :boolean
|
|
15
|
+
class_option :skip_migration, :desc => 'Dont generate migration file for model.', :type => :boolean
|
|
16
|
+
class_option :skip_timestamps, :desc => 'Don\'t add timestamps to migration file.', :type => :boolean
|
|
17
|
+
class_option :skip_controller, :desc => 'Don\'t generate controller, helper, or views.', :type => :boolean
|
|
18
|
+
class_option :with_cancan_check, :desc => 'Generate your view with CanCan Checking abilities in every actions.', :type => :boolean, :default => true
|
|
19
|
+
class_option :invert, :desc => 'Generate all controller actions except these mentioned.', :type => :boolean
|
|
20
|
+
class_option :namespace_model, :desc => 'If the resource is namespaced, include the model in the namespace.', :type => :boolean
|
|
21
|
+
class_option :haml, :desc => 'Generate HAML views instead of ERB.', :type => :boolean
|
|
22
|
+
|
|
23
|
+
class_option :testunit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
|
|
24
|
+
class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
|
|
25
|
+
class_option :shoulda, :desc => 'Use shoulda for test files.', :group => 'Test framework', :type => :boolean
|
|
26
|
+
|
|
27
|
+
def initialize(*args, &block)
|
|
28
|
+
super
|
|
29
|
+
|
|
30
|
+
print_usage unless scaffold_name.underscore =~ /^[a-z][a-z0-9_\/]+$/
|
|
31
|
+
|
|
32
|
+
@controller_actions = []
|
|
33
|
+
@model_attributes = []
|
|
34
|
+
@skip_model = options.skip_model?
|
|
35
|
+
@namespace_model = options.namespace_model?
|
|
36
|
+
@invert_actions = options.invert?
|
|
37
|
+
|
|
38
|
+
@paperclip_name = []
|
|
39
|
+
@tinymce_name = []
|
|
40
|
+
|
|
41
|
+
args_for_c_m.each do |arg|
|
|
42
|
+
if arg == '!'
|
|
43
|
+
@invert_actions = true
|
|
44
|
+
elsif arg.include?(':')
|
|
45
|
+
if arg.include?(':paperclip')
|
|
46
|
+
@paperclip_name << arg.split(':').first
|
|
47
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new("#{arg.split(':').first}_file_name", "string")
|
|
48
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new("#{arg.split(':').first}_content_type", "string")
|
|
49
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new("#{arg.split(':').first}_file_size", "integer")
|
|
50
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new("#{arg.split(':').first}_updated_at", "datetime")
|
|
51
|
+
elsif arg.include?(':tinymce')
|
|
52
|
+
@tinymce_name << arg.split(':').first
|
|
53
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(arg.split(':').first, "text")
|
|
54
|
+
else
|
|
55
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
|
56
|
+
end
|
|
57
|
+
else
|
|
58
|
+
@controller_actions << arg
|
|
59
|
+
@controller_actions << 'create' if arg == 'new'
|
|
60
|
+
@controller_actions << 'update' if arg == 'edit'
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
@controller_actions.uniq!
|
|
65
|
+
@model_attributes.uniq!
|
|
66
|
+
|
|
67
|
+
if @invert_actions || @controller_actions.empty?
|
|
68
|
+
@controller_actions = all_actions - @controller_actions
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
if @model_attributes.empty?
|
|
72
|
+
@skip_model = true # skip model if no attributes
|
|
73
|
+
if model_exists?
|
|
74
|
+
model_columns_for_attributes.each do |column|
|
|
75
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
|
76
|
+
end
|
|
77
|
+
else
|
|
78
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def create_migration
|
|
84
|
+
unless @skip_model || options.skip_migration?
|
|
85
|
+
migration_template 'migration.rb', "db/migrate/create_#{model_path.pluralize.gsub('/', '_')}.rb"
|
|
86
|
+
delete_paperclip_field_from_model_attributes
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def create_model
|
|
91
|
+
unless @skip_model
|
|
92
|
+
template 'model.rb', "app/models/#{model_path}.rb"
|
|
93
|
+
if test_framework == :rspec
|
|
94
|
+
template "tests/rspec/model.rb", "spec/models/#{model_path}_spec.rb"
|
|
95
|
+
template 'fixtures.yml', "spec/fixtures/#{model_path.pluralize}.yml"
|
|
96
|
+
else
|
|
97
|
+
template "tests/#{test_framework}/model.rb", "test/unit/#{model_path}_test.rb"
|
|
98
|
+
template 'fixtures.yml', "test/fixtures/#{model_path.pluralize}.yml"
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def create_controller
|
|
104
|
+
unless options.skip_controller?
|
|
105
|
+
template 'controller.rb', "app/controllers/#{plural_name}_controller.rb"
|
|
106
|
+
|
|
107
|
+
template 'helper.rb', "app/helpers/#{plural_name}_helper.rb"
|
|
108
|
+
|
|
109
|
+
controller_actions.each do |action|
|
|
110
|
+
if %w[index show new edit].include?(action) # Actions with templates
|
|
111
|
+
template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
|
|
112
|
+
if action == 'index'
|
|
113
|
+
template "views/#{view_language}/_table.html.#{view_language}", "app/views/#{plural_name}/_table.html.#{view_language}"
|
|
114
|
+
template "views/#{view_language}/index.js.#{view_language}", "app/views/#{plural_name}/index.js.#{view_language}"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
if form_partial?
|
|
120
|
+
template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
namespaces = plural_name.split('/')
|
|
124
|
+
resource = namespaces.pop
|
|
125
|
+
route namespaces.reverse.inject("resources :#{resource}") { |acc, namespace|
|
|
126
|
+
"namespace(:#{namespace}){ #{acc} }"
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if test_framework == :rspec
|
|
130
|
+
template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
|
|
131
|
+
else
|
|
132
|
+
template "tests/#{test_framework}/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
private
|
|
138
|
+
|
|
139
|
+
def delete_paperclip_field_from_model_attributes
|
|
140
|
+
unless @paperclip_name.empty?
|
|
141
|
+
@paperclip_name.each do |name|
|
|
142
|
+
@model_attributes.delete_if do |a|
|
|
143
|
+
a.name == "#{name}_content_type" || a.name == "#{name}_updated_at" || a.name == "#{name}_file_size"
|
|
144
|
+
end
|
|
145
|
+
@model_attributes.map do |a|
|
|
146
|
+
if a.name == "#{name}_file_name"
|
|
147
|
+
a.name = name
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def generate_action_links(action, object, link_text, link_path)
|
|
155
|
+
out = ""
|
|
156
|
+
out << "\t<% if can? :#{action}, #{object} %>\n" if options.with_cancan_check?
|
|
157
|
+
unless action == :destroy
|
|
158
|
+
out << "\t\t<%= link_to '#{link_text}', #{link_path} %>\n"
|
|
159
|
+
else
|
|
160
|
+
out << "\t\t<%= link_to '#{link_text}', #{link_path}, :confirm => 'Are you sure?', :method => :delete %>\n"
|
|
161
|
+
end
|
|
162
|
+
out << "\t<% end %>" if options.with_cancan_check?
|
|
163
|
+
out.html_safe
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def form_partial?
|
|
167
|
+
actions? :new, :edit
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def all_actions
|
|
171
|
+
%w[index show new create edit update destroy]
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def action?(name)
|
|
175
|
+
controller_actions.include? name.to_s
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def actions?(*names)
|
|
179
|
+
names.all? { |name| action? name }
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def singular_table_name
|
|
183
|
+
scaffold_name.pluralize.singularize
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def singular_name
|
|
187
|
+
scaffold_name.underscore
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def plural_name
|
|
191
|
+
scaffold_name.underscore.pluralize
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def table_name
|
|
195
|
+
if scaffold_name.include?('::') && @namespace_model
|
|
196
|
+
plural_name.gsub('/', '_')
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def class_name
|
|
201
|
+
if @namespace_model
|
|
202
|
+
scaffold_name.camelize
|
|
203
|
+
else
|
|
204
|
+
scaffold_name.split('::').last.camelize
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def model_path
|
|
209
|
+
class_name.underscore
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def plural_class_name
|
|
213
|
+
plural_name.camelize
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def instance_name
|
|
217
|
+
if @namespace_model
|
|
218
|
+
singular_name.gsub('/','_')
|
|
219
|
+
else
|
|
220
|
+
singular_name.split('/').last
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def instances_name
|
|
225
|
+
instance_name.pluralize
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def controller_methods(dir_name)
|
|
229
|
+
controller_actions.map do |action|
|
|
230
|
+
read_template("#{dir_name}/#{action}.rb")
|
|
231
|
+
end.join("\n").strip
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def render_form
|
|
235
|
+
if form_partial?
|
|
236
|
+
if options.haml?
|
|
237
|
+
"= render 'form'"
|
|
238
|
+
else
|
|
239
|
+
"<%= render 'form' %>"
|
|
240
|
+
end
|
|
241
|
+
else
|
|
242
|
+
read_template("views/#{view_language}/_form.html.#{view_language}")
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def render_table
|
|
247
|
+
if options.haml?
|
|
248
|
+
"= render 'table'"
|
|
249
|
+
else
|
|
250
|
+
"<%= render 'table' %>"
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def item_resource
|
|
255
|
+
scaffold_name.underscore.gsub('/','_')
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def items_path
|
|
259
|
+
if action? :index
|
|
260
|
+
"#{item_resource.pluralize}_path"
|
|
261
|
+
else
|
|
262
|
+
"root_path"
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def item_path(options = {})
|
|
267
|
+
if action? :show
|
|
268
|
+
name = options[:instance_variable] ? "@#{instance_name}" : instance_name
|
|
269
|
+
if %w(new edit).include? options[:action].to_s
|
|
270
|
+
"#{options[:action].to_s}_#{item_resource}_path(#{name})"
|
|
271
|
+
else
|
|
272
|
+
if scaffold_name.include?('::') && !@namespace_model
|
|
273
|
+
namespace = singular_name.split('/')[0..-2]
|
|
274
|
+
"[ :#{namespace.join(', :')}, #{name} ]"
|
|
275
|
+
else
|
|
276
|
+
name
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
else
|
|
280
|
+
items_path
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def item_url
|
|
285
|
+
if action? :show
|
|
286
|
+
item_resource + '_url'
|
|
287
|
+
else
|
|
288
|
+
items_url
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def items_url
|
|
293
|
+
if action? :index
|
|
294
|
+
item_resource.pluralize + '_url'
|
|
295
|
+
else
|
|
296
|
+
"root_url"
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def item_path_for_spec(suffix = 'path')
|
|
301
|
+
if action? :show
|
|
302
|
+
"#{item_resource}_#{suffix}(assigns[:#{instance_name}])"
|
|
303
|
+
else
|
|
304
|
+
if suffix == 'path'
|
|
305
|
+
items_path
|
|
306
|
+
else
|
|
307
|
+
items_url
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def item_path_for_test(suffix = 'path')
|
|
313
|
+
if action? :show
|
|
314
|
+
"#{item_resource}_#{suffix}(assigns(:#{instance_name}))"
|
|
315
|
+
else
|
|
316
|
+
if suffix == 'path'
|
|
317
|
+
items_path
|
|
318
|
+
else
|
|
319
|
+
items_url
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def model_columns_for_attributes
|
|
325
|
+
class_name.constantize.columns.reject do |column|
|
|
326
|
+
column.name.to_s =~ /^(id|created_at|updated_at)$/
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def view_language
|
|
331
|
+
options.haml? ? 'haml' : 'erb'
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def test_framework
|
|
335
|
+
return @test_framework if defined?(@test_framework)
|
|
336
|
+
if options.testunit?
|
|
337
|
+
return @test_framework = :testunit
|
|
338
|
+
elsif options.rspec?
|
|
339
|
+
return @test_framework = :rspec
|
|
340
|
+
elsif options.shoulda?
|
|
341
|
+
return @test_framework = :shoulda
|
|
342
|
+
else
|
|
343
|
+
return @test_framework = default_test_framework
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
def default_test_framework
|
|
348
|
+
File.exist?(destination_path("spec")) ? :rspec : :testunit
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
def model_exists?
|
|
352
|
+
File.exist? destination_path("app/models/#{singular_name}.rb")
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
def read_template(relative_path)
|
|
356
|
+
ERB.new(File.read(find_in_source_paths(relative_path)), nil, '-').result(binding)
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# FIXME: Should be proxied to ActiveRecord::Generators::Base
|
|
360
|
+
# Implement the required interface for Rails::Generators::Migration.
|
|
361
|
+
def self.next_migration_number(dirname) #:nodoc:
|
|
362
|
+
if ActiveRecord::Base.timestamped_migrations
|
|
363
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
364
|
+
else
|
|
365
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
def create
|
|
2
|
+
@<%= instance_name %> = <%= class_name %>.new(params[:<%= instance_name %>])
|
|
3
|
+
if @<%= instance_name %>.save
|
|
4
|
+
redirect_to <%= items_url %>, :notice => "Successfully created <%= class_name.underscore.humanize.downcase %>."
|
|
5
|
+
else
|
|
6
|
+
render :action => 'new'
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
def index
|
|
2
|
+
@search = <%= class_name %>.search(params[:search])
|
|
3
|
+
@<%= instances_name %> = @search.paginate(:page => params[:page], :per_page => 10)
|
|
4
|
+
|
|
5
|
+
respond_to do |format|
|
|
6
|
+
format.html # index.html.erb
|
|
7
|
+
format.xml { render :xml => @<%= instances_name %> }
|
|
8
|
+
format.js
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
def update
|
|
2
|
+
@<%= instance_name %> = <%= class_name %>.find(params[:id])
|
|
3
|
+
if @<%= instance_name %>.update_attributes(params[:<%= instance_name %>])
|
|
4
|
+
redirect_to <%= items_url %>, :notice => "Successfully updated <%= class_name.underscore.humanize.downcase %>."
|
|
5
|
+
else
|
|
6
|
+
render :action => 'edit'
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
class <%= plural_class_name %>Controller < ApplicationController
|
|
2
|
+
<%- unless @tinymce_name.empty? -%>
|
|
3
|
+
uses_tiny_mce(:options => { :theme => 'advanced', :theme_advanced_resizing => true, :theme_advanced_resize_horizontal => false, :plugins => %w{ table fullscreen }}, :only => [:new, :edit])
|
|
4
|
+
<%- end -%>
|
|
5
|
+
|
|
6
|
+
<%= controller_methods :actions %>
|
|
7
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class Create<%= class_name.pluralize.delete('::') %> < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :<%= table_name || plural_name.split('/').last %> do |t|
|
|
4
|
+
<%- for attribute in model_attributes -%>
|
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
|
6
|
+
<%- end -%>
|
|
7
|
+
<%- unless options[:skip_timestamps] -%>
|
|
8
|
+
t.timestamps
|
|
9
|
+
<%- end -%>
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.down
|
|
14
|
+
drop_table :<%= table_name || plural_name.split('/').last %>
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
class <%= class_name %> < ActiveRecord::Base
|
|
2
|
+
<%= "set_table_name :#{table_name}\n" if table_name -%>
|
|
3
|
+
<%- unless @paperclip_name.empty? -%>
|
|
4
|
+
has_attached_file <%= @paperclip_name.map { |name| ":#{name}" }.join(", ") %>
|
|
5
|
+
<%- end -%>
|
|
6
|
+
attr_accessible <%= model_attributes.map { |a| ":#{a.name}" }.join(", ") %>
|
|
7
|
+
end
|