xenda-nifty-generators 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/CHANGELOG +105 -0
  2. data/LICENSE +20 -0
  3. data/Manifest +104 -0
  4. data/README.rdoc +14 -0
  5. data/Rakefile +15 -0
  6. data/TODO +7 -0
  7. data/lib/nifty_generators.rb +3 -0
  8. data/nifty-generators.gemspec +31 -0
  9. data/rails_generators/nifty_authentication/USAGE +50 -0
  10. data/rails_generators/nifty_authentication/lib/insert_commands.rb +74 -0
  11. data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +128 -0
  12. data/rails_generators/nifty_authentication/templates/authentication.rb +61 -0
  13. data/rails_generators/nifty_authentication/templates/authlogic_session.rb +2 -0
  14. data/rails_generators/nifty_authentication/templates/fixtures.yml +24 -0
  15. data/rails_generators/nifty_authentication/templates/migration.rb +20 -0
  16. data/rails_generators/nifty_authentication/templates/sessions_controller.rb +45 -0
  17. data/rails_generators/nifty_authentication/templates/sessions_helper.rb +2 -0
  18. data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  19. data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +83 -0
  20. data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +26 -0
  21. data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  22. data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +85 -0
  23. data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +27 -0
  24. data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  25. data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +88 -0
  26. data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +23 -0
  27. data/rails_generators/nifty_authentication/templates/user.rb +42 -0
  28. data/rails_generators/nifty_authentication/templates/users_controller.rb +18 -0
  29. data/rails_generators/nifty_authentication/templates/users_helper.rb +2 -0
  30. data/rails_generators/nifty_authentication/templates/views/erb/login.html.erb +30 -0
  31. data/rails_generators/nifty_authentication/templates/views/erb/signup.html.erb +24 -0
  32. data/rails_generators/nifty_authentication/templates/views/haml/login.html.haml +30 -0
  33. data/rails_generators/nifty_authentication/templates/views/haml/signup.html.haml +24 -0
  34. data/rails_generators/nifty_config/USAGE +23 -0
  35. data/rails_generators/nifty_config/nifty_config_generator.rb +32 -0
  36. data/rails_generators/nifty_config/templates/config.yml +8 -0
  37. data/rails_generators/nifty_config/templates/load_config.rb +2 -0
  38. data/rails_generators/nifty_layout/USAGE +25 -0
  39. data/rails_generators/nifty_layout/nifty_layout_generator.rb +44 -0
  40. data/rails_generators/nifty_layout/templates/helper.rb +22 -0
  41. data/rails_generators/nifty_layout/templates/layout.html.erb +22 -0
  42. data/rails_generators/nifty_layout/templates/layout.html.haml +19 -0
  43. data/rails_generators/nifty_layout/templates/stylesheet.css +81 -0
  44. data/rails_generators/nifty_layout/templates/stylesheet.sass +67 -0
  45. data/rails_generators/nifty_scaffold/USAGE +51 -0
  46. data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +243 -0
  47. data/rails_generators/nifty_scaffold/templates/actions/create.rb +9 -0
  48. data/rails_generators/nifty_scaffold/templates/actions/destroy.rb +6 -0
  49. data/rails_generators/nifty_scaffold/templates/actions/edit.rb +3 -0
  50. data/rails_generators/nifty_scaffold/templates/actions/index.rb +7 -0
  51. data/rails_generators/nifty_scaffold/templates/actions/new.rb +3 -0
  52. data/rails_generators/nifty_scaffold/templates/actions/show.rb +3 -0
  53. data/rails_generators/nifty_scaffold/templates/actions/update.rb +9 -0
  54. data/rails_generators/nifty_scaffold/templates/controller.rb +3 -0
  55. data/rails_generators/nifty_scaffold/templates/fixtures.yml +9 -0
  56. data/rails_generators/nifty_scaffold/templates/helper.rb +2 -0
  57. data/rails_generators/nifty_scaffold/templates/inherited_resources_controller.rb +10 -0
  58. data/rails_generators/nifty_scaffold/templates/migration.rb +16 -0
  59. data/rails_generators/nifty_scaffold/templates/model.rb +3 -0
  60. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  61. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  62. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  63. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  64. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  65. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  66. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  67. data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +8 -0
  68. data/rails_generators/nifty_scaffold/templates/tests/rspec/model.rb +7 -0
  69. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  70. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  71. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  72. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  73. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  74. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  75. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  76. data/rails_generators/nifty_scaffold/templates/tests/shoulda/controller.rb +5 -0
  77. data/rails_generators/nifty_scaffold/templates/tests/shoulda/model.rb +7 -0
  78. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  79. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  80. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  81. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  82. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  83. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  84. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  85. data/rails_generators/nifty_scaffold/templates/tests/testunit/controller.rb +5 -0
  86. data/rails_generators/nifty_scaffold/templates/tests/testunit/model.rb +7 -0
  87. data/rails_generators/nifty_scaffold/templates/views/erb/_fields.html.erb +10 -0
  88. data/rails_generators/nifty_scaffold/templates/views/erb/_form.html.erb +10 -0
  89. data/rails_generators/nifty_scaffold/templates/views/erb/edit.html.erb +14 -0
  90. data/rails_generators/nifty_scaffold/templates/views/erb/index.html.erb +31 -0
  91. data/rails_generators/nifty_scaffold/templates/views/erb/new.html.erb +7 -0
  92. data/rails_generators/nifty_scaffold/templates/views/erb/show.html.erb +20 -0
  93. data/rails_generators/nifty_scaffold/templates/views/haml/_fields.html.haml +7 -0
  94. data/rails_generators/nifty_scaffold/templates/views/haml/_form.html.haml +8 -0
  95. data/rails_generators/nifty_scaffold/templates/views/haml/edit.html.haml +14 -0
  96. data/rails_generators/nifty_scaffold/templates/views/haml/index.html.haml +28 -0
  97. data/rails_generators/nifty_scaffold/templates/views/haml/new.html.haml +7 -0
  98. data/rails_generators/nifty_scaffold/templates/views/haml/show.html.haml +20 -0
  99. data/tasks/deployment.rake +2 -0
  100. data/test/test_helper.rb +117 -0
  101. data/test/test_nifty_authentication_generator.rb +236 -0
  102. data/test/test_nifty_config_generator.rb +37 -0
  103. data/test/test_nifty_layout_generator.rb +42 -0
  104. data/test/test_nifty_scaffold_generator.rb +534 -0
  105. data/xenda-nifty-generators.gemspec +31 -0
  106. metadata +173 -0
@@ -0,0 +1,22 @@
1
+ # These helper methods can be called in your template to set variables to be used in the layout
2
+ # This module should be included in all views globally,
3
+ # to do so you may need to add this line to your ApplicationController
4
+ # helper :layout
5
+ module LayoutHelper
6
+ def title(page_title, show_title = true)
7
+ @content_for_title = page_title.to_s
8
+ @show_title = show_title
9
+ end
10
+
11
+ def show_title?
12
+ @show_title
13
+ end
14
+
15
+ def stylesheet(*args)
16
+ content_for(:head) { stylesheet_link_tag(*args) }
17
+ end
18
+
19
+ def javascript(*args)
20
+ content_for(:head) { javascript_include_tag(*args) }
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html>
4
+ <head>
5
+ <title><%%= h(yield(:title) || "Untitled") %></title>
6
+ <%%= stylesheet_link_tag '<%= file_name %>' %>
7
+ <%%= yield(:head) %>
8
+ </head>
9
+ <body>
10
+ <div id="container">
11
+ <%%- flash.each do |name, msg| -%>
12
+ <%%= content_tag :div, msg, :id => "flash_#{name}" %>
13
+ <%%- end -%>
14
+
15
+ <%%- if show_title? -%>
16
+ <h1><%%=h yield(:title) %></h1>
17
+ <%%- end -%>
18
+
19
+ <%%= yield %>
20
+ </div>
21
+ </body>
22
+ </html>
@@ -0,0 +1,19 @@
1
+ !!! Strict
2
+ %html{html_attrs}
3
+
4
+ %head
5
+ %title
6
+ = h(yield(:title) || "Untitled")
7
+ %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
8
+ = stylesheet_link_tag '<%= file_name %>'
9
+ = yield(:head)
10
+
11
+ %body
12
+ #container
13
+ - flash.each do |name, msg|
14
+ = content_tag :div, msg, :id => "flash_#{name}"
15
+
16
+ - if show_title?
17
+ %h1=h yield(:title)
18
+
19
+ = yield
@@ -0,0 +1,81 @@
1
+ body {
2
+ background-color: #4B7399;
3
+ font-family: Verdana, Helvetica, Arial;
4
+ font-size: 14px;
5
+ }
6
+
7
+ a img {
8
+ border: none;
9
+ }
10
+
11
+ a {
12
+ color: #0000FF;
13
+ }
14
+
15
+ .clear {
16
+ clear: both;
17
+ height: 0;
18
+ overflow: hidden;
19
+ }
20
+
21
+ #container {
22
+ width: 75%;
23
+ margin: 0 auto;
24
+ background-color: #FFF;
25
+ padding: 20px 40px;
26
+ border: solid 1px black;
27
+ margin-top: 20px;
28
+ }
29
+
30
+ #flash_notice, #flash_error {
31
+ padding: 5px 8px;
32
+ margin: 10px 0;
33
+ }
34
+
35
+ #flash_notice {
36
+ background-color: #CFC;
37
+ border: solid 1px #6C6;
38
+ }
39
+
40
+ #flash_error {
41
+ background-color: #FCC;
42
+ border: solid 1px #C66;
43
+ }
44
+
45
+ .fieldWithErrors {
46
+ display: inline;
47
+ }
48
+
49
+ #errorExplanation {
50
+ width: 400px;
51
+ border: 2px solid #CF0000;
52
+ padding: 0px;
53
+ padding-bottom: 12px;
54
+ margin-bottom: 20px;
55
+ background-color: #f0f0f0;
56
+ }
57
+
58
+ #errorExplanation h2 {
59
+ text-align: left;
60
+ font-weight: bold;
61
+ padding: 5px 5px 5px 15px;
62
+ font-size: 12px;
63
+ margin: 0;
64
+ background-color: #c00;
65
+ color: #fff;
66
+ }
67
+
68
+ #errorExplanation p {
69
+ color: #333;
70
+ margin-bottom: 0;
71
+ padding: 8px;
72
+ }
73
+
74
+ #errorExplanation ul {
75
+ margin: 2px 24px;
76
+ }
77
+
78
+ #errorExplanation ul li {
79
+ font-size: 12px;
80
+ list-style: disc;
81
+ }
@@ -0,0 +1,67 @@
1
+ !primary_color = #4B7399
2
+
3
+ body
4
+ :background-color = !primary_color
5
+ :font
6
+ :family Verdana, Helvetica, Arial
7
+ :size 14px
8
+
9
+ a
10
+ :color #0000FF
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 #fff
23
+ :padding 20px 40px
24
+ :border solid 1px black
25
+ :margin-top 20px
26
+
27
+ #flash_notice,
28
+ #flash_error
29
+ :padding 5px 8px
30
+ :margin 10px 0
31
+
32
+ #flash_notice
33
+ :background-color #CFC
34
+ :border solid 1px #6C6
35
+
36
+ #flash_error
37
+ :background-color #FCC
38
+ :border solid 1px #C66
39
+
40
+ .fieldWithErrors
41
+ :display inline
42
+
43
+ #errorExplanation
44
+ :width 400px
45
+ :border 2px solid #CF0000
46
+ :padding 0
47
+ :padding-bottom 12px
48
+ :margin-bottom 20px
49
+ :background-color #f0f0f0
50
+ h2
51
+ :text-align left
52
+ :padding 5px 5px 5px 15px
53
+ :margin 0
54
+ :font
55
+ :weight bold
56
+ :size 12px
57
+ :background-color #c00
58
+ :color #fff
59
+ p
60
+ :color #333
61
+ :margin-bottom 0
62
+ :padding 8px
63
+ ul
64
+ :margin 2px 24px
65
+ li
66
+ :font-size 12px
67
+ :list-style disc
@@ -0,0 +1,51 @@
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 nifty_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, and 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, `nifty_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 map.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 effect model attributes.
33
+
34
+ Examples:
35
+ script/generate nifty_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
+
41
+ script/generate nifty_scaffold post name:string content:text index new edit
42
+
43
+ Will create a Post model and migration file with the name and content
44
+ attributes. It will also create a controller with index, new, create,
45
+ edit, and update actions. Notice the create and update actions are
46
+ added automatically with new and edit.
47
+
48
+ script/generate nifty_scaffold post ! show new
49
+
50
+ Creates a posts controller (no model) with index, edit, update, and
51
+ destroy actions.
@@ -0,0 +1,243 @@
1
+ class NiftyScaffoldGenerator < 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
+ if rspec?
53
+ m.directory "spec/models"
54
+ m.template "tests/#{test_framework}/model.rb", "spec/models/#{singular_name}_spec.rb"
55
+ m.directory "spec/fixtures"
56
+ m.template "fixtures.yml", "spec/fixtures/#{plural_name}.yml"
57
+ else
58
+ m.directory "test/unit"
59
+ m.template "tests/#{test_framework}/model.rb", "test/unit/#{singular_name}_test.rb"
60
+ m.directory "test/fixtures"
61
+ m.template "fixtures.yml", "test/fixtures/#{plural_name}.yml"
62
+ end
63
+ end
64
+
65
+ unless options[:skip_controller]
66
+ m.directory "app/controllers"
67
+ if options[:inherited_resources]
68
+ m.template "inherited_resources_controller.rb", "app/controllers/#{plural_name}_controller.rb"
69
+ else
70
+ m.template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
71
+ end
72
+
73
+ m.directory "app/helpers"
74
+ m.template "helper.rb", "app/helpers/#{plural_name}_helper.rb"
75
+
76
+ m.directory "app/views/#{plural_name}"
77
+ controller_actions.each do |action|
78
+ if File.exist? source_path("views/#{view_language}/#{action}.html.#{view_language}")
79
+ m.template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
80
+ end
81
+ end
82
+
83
+ if form_partial?
84
+ if options[:formtastic]
85
+ m.template "views/#{view_language}/_fields.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
86
+ else
87
+ m.template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
88
+ end
89
+ end
90
+
91
+ m.route_resources plural_name
92
+
93
+ if rspec?
94
+ m.directory "spec/controllers"
95
+ m.template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
96
+ else
97
+ m.directory "test/functional"
98
+ m.template "tests/#{test_framework}/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ def form_partial?
105
+ actions? :new, :edit
106
+ end
107
+
108
+ def all_actions
109
+ %w[index show new create edit update destroy]
110
+ end
111
+
112
+ def action?(name)
113
+ controller_actions.include? name.to_s
114
+ end
115
+
116
+ def actions?(*names)
117
+ names.all? { |n| action? n.to_s }
118
+ end
119
+
120
+ def singular_name
121
+ name.underscore
122
+ end
123
+
124
+ def plural_name
125
+ name.underscore.pluralize
126
+ end
127
+
128
+ def class_name
129
+ name.camelize
130
+ end
131
+
132
+ def plural_class_name
133
+ plural_name.camelize
134
+ end
135
+
136
+ def controller_methods(dir_name)
137
+ controller_actions.map do |action|
138
+ read_template("#{dir_name}/#{action}.rb")
139
+ end.join(" \n").strip
140
+ end
141
+
142
+ def render_form
143
+ if form_partial?
144
+ if options[:haml]
145
+ "= render :partial => 'form'"
146
+ else
147
+ "<%= render :partial => 'form' %>"
148
+ end
149
+ else
150
+ read_template("views/#{view_language}/_form.html.#{view_language}")
151
+ end
152
+ end
153
+
154
+ def items_path(suffix = 'path')
155
+ if action? :index
156
+ "#{plural_name}_#{suffix}"
157
+ else
158
+ "root_#{suffix}"
159
+ end
160
+ end
161
+
162
+ def item_path(suffix = 'path')
163
+ if action? :show
164
+ "@#{singular_name}"
165
+ else
166
+ items_path(suffix)
167
+ end
168
+ end
169
+
170
+ def item_path_for_spec(suffix = 'path')
171
+ if action? :show
172
+ "#{singular_name}_#{suffix}(assigns[:#{singular_name}])"
173
+ else
174
+ items_path(suffix)
175
+ end
176
+ end
177
+
178
+ def item_path_for_test(suffix = 'path')
179
+ if action? :show
180
+ "#{singular_name}_#{suffix}(assigns(:#{singular_name}))"
181
+ else
182
+ items_path(suffix)
183
+ end
184
+ end
185
+
186
+ def model_columns_for_attributes
187
+ class_name.constantize.columns.reject do |column|
188
+ column.name.to_s =~ /^(id|created_at|updated_at)$/
189
+ end
190
+ end
191
+
192
+ def rspec?
193
+ test_framework == :rspec
194
+ end
195
+
196
+ protected
197
+
198
+ def view_language
199
+ options[:haml] ? 'haml' : 'erb'
200
+ end
201
+
202
+ def test_framework
203
+ options[:test_framework] ||= default_test_framework
204
+ end
205
+
206
+ def default_test_framework
207
+ File.exist?(destination_path("spec")) ? :rspec : :testunit
208
+ end
209
+
210
+ def add_options!(opt)
211
+ opt.separator ''
212
+ opt.separator 'Options:'
213
+ opt.on("--skip-model", "Don't generate a model or migration file.") { |v| options[:skip_model] = v }
214
+ opt.on("--skip-migration", "Don't generate migration file for model.") { |v| options[:skip_migration] = v }
215
+ opt.on("--skip-timestamps", "Don't add timestamps to migration file.") { |v| options[:skip_timestamps] = v }
216
+ opt.on("--skip-controller", "Don't generate controller, helper, or views.") { |v| options[:skip_controller] = v }
217
+ opt.on("--invert", "Generate all controller actions except these mentioned.") { |v| options[:invert] = v }
218
+ opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = v }
219
+ opt.on("--inherited-resources", "Generate inherited-resources controller instead of conventional.") { |v| options[:inherited_resources] = v }
220
+ opt.on("--will-paginate", "Generate will-paginate code.") { |v| options[:will_paginate] = v }
221
+ opt.on("--formtastic", "Generate formtastic forms.") { |v| options[:formtastic] = v }
222
+ opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
223
+ opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
224
+ opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
225
+ end
226
+
227
+ # is there a better way to do this? Perhaps with const_defined?
228
+ def model_exists?
229
+ File.exist? destination_path("app/models/#{singular_name}.rb")
230
+ end
231
+
232
+ def read_template(relative_path)
233
+ ERB.new(File.read(source_path(relative_path)), nil, '-').result(binding)
234
+ end
235
+
236
+ def banner
237
+ <<-EOS
238
+ Creates a controller and optional model given the name, actions, and attributes.
239
+
240
+ USAGE: #{$0} #{spec.name} ModelName [controller_actions and model:attributes] [options]
241
+ EOS
242
+ end
243
+ end