rotten-generators 0.9.0
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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +10 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/cucumber.yml +1 -0
- data/features/rotten.feature +9 -0
- data/features/step_definitions/rotten_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/generators.gemspec +126 -0
- data/lib/rotten_generators.rb +3 -0
- data/rails_generators/rotten_authentication/lib/insert_commands.rb +74 -0
- data/rails_generators/rotten_authentication/rotten_authentication_generator.rb +102 -0
- data/rails_generators/rotten_authentication/templates/authentication.rb +37 -0
- data/rails_generators/rotten_authentication/templates/fixtures.yml +12 -0
- data/rails_generators/rotten_authentication/templates/migration.rb +15 -0
- data/rails_generators/rotten_authentication/templates/sessions_controller.rb +22 -0
- data/rails_generators/rotten_authentication/templates/sessions_helper.rb +2 -0
- data/rails_generators/rotten_authentication/templates/tests/rspec/sessions_controller.rb +25 -0
- data/rails_generators/rotten_authentication/templates/tests/rspec/user.rb +81 -0
- data/rails_generators/rotten_authentication/templates/tests/rspec/users_controller.rb +24 -0
- data/rails_generators/rotten_authentication/templates/user.rb +38 -0
- data/rails_generators/rotten_authentication/templates/users_controller.rb +16 -0
- data/rails_generators/rotten_authentication/templates/users_helper.rb +2 -0
- data/rails_generators/rotten_authentication/templates/views/haml/login.html.haml +15 -0
- data/rails_generators/rotten_authentication/templates/views/haml/signup.html.haml +24 -0
- data/rails_generators/rotten_controller/rotten_controller_generator.rb +52 -0
- data/rails_generators/rotten_controller/templates/controller.rb +38 -0
- data/rails_generators/rotten_controller/templates/controller_spec.rb +25 -0
- data/rails_generators/rotten_controller/templates/helper.rb +2 -0
- data/rails_generators/rotten_controller/templates/helper_spec.rb +11 -0
- data/rails_generators/rotten_controller/templates/view.html.haml +2 -0
- data/rails_generators/rotten_controller/templates/view_spec.rb +12 -0
- data/rails_generators/rotten_layout/USAGE +1 -0
- data/rails_generators/rotten_layout/rotten_layout_generator.rb +63 -0
- data/rails_generators/rotten_layout/templates/helper.rb +30 -0
- data/rails_generators/rotten_layout/templates/js/jquery-1.3.2.min.js +19 -0
- data/rails_generators/rotten_layout/templates/js/jquery-ui-1.7.2.min.js +298 -0
- data/rails_generators/rotten_layout/templates/layout.html.haml +45 -0
- data/rails_generators/rotten_layout/templates/one_column.html.haml +11 -0
- data/rails_generators/rotten_layout/templates/sass/colour.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/form.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/handheld.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/ie.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/layout.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/print.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/reset.sass +137 -0
- data/rails_generators/rotten_layout/templates/sass/screen.sass +5 -0
- data/rails_generators/rotten_layout/templates/sass/type.sass +1 -0
- data/rails_generators/rotten_layout/templates/shared_analytics.html.haml +10 -0
- data/rails_generators/rotten_layout/templates/shared_flash_messages.html.haml +12 -0
- data/rails_generators/rotten_layout/templates/shared_footer.html.haml +15 -0
- data/rails_generators/rotten_layout/templates/shared_header.html.haml +5 -0
- data/rails_generators/rotten_layout/templates/shared_navigation.html.haml +3 -0
- data/rails_generators/rotten_layout/templates/shared_sidebar.html.haml +13 -0
- data/rails_generators/rotten_layout/templates/two_column_left.html.haml +15 -0
- data/rails_generators/rotten_layout/templates/two_column_right.html.haml +14 -0
- data/rails_generators/rotten_scaffold/USAGE +48 -0
- data/rails_generators/rotten_scaffold/rotten_scaffold_generator.rb +204 -0
- data/rails_generators/rotten_scaffold/templates/actions/create.rb +9 -0
- data/rails_generators/rotten_scaffold/templates/actions/destroy.rb +6 -0
- data/rails_generators/rotten_scaffold/templates/actions/edit.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/actions/index.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/actions/new.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/actions/show.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/actions/update.rb +9 -0
- data/rails_generators/rotten_scaffold/templates/controller.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/fixtures.yml +9 -0
- data/rails_generators/rotten_scaffold/templates/helper.rb +2 -0
- data/rails_generators/rotten_scaffold/templates/migration.rb +16 -0
- data/rails_generators/rotten_scaffold/templates/model.rb +2 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/controller.rb +8 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/model.rb +7 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/_form.html.haml +14 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/edit.html.haml +14 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/index.html.haml +25 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/new.html.haml +7 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/show.html.haml +20 -0
- data/spec/rotten_spec.rb +7 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +9 -0
- metadata +143 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
- content_for :layout_name, "one_column"
|
|
2
|
+
- content_for :content do
|
|
3
|
+
= render :partial => "shared/flash_messages"
|
|
4
|
+
.main
|
|
5
|
+
.content
|
|
6
|
+
- if show_title?
|
|
7
|
+
%h2=h yield(:title)
|
|
8
|
+
= yield(:one_column_content) || yield
|
|
9
|
+
|
|
10
|
+
= render :file => 'layouts/application'
|
|
11
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
//
|
|
2
|
+
=============================================================================
|
|
3
|
+
|
|
4
|
+
R E S E T . S A S S
|
|
5
|
+
-----------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
html
|
|
9
|
+
:color #000
|
|
10
|
+
:background #FFF
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
body, div, dl, dt, dd, ul, ol
|
|
14
|
+
:margin 0
|
|
15
|
+
:padding 0
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
li
|
|
19
|
+
:margin 0
|
|
20
|
+
:padding 0
|
|
21
|
+
:list-style none
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
h1, h2, h3, h4, h5, h6
|
|
25
|
+
:margin 0
|
|
26
|
+
:padding 0
|
|
27
|
+
:font-size 100%
|
|
28
|
+
:font-weight normal
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
pre
|
|
32
|
+
:margin 0
|
|
33
|
+
:padding 0
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
code
|
|
37
|
+
:margin 0
|
|
38
|
+
:padding 0
|
|
39
|
+
:font-style normal
|
|
40
|
+
:font-weight normal
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
form
|
|
44
|
+
:margin 0
|
|
45
|
+
:padding 0
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
fieldset
|
|
49
|
+
:margin 0
|
|
50
|
+
:padding 0
|
|
51
|
+
:border 0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
legend
|
|
55
|
+
:margin 0
|
|
56
|
+
:padding 0
|
|
57
|
+
:color #000
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
input, textarea
|
|
61
|
+
:margin 0
|
|
62
|
+
:padding 0
|
|
63
|
+
:font-family inherit
|
|
64
|
+
:font-size inherit
|
|
65
|
+
:font-weight inherit
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
p, blockquote
|
|
69
|
+
:margin 0
|
|
70
|
+
:padding 0
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
th
|
|
74
|
+
:margin 0
|
|
75
|
+
:padding 0
|
|
76
|
+
:font-style normal
|
|
77
|
+
:font-weight normal
|
|
78
|
+
:text-align left
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
td
|
|
82
|
+
:margin 0
|
|
83
|
+
:padding 0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
table
|
|
87
|
+
:border-collapse collapse
|
|
88
|
+
:border-spacing 0
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
img
|
|
92
|
+
:border 0
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
address
|
|
96
|
+
:font-style normal
|
|
97
|
+
:font-weight normal
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
caption
|
|
101
|
+
:font-style normal
|
|
102
|
+
:font-weight normal
|
|
103
|
+
:text-align left
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
cite, dfn, em, strong, var
|
|
107
|
+
:font-style normal
|
|
108
|
+
:font-weight normal
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
q
|
|
112
|
+
&:before, &:after
|
|
113
|
+
:content ''
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
abbr, acronym
|
|
117
|
+
:border 0
|
|
118
|
+
:font-variant normal
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
sup
|
|
122
|
+
:vertical-align text-top
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
sub
|
|
126
|
+
:vertical-align text-bottom
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
select
|
|
130
|
+
:font-family inherit
|
|
131
|
+
:font-size inherit
|
|
132
|
+
:font-weight inherit
|
|
133
|
+
&:before,
|
|
134
|
+
&:after
|
|
135
|
+
:content ""
|
|
136
|
+
|
|
137
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
- if ENV['RAILS_ENV'] == 'production'
|
|
2
|
+
:javascript
|
|
3
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
|
4
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
|
5
|
+
|
|
6
|
+
:javascript
|
|
7
|
+
try {
|
|
8
|
+
var pageTracker = _gat._getTracker("UA-231207-?");
|
|
9
|
+
pageTracker._trackPageview();
|
|
10
|
+
} catch(err) {}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
%ul#navigation
|
|
2
|
+
%li#links
|
|
3
|
+
%ul
|
|
4
|
+
%li= link_to "Help/Support"
|
|
5
|
+
%li.last= link_to "Feedback"
|
|
6
|
+
%li#info
|
|
7
|
+
%ul
|
|
8
|
+
%li#copyright Copyright © 2009 Peter Coulton
|
|
9
|
+
%li#version= version
|
|
10
|
+
%li#validators
|
|
11
|
+
= link_to image_tag("http://www.w3.org/Icons/valid-xhtml10-blue", :alt => "Valid XHTML 1.0 Strict" ), "http://validator.w3.org/check?uri=referer"
|
|
12
|
+
= link_to image_tag("http://jigsaw.w3.org/css-validator/images/vcss-blue", :alt => "Valid CSS!" ), "http://jigsaw.w3.org/css-validator/check/referer"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
- unless yield(:sidebar)
|
|
2
|
+
:maruku
|
|
3
|
+
### Sidebar
|
|
4
|
+
|
|
5
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
|
|
6
|
+
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
|
7
|
+
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
|
|
8
|
+
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
9
|
+
nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa
|
|
10
|
+
qui officia deserunt mollit anim id est laborum.
|
|
11
|
+
|
|
12
|
+
- else
|
|
13
|
+
= yield(:sidebar)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
- content_for :layout_name, "two_column_right"
|
|
2
|
+
- content_for :content do
|
|
3
|
+
= render :partial => "shared/flash_messages"
|
|
4
|
+
.main
|
|
5
|
+
.content
|
|
6
|
+
- if show_title?
|
|
7
|
+
%h2=h yield(:title)
|
|
8
|
+
= yield(:two_column_content) || yield
|
|
9
|
+
|
|
10
|
+
.sidebar
|
|
11
|
+
.content
|
|
12
|
+
= render :partial => "shared/sidebar"
|
|
13
|
+
|
|
14
|
+
= render :file => 'layouts/application'
|
|
15
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
- content_for :layout_name, "two_column_left"
|
|
2
|
+
- content_for :content do
|
|
3
|
+
= render :partial => "shared/flash_messages"
|
|
4
|
+
.main
|
|
5
|
+
.content
|
|
6
|
+
- if show_title?
|
|
7
|
+
%h2=h yield(:title)
|
|
8
|
+
= yield(:two_column_content) || yield
|
|
9
|
+
|
|
10
|
+
.sidebar
|
|
11
|
+
.content
|
|
12
|
+
= render :partial => "shared/sidebar"
|
|
13
|
+
|
|
14
|
+
= render :file => 'layouts/application'
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
Usage:
|
|
8
|
+
Pass the name of the model, either CamelCased or under_scored, as the first
|
|
9
|
+
argument, and an optional list of attribute pairs and controller actions.
|
|
10
|
+
|
|
11
|
+
If no controller actions are specified, they will default to index, show,
|
|
12
|
+
new, create, edit, update, and destroy.
|
|
13
|
+
|
|
14
|
+
IMPORTANT: If no attribute pairs are specified, no model will be generated.
|
|
15
|
+
It will try to determine the attributes from an existing model.
|
|
16
|
+
|
|
17
|
+
Attribute pairs are column_name:sql_type arguments specifying the
|
|
18
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
|
19
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
|
20
|
+
|
|
21
|
+
For example, `rotten_scaffold post name:string content:text hidden:boolean`
|
|
22
|
+
gives you a model with those three attributes, a controller that handles
|
|
23
|
+
the create/show/update/destroy, forms to create and edit your posts, and
|
|
24
|
+
an index that lists them all, as well as a map.resources :posts
|
|
25
|
+
declaration in config/routes.rb.
|
|
26
|
+
|
|
27
|
+
Adding an "!" in the mix of arguments will invert the passed controller
|
|
28
|
+
actions. This will include all 7 controller actitons except the ones
|
|
29
|
+
mentioned. This option doesn't effect model attributes.
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
script/generate rotten_scaffold post
|
|
33
|
+
|
|
34
|
+
Will create a controller called "posts" it will contain all seven
|
|
35
|
+
CRUD actions along with the views. A model will NOT be created,
|
|
36
|
+
instead it will look for an existing model and use those attributes.
|
|
37
|
+
|
|
38
|
+
script/generate rotten_scaffold post name:string content:text index new edit
|
|
39
|
+
|
|
40
|
+
Will create a Post model and migration file with the name and content
|
|
41
|
+
attributes. It will also create a controller with index, new, create,
|
|
42
|
+
edit, and update actions. Notice the create and update actions are
|
|
43
|
+
added automatically with new and edit.
|
|
44
|
+
|
|
45
|
+
script/generate rotten_scaffold post ! show new
|
|
46
|
+
|
|
47
|
+
Creates a posts controller (no model) with index, edit, update, and
|
|
48
|
+
destroy actions.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
class RottenScaffoldGenerator < Rails::Generator::Base
|
|
2
|
+
attr_accessor :name, :attributes, :controller_actions
|
|
3
|
+
|
|
4
|
+
def initialize(runtime_args, runtime_options = {})
|
|
5
|
+
super
|
|
6
|
+
usage if @args.empty?
|
|
7
|
+
|
|
8
|
+
@name = @args.first
|
|
9
|
+
@controller_actions = []
|
|
10
|
+
@attributes = []
|
|
11
|
+
|
|
12
|
+
@args[1..-1].each do |arg|
|
|
13
|
+
if arg == '!'
|
|
14
|
+
options[:invert] = true
|
|
15
|
+
elsif arg.include? ':'
|
|
16
|
+
@attributes << Rails::Generator::GeneratedAttribute.new(*arg.split(":"))
|
|
17
|
+
else
|
|
18
|
+
@controller_actions << arg
|
|
19
|
+
@controller_actions << 'create' if arg == 'new'
|
|
20
|
+
@controller_actions << 'update' if arg == 'edit'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
@controller_actions.uniq!
|
|
25
|
+
@attributes.uniq!
|
|
26
|
+
|
|
27
|
+
if options[:invert] || @controller_actions.empty?
|
|
28
|
+
@controller_actions = all_actions - @controller_actions
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if @attributes.empty?
|
|
32
|
+
options[:skip_model] = true # default to skipping model if no attributes passed
|
|
33
|
+
if model_exists?
|
|
34
|
+
model_columns_for_attributes.each do |column|
|
|
35
|
+
@attributes << Rails::Generator::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
|
36
|
+
end
|
|
37
|
+
else
|
|
38
|
+
@attributes << Rails::Generator::GeneratedAttribute.new('name', 'string')
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def manifest
|
|
44
|
+
record do |m|
|
|
45
|
+
unless options[:skip_model]
|
|
46
|
+
m.directory "app/models"
|
|
47
|
+
m.template "model.rb", "app/models/#{singular_name}.rb"
|
|
48
|
+
unless options[:skip_migration]
|
|
49
|
+
m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{plural_name}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
m.directory "spec/models"
|
|
53
|
+
m.template "tests/#{test_framework}/model.rb", "spec/models/#{singular_name}_spec.rb"
|
|
54
|
+
m.directory "spec/fixtures"
|
|
55
|
+
m.template "fixtures.yml", "spec/fixtures/#{plural_name}.yml"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
unless options[:skip_controller]
|
|
59
|
+
m.directory "app/controllers"
|
|
60
|
+
m.template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
|
|
61
|
+
|
|
62
|
+
m.directory "app/helpers"
|
|
63
|
+
m.template "helper.rb", "app/helpers/#{plural_name}_helper.rb"
|
|
64
|
+
|
|
65
|
+
m.directory "app/views/#{plural_name}"
|
|
66
|
+
controller_actions.each do |action|
|
|
67
|
+
if File.exist? source_path("views/#{view_language}/#{action}.html.#{view_language}")
|
|
68
|
+
m.template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
if form_partial?
|
|
73
|
+
m.template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
m.route_resources plural_name
|
|
77
|
+
|
|
78
|
+
m.directory "spec/controllers"
|
|
79
|
+
m.template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def form_partial?
|
|
85
|
+
actions? :new, :edit
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def all_actions
|
|
89
|
+
%w[index show new create edit update destroy]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def action?(name)
|
|
93
|
+
controller_actions.include? name.to_s
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def actions?(*names)
|
|
97
|
+
names.all? { |n| action? n.to_s }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def singular_name
|
|
101
|
+
name.underscore
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def plural_name
|
|
105
|
+
name.underscore.pluralize
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def class_name
|
|
109
|
+
name.camelize
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def plural_class_name
|
|
113
|
+
plural_name.camelize
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def controller_methods(dir_name)
|
|
117
|
+
controller_actions.map do |action|
|
|
118
|
+
read_template("#{dir_name}/#{action}.rb")
|
|
119
|
+
end.join(" \n").strip
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def render_form
|
|
123
|
+
if form_partial?
|
|
124
|
+
"= render :partial => 'form'"
|
|
125
|
+
else
|
|
126
|
+
read_template("views/#{view_language}/_form.html.#{view_language}")
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def item_path(suffix = 'path')
|
|
131
|
+
if action? :show
|
|
132
|
+
"@#{singular_name}"
|
|
133
|
+
else
|
|
134
|
+
"#{plural_name}_#{suffix}"
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def item_path_for_spec(suffix = 'path')
|
|
139
|
+
if action? :show
|
|
140
|
+
"#{singular_name}_#{suffix}(assigns[:#{singular_name}])"
|
|
141
|
+
else
|
|
142
|
+
"#{plural_name}_#{suffix}"
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def item_path_for_test(suffix = 'path')
|
|
147
|
+
if action? :show
|
|
148
|
+
"#{singular_name}_#{suffix}(assigns(:#{singular_name}))"
|
|
149
|
+
else
|
|
150
|
+
"#{plural_name}_#{suffix}"
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def model_columns_for_attributes
|
|
155
|
+
class_name.constantize.columns.reject do |column|
|
|
156
|
+
column.name.to_s =~ /^(id|created_at|updated_at)$/
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def rspec?
|
|
161
|
+
test_framework == :rspec
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
protected
|
|
165
|
+
|
|
166
|
+
def view_language
|
|
167
|
+
'haml'
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def test_framework
|
|
171
|
+
options[:test_framework] ||= default_test_framework
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def default_test_framework
|
|
175
|
+
:rspec
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def add_options!(opt)
|
|
179
|
+
opt.separator ''
|
|
180
|
+
opt.separator 'Options:'
|
|
181
|
+
opt.on("--skip-model", "Don't generate a model or migration file.") { |v| options[:skip_model] = v }
|
|
182
|
+
opt.on("--skip-migration", "Don't generate migration file for model.") { |v| options[:skip_migration] = v }
|
|
183
|
+
opt.on("--skip-timestamps", "Don't add timestamps to migration file.") { |v| options[:skip_timestamps] = v }
|
|
184
|
+
opt.on("--skip-controller", "Don't generate controller, helper, or views.") { |v| options[:skip_controller] = v }
|
|
185
|
+
opt.on("--invert", "Generate all controller actions except these mentioned.") { |v| options[:invert] = v }
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# is there a better way to do this? Perhaps with const_defined?
|
|
189
|
+
def model_exists?
|
|
190
|
+
File.exist? destination_path("app/models/#{singular_name}.rb")
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def read_template(relative_path)
|
|
194
|
+
ERB.new(File.read(source_path(relative_path)), nil, '-').result(binding)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def banner
|
|
198
|
+
<<-EOS
|
|
199
|
+
Creates a controller and optional model given the name, actions, and attributes.
|
|
200
|
+
|
|
201
|
+
USAGE: #{$0} #{spec.name} ModelName [controller_actions and model:attributes] [options]
|
|
202
|
+
EOS
|
|
203
|
+
end
|
|
204
|
+
end
|