michel-dry_scaffold 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/CHANGELOG.textile +51 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +461 -0
  4. data/Rakefile +48 -0
  5. data/TODO.textile +40 -0
  6. data/bin/dmodel +3 -0
  7. data/bin/dry_model +3 -0
  8. data/bin/dry_scaffold +3 -0
  9. data/bin/dscaffold +3 -0
  10. data/config/scaffold.yml +34 -0
  11. data/generators/dmodel/dmodel_generator.rb +15 -0
  12. data/generators/dry_model/USAGE +9 -0
  13. data/generators/dry_model/dry_model_generator.rb +134 -0
  14. data/generators/dry_model/prototypes/active_record_migration.rb +17 -0
  15. data/generators/dry_model/prototypes/active_record_model.rb +9 -0
  16. data/generators/dry_model/prototypes/fixture_data/active_record_fixtures.yml +3 -0
  17. data/generators/dry_model/prototypes/fixture_data/factory_girl_factories.rb +4 -0
  18. data/generators/dry_model/prototypes/fixture_data/machinist_blueprints.rb +8 -0
  19. data/generators/dry_model/prototypes/tests/rspec/unit_test.rb +9 -0
  20. data/generators/dry_model/prototypes/tests/shoulda/unit_test.rb +20 -0
  21. data/generators/dry_model/prototypes/tests/test_unit/unit_test.rb +15 -0
  22. data/generators/dry_model/templates/models/active_record_migration.rb +23 -0
  23. data/generators/dry_model/templates/models/active_record_model.rb +15 -0
  24. data/generators/dry_model/templates/models/fixture_data/active_record_fixtures.yml +6 -0
  25. data/generators/dry_model/templates/models/fixture_data/factory_girl_factories.rb +5 -0
  26. data/generators/dry_model/templates/models/fixture_data/machinist_blueprints.rb +9 -0
  27. data/generators/dry_model/templates/models/tests/rspec/unit_test.rb +11 -0
  28. data/generators/dry_model/templates/models/tests/shoulda/unit_test.rb +23 -0
  29. data/generators/dry_model/templates/models/tests/test_unit/unit_test.rb +17 -0
  30. data/generators/dry_scaffold/USAGE +11 -0
  31. data/generators/dry_scaffold/dry_scaffold_generator.rb +415 -0
  32. data/generators/dry_scaffold/prototypes/controllers/action_controller.rb +135 -0
  33. data/generators/dry_scaffold/prototypes/controllers/inherited_resources_controller.rb +25 -0
  34. data/generators/dry_scaffold/prototypes/controllers/tests/rspec/functional_test.rb +57 -0
  35. data/generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb +99 -0
  36. data/generators/dry_scaffold/prototypes/controllers/tests/test_unit/functional_test.rb +70 -0
  37. data/generators/dry_scaffold/prototypes/helpers/helper.rb +3 -0
  38. data/generators/dry_scaffold/prototypes/helpers/tests/rspec/unit_test.rb +9 -0
  39. data/generators/dry_scaffold/prototypes/helpers/tests/shoulda/unit_test.rb +9 -0
  40. data/generators/dry_scaffold/prototypes/helpers/tests/test_unit/unit_test.rb +9 -0
  41. data/generators/dry_scaffold/prototypes/views/builder/index.atom.builder +20 -0
  42. data/generators/dry_scaffold/prototypes/views/builder/index.rss.builder +21 -0
  43. data/generators/dry_scaffold/prototypes/views/haml/_form.html.haml +3 -0
  44. data/generators/dry_scaffold/prototypes/views/haml/_item.html.haml +9 -0
  45. data/generators/dry_scaffold/prototypes/views/haml/edit.html.haml +10 -0
  46. data/generators/dry_scaffold/prototypes/views/haml/index.html.haml +17 -0
  47. data/generators/dry_scaffold/prototypes/views/haml/layout.html.haml +18 -0
  48. data/generators/dry_scaffold/prototypes/views/haml/new.html.haml +10 -0
  49. data/generators/dry_scaffold/prototypes/views/haml/show.html.haml +13 -0
  50. data/generators/dry_scaffold/templates/controllers/action_controller.rb +250 -0
  51. data/generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb +36 -0
  52. data/generators/dry_scaffold/templates/controllers/tests/rspec/functional_test.rb +85 -0
  53. data/generators/dry_scaffold/templates/controllers/tests/shoulda/functional_test.rb +90 -0
  54. data/generators/dry_scaffold/templates/controllers/tests/test_unit/functional_test.rb +87 -0
  55. data/generators/dry_scaffold/templates/helpers/helper.rb +3 -0
  56. data/generators/dry_scaffold/templates/helpers/tests/rspec/unit_test.rb +9 -0
  57. data/generators/dry_scaffold/templates/helpers/tests/shoulda/unit_test.rb +9 -0
  58. data/generators/dry_scaffold/templates/helpers/tests/test_unit/unit_test.rb +9 -0
  59. data/generators/dry_scaffold/templates/views/builder/index.atom.builder +20 -0
  60. data/generators/dry_scaffold/templates/views/builder/index.rss.builder +21 -0
  61. data/generators/dry_scaffold/templates/views/haml/_form.html.haml +13 -0
  62. data/generators/dry_scaffold/templates/views/haml/_item.html.haml +10 -0
  63. data/generators/dry_scaffold/templates/views/haml/edit.html.haml +18 -0
  64. data/generators/dry_scaffold/templates/views/haml/index.html.haml +38 -0
  65. data/generators/dry_scaffold/templates/views/haml/layout.html.haml +19 -0
  66. data/generators/dry_scaffold/templates/views/haml/new.html.haml +18 -0
  67. data/generators/dry_scaffold/templates/views/haml/show.html.haml +13 -0
  68. data/generators/dscaffold/dscaffold_generator.rb +15 -0
  69. data/lib/dry_generator.rb +197 -0
  70. data/lib/dry_scaffold/tasks.rb +5 -0
  71. data/lib/setup_helper.rb +36 -0
  72. data/rails/init.rb +3 -0
  73. data/tasks/dry_scaffold.rake +95 -0
  74. metadata +132 -0
data/CHANGELOG.textile ADDED
@@ -0,0 +1,51 @@
1
+ h1. 0.3.4 (2009-09-16)
2
+
3
+ * Fixed bug: Make it possible to require rake tasks (In Rakefile: require 'dry_scaffold/tasks')
4
+
5
+ h1. 0.3.2/0.3.3 (2009-09-14)
6
+
7
+ * Fixed bug: Rspec tests issues
8
+
9
+ h1. 0.3.1 (2009-09-09)
10
+
11
+ * Feature: Added Rspec tests generation
12
+
13
+ h1. 0.3.0 (2009-07-23)
14
+
15
+ * Major refactoring of the code.
16
+ * Test/Fixture-stuff re-written from the ground, now tested thoroughly and considered stable - was not before. Plenty sloppy bugs squashed.
17
+ * Added Shoulda tests generation.
18
+
19
+ h1. 0.2.5 (2009-06-12)
20
+
21
+ * Fixed typo: Gem configuration instructions in README.
22
+ * Fixed bug: Re-generated gemspec - missing files. (cjheath)
23
+
24
+ h1. 0.2.4 (2009-05-19)
25
+
26
+ * Fixed bug: Causing generator to fail if test/unit/helpers path don't exist.
27
+
28
+ h1. 0.2.3 (2009-05-12)
29
+
30
+ * Fixed bug: Missing executables in gemspec.
31
+
32
+ h1. 0.2.2 (2009-05-06)
33
+
34
+ * Feature: Specifying actions new+ instead of new, then actions new/create. Same applies to edit+, i.e. edit/update.
35
+ * Feature: For respond_to-formats ATOM/RSS; builders will be generated unless --skip-builders flag is specified
36
+ * Feature: If route is already declared in 'config/routes.rb', then don't generate the route again.
37
+ * Refactor: New template directory structure and naming conventions - more generic. Preparing for optional test frameworks.
38
+ * Refactor: Cleaned up views with generator helpers.
39
+ * Fixed bug: Options for factory_girl vs. machinist got in-versed, i.e. typo.
40
+ * Fixed bug: Options got ignored because of a typo. Grrr....
41
+
42
+ h1. 0.2.1 (2009-05-03)
43
+
44
+ * New feature: Possible to set generator default args in a config file (config/scaffold.yml), or rely on defaults.
45
+ * Fixed issue: Rails default_options don't seem to work at all; replacing it with own solution.
46
+ * Fixed bug: Typo in formats arg parser.
47
+ * Refactor: Gem requires less hardcoded.
48
+
49
+ h1. 0.2.0 (2009-05-01)
50
+
51
+ * New dry model generator: Extends Rails default model generator with features such as generation of factory_girl/machinis/object_daddy-factories if available and requested (or fixtures), and specifying database column indexes upon generation in a very convenient way.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jonas Grimfelt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,461 @@
1
+ h1. DRY SCAFFOLD
2
+
3
+ _A Rails scaffold generator that generates DRYer, cleaner, and more useful code._
4
+
5
+ h2. Description
6
+
7
+ DryScaffold is a replacement for the Rails scaffold generator that generates code that most people end up deleting or rewriting anyway because of the unusable code. The scaffold concept is powerful, but it has more potential than generating messy and almost useless code - something that might change with Rails 3 though. The goal with DryScaffold is to generate DRY, beautiful, and standards compliant code based on common patterns without adding a lot of assumptions.
8
+
9
+ *Key Concepts:*
10
+
11
+ * Controllers that are DRY, RESTful, no code-smells, following conventions, and implementing VERY common patterns.
12
+ * Views that are DRY, semantic, standards compliant, valid, and more useful in development.
13
+ * Factories instead of fixtures.
14
+ * Generator that gets smart with additional arguments - but not stupid without them.
15
+ * Any Rails developer should be able to switch generator with no effort - follow current conventions, but extend them.
16
+
17
+ h2. Dependencies
18
+
19
+ h3. Required:
20
+
21
+ * "*haml*":http://github.com/nex3/haml - ERB sucks like PHP, end of story
22
+
23
+ h3. Optional:
24
+
25
+ h4. Controllers/Views
26
+
27
+ * "*inherited_resources*":http://github.com/josevalim/inherited_resources - DRY/Resourceful controllers
28
+ * "*formtastic*":http://github.com/justinfrench/formtastic - DRY and semantic forms
29
+ * "*will_paginate*":http://github.com/mislav/will_paginate - Pagination
30
+
31
+ h4. Models
32
+
33
+ * "*factory_girl*":http://github.com/thoughtbot/factory_girl - Fixture-replacement
34
+ * "*machinist*":http://github.com/notahat/machinist - Fixture-replacement
35
+ * "*object_daddy*":http://github.com/flogic/object_daddy - Fixture-replacement
36
+
37
+ h4. Testing
38
+
39
+ * "*shoulda*":http://github.com/thoughtbot/shoulda - Testing framework
40
+ * "*rspec*":http://wiki.github.com/dchelimsky/rspec - Testing framework
41
+
42
+ h2. Features
43
+
44
+ h3. Overview
45
+
46
+ The most characteristic features:
47
+
48
+ * Generates DRY controllers + functional tests.
49
+ * Generates DRY, semantic, and standard compliant views in HAML - not just HAMLized templates.
50
+ * Generates formtastic - very DRY - forms (using "formtastic" by Justin French et. al.) by default. Note: Can be turned off.
51
+ * Generates resourceful - even DRYer - controllers (using the "inherited_resources" by José Valim) by default. Note: Can be turned off.
52
+ * Collection pagination using will_paginate by default. Note: Can be turned off.
53
+ * Optionally specify what actions/views to generate (stubs for specified REST-actions will be generated).
54
+ * Optionally specify what respond_to-formats to generate (stubs for the most common respond_to-formats will be generated).
55
+ * Generates default helpers/models/migrations, and REST-routes (if not already defined).
56
+ * Generates default search using searchlogic
57
+
58
+ h3. Formtastic Forms
59
+
60
+ Quick and dirty; Formtastic makes your form views cleaner, and your life as a Rails developer easier (for real). Formtastic forms can be turned off, but I would recommend any Rails developer to consider using it - there is really no good reason not to if you not running very old version of Rails.
61
+
62
+ h4. Standard
63
+
64
+ HAML + ActionView FormHelpers:
65
+
66
+ <pre>- form_for(@duck) do |f|
67
+ = f.error_messages
68
+ %ul
69
+ %li
70
+ = f.label :name, 'Name'
71
+ = f.text_field :name
72
+ %li
73
+ = f.label :about, 'About'
74
+ = f.text_area :about
75
+ %p.buttons
76
+ = f.submit 'Create'</pre>
77
+
78
+ h4. Formtastic
79
+
80
+ HAML + Formtastic:
81
+
82
+ <pre>- semantic_form_for(@duck) do |f|
83
+ - f.inputs do
84
+ = f.input :name
85
+ = f.input :about
86
+ - f.buttons do
87
+ = f.commit_button 'Create'</pre>
88
+
89
+ Find out more about *formtastic*: "http://github.com/justinfrench/formtastic":http://github.com/justinfrench/formtastic
90
+
91
+ h3. Resourceful Controllers
92
+
93
+ Quick and dirty; InheritedResources makes your controllers controllers cleaner, and might make experienced Rails developer's life DRYer code wise. This is possible because of REST as a convention in Rails, and therefore the patterns that arise in controllers can be DRYed up A LOT. Resourceful - InheritedResources-based - controllers can be turned off, but I would recommend any experienced Rails developer to consider using it - there is really no good reason not to unless maybe if you are a Rails beginner, then you should consider get used to the basic Rails building blocks first.
94
+
95
+ h4. Standard
96
+
97
+ Using ActionController:
98
+
99
+ <pre>def new
100
+ @duck = Duck.new
101
+
102
+ respond_to do |format|
103
+ format.html # new.html.haml
104
+ format.xml { render :xml => @duck }
105
+ format.json { render :json => @duck }
106
+ end
107
+ end</pre>
108
+
109
+ h4. Resourceful
110
+
111
+ Using InheritedResources:
112
+
113
+ <pre>actions :new
114
+ respond_to :html, :xml, :json</pre>
115
+
116
+ Find out more about *inherited_resources*: "http://github.com/josevalim/inherited_resources":http://github.com/josevalim/inherited_resources
117
+
118
+ h3. Pagination
119
+
120
+ Pagination is such a common feature that always seems to be implemented anyway, so DryScaffold will generate a DRY solution for this in each controller that you can tweak - even thought that will not be needed in most cases. See DRY Patterns beneath for more details how it's done. Pagination - using WillPaginate - can be turned off.
121
+
122
+ Find out more about *will_paginate*: "http://github.com/mislav/will_paginate":http://github.com/mislav/will_paginate
123
+
124
+ h3. DRYying Patterns
125
+
126
+ Either if you choosing default or resourceful controllers, this pattern is used to DRYing up controllers a bit more, and at the same time loading resources in the same place using before_filter while adding automatic pagination for collections.
127
+
128
+ h4. Standard
129
+
130
+ ActionController with pagination:
131
+
132
+ <pre>before_filter :load_resource, :only => [:show, :edit, :update, :destroy]
133
+ before_filter :load_and_paginate_resources, :only => [:index]
134
+
135
+ ...
136
+
137
+ protected
138
+
139
+ def collection
140
+ paginate_options ||= {}
141
+ paginate_options[:page] ||= (params[:page] || 1)
142
+ paginate_options[:per_page] ||= (params[:per_page] || 20)
143
+ @collection = @resources ||= Duck.paginate(paginate_options)
144
+ end
145
+ alias :load_and_paginate_resources :collection
146
+
147
+ def resource
148
+ @resource = @resource = ||= Duck.find(params[:id])
149
+ end
150
+ alias :load_resource :resource</pre>
151
+
152
+ h4. Resourceful
153
+
154
+ InheritedResources with pagination:
155
+
156
+ <pre>protected
157
+
158
+ def collection
159
+ paginate_options ||= {}
160
+ paginate_options[:page] ||= (params[:page] || 1)
161
+ paginate_options[:per_page] ||= (params[:per_page] || 20)
162
+ @resources ||= end_of_association_chain.paginate(paginate_options)
163
+ end</pre>
164
+
165
+ h3. View Partials
166
+
167
+ A very common pattern is to break up views in partials, which is also what DryScaffold does:
168
+
169
+ * @new@/@edit@ => @_form@
170
+ * @index@ => @_item@
171
+
172
+ h3. More To Come... (TODO)
173
+
174
+ These are things I have in mind:
175
+
176
+ * Handle belongs_to, i.e. specify MODEL --belongs-to PARENT_MODEL, which generates proper routes, proper before-filters if inherited_resources-controller, adding belongs_to-association in model, and correct form_for arguments.
177
+ * RSpec-support?
178
+
179
+ h2. Setup
180
+
181
+ Installing DryScaffold is easy:
182
+
183
+ h3. 1. Installation
184
+
185
+ Install DryScaffold...
186
+
187
+ h4. Gem (Recommended)
188
+
189
+ <pre>sudo gem install grimen-dry_scaffold --source http://gems.github.com</pre>
190
+
191
+ ...and in config: @config/environments/development.rb@
192
+
193
+ <pre>config.gem 'grimen-dry_scaffold', :lib => false, :source => 'http://gems.github.com'</pre>
194
+
195
+ h4. Plugin
196
+
197
+ <pre>./script/plugin install git://github.com/grimen/dry_scaffold.git</pre>
198
+
199
+ h3. 2. Install Dependencies (Partly optional)
200
+
201
+ Install dependencies to release the full power of dry_scaffold. Only HAML is really required of these, but how could anyone resist candy? =)
202
+
203
+ h4. Automatic/Express
204
+
205
+ For us lazy ones... =) *Note:* Probably won't work without require the rake tasks first in the project @Rakefile@: @require 'dry_scaffold/tasks'@
206
+
207
+ <pre>rake dry_scaffold:setup</pre>
208
+
209
+ Will install the dependencies, initialize HAML within current Rails project if not already done, and automatically referencing the dependency gems within the current Rails project environment config if they are not already in there (note: nothing will be overwritten).
210
+
211
+ h4. Manual
212
+
213
+ Get the gems...you want:
214
+
215
+ <pre>sudo gem install haml
216
+ sudo gem install mislav-will_paginate
217
+ sudo gem install justinfrench-formtastic
218
+ sudo gem install josevalim-inherited_resources
219
+ sudo gem install searchlogic
220
+ </pre>
221
+
222
+ ...and same for the config config: @config/environments/development.rb@
223
+
224
+ <pre>config.gem 'haml'
225
+ config.gem 'will_paginate'
226
+ config.gem 'justinfrench-formtastic', :lib => 'formtastic', :source => 'http://gems.github.com'
227
+ config.gem 'josevalim-inherited_resources', :lib => 'inherited_resources', :source => 'http://gems.github.com'
228
+ config.gem 'binarylogic-searchlogic', :source => 'http://gems.github.com'
229
+ </pre>
230
+
231
+ Also configure @config/environments/test.rb@ with the RSpec library if you want to
232
+
233
+ <pre>config.gem 'rspec'
234
+ config.gem 'rspec-rails'</pre>
235
+
236
+ And don't forget to initialize it as well:
237
+
238
+ <pre>./script/generate rspec</pre>
239
+
240
+ To access Rake tasks in Rails from the gem version of DryScaffold you need to do this:
241
+
242
+ In your project @Rakefile@:
243
+
244
+ <pre>
245
+ require 'dry_scaffold/tasks'
246
+ </pre>
247
+
248
+ Don't ask me why me why this is the only way with gems...Ask the Rails core team, because this is not conventions over configuration. Raur...
249
+
250
+ h2. Usage
251
+
252
+ <pre>./script/generate dry_scaffold ModelName [attribute:type attribute:type] [_actions:new,create,...] [_formats:html,json,...] [_indexes:attribute,...] [--skip-pagination] [--skip-resourceful] [--skip-formtastic] [--skip-views] [--skip-helpers] [--skip-migration] [--skip-timestamps] [--skip-tests] [--skip-controller-tests] [--layout] [--tunit] [--shoulda] [--rspec] [--fixtures] [--fgirl] [--machinist] [--odaddy]</pre>
253
+
254
+ ...or use the alias @dscaffold@ instead of @dry_scaffold@.
255
+
256
+ For generating just a *model*, then use:
257
+
258
+ <pre>./script/generate dry_model ModelName [attribute:type attribute:type] [_indexes:attribute,...] [--skip-migration] [--skip-timestamps] [--skip-tests] [--tunit] [--shoulda] [--rspec] [--fixtures] [--fgirl] [--machinist] [--odaddy]</pre>
259
+
260
+ ...or use the alias @dmodel@ instead of @dry_model@.
261
+
262
+ h3. Model Name
263
+
264
+ Example:
265
+
266
+ <pre>Duck</pre>
267
+
268
+ Same as in the default scaffold/model generator; the name of a new/existing model.
269
+
270
+ h3. Model Attributes
271
+
272
+ Example:
273
+
274
+ <pre>name:string about:text ...</pre>
275
+
276
+ Same as in the default scaffold/model generator; model attributes and database migration column types.
277
+
278
+ h3. Controller Actions
279
+
280
+ Example:
281
+
282
+ <pre>_actions:new,create,quack,index,...</pre>
283
+
284
+ You can override what actions that should be generated directly - including custom actions.
285
+
286
+ h4. Default Actions (REST)
287
+
288
+ If no actions are specified, the following REST-actions will be generated by default:
289
+
290
+ * @show@
291
+ * @index@
292
+ * @new@
293
+ * @edit@
294
+ * @create@
295
+ * @update@
296
+ * @destroy@
297
+
298
+ Default controller action stubs, controller action test stubs, and corresponding views (and required partials), are generated for all of these actions.
299
+
300
+ These default actions can also be included using the quantifiers @*@ and @+@, which makes it easier to add new actions without having to specify all the default actions explicit. Example:
301
+
302
+ <pre>_actions:quack # => quack</pre>
303
+ <pre>_actions:*,quack # => show,index,new,edit,create,update,destroy,quack</pre>
304
+ <pre>_actions:new+,edit,quack # => new,edit,create,quack</pre>
305
+ <pre>_actions:new+,edit+,quack # => new,edit,create,update,quack</pre>
306
+
307
+ h4. Custom Actions
308
+
309
+ The above REST actions are in many RESTful applications the only ones needed. Any other specified actions will generate empty action function stubs for manual implementation. No views will be generated for custom actions.
310
+
311
+ h3. Controller Formats
312
+
313
+ Example:
314
+
315
+ <pre>_formats:html,xml,txt,... # <=> _respond_to:html,xml,txt,...</pre>
316
+
317
+ You can override what respond_to-formats that should be generated directly - only for REST-actions right now because I tried to avoid bad assumptions.
318
+
319
+ h4. Default Formats
320
+
321
+ If no formats are specified, the following formats will be generated by default:
322
+
323
+ * @html@ => Template: resource.html.haml
324
+ * @js@ => Template: resource.js.rjs
325
+ * @xml@ => Render: resource.to_xml
326
+ * @json@ => Render: resource.to_json
327
+
328
+ Default respond block stubs are generated for all of these formats - for each generated REST-action.
329
+
330
+ Like for actions, these default respond_to-formats can also be included using the alias symbol @*@, which makes it easier to add new formats without having to specify all the default formats explicit. Example:
331
+
332
+ <pre>_formats:iphone # => _formats:iphone</pre>
333
+ <pre>_formats:*,iphone # => _formats:html,js,xml,json,iphone</pre>
334
+
335
+ h4. Additional Formats
336
+
337
+ Also, default respond block stubs are generated for any of these formats - for each generated REST-action - if they are specified:
338
+
339
+ * @atom@ => Template: index.atom.builder
340
+ * @rss@ => Template: index.rss.builder
341
+ * @yaml@/@yml@ => Render: resource.to_yaml
342
+ * @txt@/@text@ => Render: resource.to_s
343
+
344
+ NOTE: Only for Non-InheritedResources controllers for now.
345
+
346
+ For the feed formats @atom@ and @rss@, builders are automatically generated if @index@-action is specified. Example:
347
+
348
+ @app/views/ducks/index.atom.builder@
349
+
350
+ <pre>
351
+ atom_feed(:language => I18n.locale) do |feed|
352
+ feed.title 'Resources'
353
+ feed.subtitle 'Index of all resources.'
354
+ feed.updated (@resources.first.created_at rescue Time.now.utc).strftime('%Y-%m-%dT%H:%M:%SZ'))
355
+
356
+ @resources.each do |resource|
357
+ feed.entry(resource) do |entry|
358
+ entry.title 'title'
359
+ entry.summary 'summary'
360
+
361
+ resource.author do |author|
362
+ author.name 'author_name'
363
+ end
364
+ end
365
+ end
366
+ end
367
+ </pre>
368
+
369
+ Builder generation can be skipped by specifying the @--skip-builders@ flag.
370
+
371
+ h4. Custom Formats
372
+
373
+ The above formats are the most commonly used ones, and respond blocks are already implemented using Rails default dependencies. Any other specified formats (such as PDF, CSV, etc.) will generate empty respond block stubs for manual implementation with help of additional dependencies.
374
+
375
+ h3. Model Indexes
376
+
377
+ Example:
378
+
379
+ If model attributes are specified as:
380
+
381
+ <pre>name:string owner:reference</pre>
382
+
383
+ ...then we could do this (for polymorphic association):
384
+
385
+ <pre>_indexes:owner_id # => (In migration:) add_index :duck, :owner_id</pre>
386
+
387
+ ...or in account for a polymorphic association:
388
+
389
+ <pre>_indexes:owner_id+owner_type # => (In migration:) add_index :duck, [:owner_id, :owner_type]</pre>
390
+
391
+ NOTE: Of course...you need to specify indexes based on attributes that exists for this model, otherwise your migration will not be valid - DryScaffold is leaving this responsible to you.
392
+
393
+ h3. Options/Flags
394
+
395
+ Example:
396
+
397
+ <pre>--skip-resourceful --layout</pre>
398
+
399
+ h4. Scaffold
400
+
401
+ These are the options for the scaffold-generator.
402
+
403
+ * @--skip-pagination@ - Don't generate pagination of collections in controller and views, i.e. don't use *will_paginate*.
404
+ * @--skip-resourceful@ - Don't generate resourceful controller, i.e. don't use *inherited_resources*.
405
+ * @--skip-formtastic@ - Don't generate formtastic forms in views, i.e. don't use *formtastic*.
406
+ * @--skip-views@ - Don't generate views.
407
+ * @--skip-helpers@ - Don't generate helpers.
408
+ * @--skip-builders@ - Don't generate builders.
409
+ * @--skip-controller-tests@ - Don't generate controller tests
410
+ * @--layout@ - Generate layout.
411
+
412
+ h4. Model
413
+
414
+ These are the options for the model/scaffold-generators.
415
+
416
+ * @--skip-timestamps@ - Don't add timestamps to the migration file.
417
+ * @--skip-migration@ - Skip generation of migration file.
418
+
419
+ h4. All
420
+
421
+ * @--skip-tests@ - Don't generate tests (functional/unit/...).
422
+ * @--tunit@ - Generate/Use test_unit tests. Note: Rails default.
423
+ * @--shoulda@ - Generate/Use *shoulda* tests.
424
+ * @--rspec@ - Generate/Use *rspec* tests.
425
+ * @--fixtures@ - Generate/Use fixtures. Note: Rails default.
426
+ * @--fgirl@ - Generate/Use *factory_girl* factories.
427
+ * @--machinist@ - Generate/Use *machinist* blueprints (factories).
428
+ * @--odaddy@ - Generate/Use *object_daddy* generator/factory methods.
429
+
430
+ As DryScaffold is built upon Rails generator, the default generator options is available as well. For more details; see Rails documentation.
431
+
432
+ h3. Setting Defaults
433
+
434
+ You can set defaults for the generator args/options in @config/scaffold.yml@. To generate this file, simply do:
435
+
436
+ <pre>rake dry_scaffold:config:generate</pre>
437
+
438
+ h2. Examples
439
+
440
+ No need for more samples here, just create a new Rails project, install DryScaffold and it's dependencies, and try it out!
441
+
442
+ For your inspiration, you could try the following:
443
+
444
+ <pre>./script/generate dry_scaffold Zebra name:string about:text --skip-resourceful
445
+ ./script/generate dscaffold Kangaroo name:string about:text --skip-formtastic
446
+ ./script/generate dscaffold Duck name:string about:text _actions:new,create,index,quack
447
+ ./script/generate dscaffold Parrot name:string about:text _formats:html,xml,yml
448
+ ./script/generate dmodel GoldFish name:string about:text _indexes:name --fgirl
449
+ ./script/generate dmodel Frog name:string about:text _indexes:name,name+about --fixtures</pre>
450
+
451
+ ...or just go crazy!
452
+
453
+ h2. Bugs & Feedback
454
+
455
+ If you experience any issues/bugs or have feature requests, just file a GitHub-issue or send me a message.
456
+ If you think parts of my implementation could be implemented nicer somehow, please let me know...or just fork it and fix it yourself! =)
457
+ At last, positive feedback is always appreciated!
458
+
459
+ h2. License
460
+
461
+ Copyright (c) 2009 Jonas Grimfelt, released under the MIT-license.