grimen-dry_scaffold 0.2.3 → 0.2.4
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/README.textile +61 -48
- data/Rakefile +1 -1
- data/TODO.textile +1 -1
- data/generators/dry_model/dry_model_generator.rb +2 -2
- data/generators/dry_scaffold/dry_scaffold_generator.rb +3 -3
- metadata +2 -2
data/README.textile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
h1. DRY SCAFFOLD
|
2
2
|
|
3
|
-
|
3
|
+
_A Rails scaffold generator that generates DRYer, cleaner, and more useful code._
|
4
4
|
|
5
5
|
h2. Description
|
6
6
|
|
7
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
8
|
|
9
|
-
|
10
|
-
|
9
|
+
*Key Concepts:*
|
10
|
+
|
11
11
|
* Controllers that are DRY, RESTful, no code-smells, following conventions, and implementing VERY common patterns.
|
12
12
|
* Views that are DRY, semantic, standards compliant, valid, and more useful in development.
|
13
13
|
* Factories instead of fixtures.
|
@@ -17,19 +17,19 @@ h3. Key Concepts:
|
|
17
17
|
h2. Dependencies
|
18
18
|
|
19
19
|
h3. Required:
|
20
|
-
|
20
|
+
|
21
21
|
* "*haml*":http://github.com/nex3/haml - ERB sucks like PHP, end of story
|
22
22
|
|
23
23
|
h3. Optional:
|
24
|
-
|
24
|
+
|
25
25
|
h4. Controllers/Views
|
26
|
-
|
26
|
+
|
27
27
|
* "*will_paginate*":http://github.com/mislav/will_paginate - Pagination
|
28
28
|
* "*formtastic*":http://github.com/justinfrench/formtastic - DRY and semantic forms
|
29
29
|
* "*inherited_resources*":http://github.com/josevalim/inherited_resources - DRY/Resourceful controllers
|
30
|
-
|
30
|
+
|
31
31
|
h4. Models
|
32
|
-
|
32
|
+
|
33
33
|
* "*factory_girl*":http://github.com/thoughtbot/factory_girl - Fixture-replacement
|
34
34
|
* "*machinist*":http://github.com/notahat/machinist - Fixture-replacement
|
35
35
|
* "*object_daddy*":http://github.com/flogic/object_daddy - Fixture-replacement
|
@@ -53,7 +53,9 @@ h3. Formtastic Forms
|
|
53
53
|
|
54
54
|
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.
|
55
55
|
|
56
|
-
h4.
|
56
|
+
h4. Standard
|
57
|
+
|
58
|
+
HAML + ActionView FormHelpers:
|
57
59
|
|
58
60
|
<pre>- form_for(@duck) do |f|
|
59
61
|
= f.error_messages
|
@@ -67,7 +69,9 @@ h4. Default HAML (without Formtastic):
|
|
67
69
|
%p.buttons
|
68
70
|
= f.submit 'Create'</pre>
|
69
71
|
|
70
|
-
h4. Formtastic
|
72
|
+
h4. Formtastic
|
73
|
+
|
74
|
+
HAML + Formtastic:
|
71
75
|
|
72
76
|
<pre>- semantic_form_for(@duck) do |f|
|
73
77
|
- f.inputs do
|
@@ -82,7 +86,9 @@ h3. Resourceful Controllers
|
|
82
86
|
|
83
87
|
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.
|
84
88
|
|
85
|
-
h4.
|
89
|
+
h4. Standard
|
90
|
+
|
91
|
+
Using ActionController:
|
86
92
|
|
87
93
|
<pre>def new
|
88
94
|
@duck = Duck.new
|
@@ -94,7 +100,9 @@ h4. Default (without InheritedResources)
|
|
94
100
|
end
|
95
101
|
end</pre>
|
96
102
|
|
97
|
-
h4. Resourceful
|
103
|
+
h4. Resourceful
|
104
|
+
|
105
|
+
Using InheritedResources:
|
98
106
|
|
99
107
|
<pre>actions :new
|
100
108
|
respond_to :html, :xml, :json</pre>
|
@@ -107,11 +115,13 @@ Pagination is such a common feature that always seems to be implemented anyway,
|
|
107
115
|
|
108
116
|
Find out more about *will_paginate*: "http://github.com/mislav/will_paginate":http://github.com/mislav/will_paginate
|
109
117
|
|
110
|
-
h3.
|
118
|
+
h3. DRYying Patterns
|
111
119
|
|
112
120
|
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.
|
113
121
|
|
114
|
-
h4.
|
122
|
+
h4. Standard
|
123
|
+
|
124
|
+
ActionController with pagination:
|
115
125
|
|
116
126
|
<pre>before_filter :load_resource, :only => [:show, :edit, :update, :destroy]
|
117
127
|
before_filter :load_and_paginate_resources, :only => [:index]
|
@@ -133,7 +143,9 @@ protected
|
|
133
143
|
end
|
134
144
|
alias :load_resource :resource</pre>
|
135
145
|
|
136
|
-
h4. Resourceful
|
146
|
+
h4. Resourceful
|
147
|
+
|
148
|
+
InheritedResources with pagination:
|
137
149
|
|
138
150
|
<pre>protected
|
139
151
|
|
@@ -152,8 +164,8 @@ h3. View Partials
|
|
152
164
|
|
153
165
|
A very common pattern is to break up views in partials, which is also what DryScaffold does:
|
154
166
|
|
155
|
-
* new
|
156
|
-
* index => _item
|
167
|
+
* @new@/@edit@ => @_form@
|
168
|
+
* @index@ => @_item@
|
157
169
|
|
158
170
|
h3. More To Come... (TODO)
|
159
171
|
|
@@ -164,7 +176,7 @@ These are things I have in mind:
|
|
164
176
|
|
165
177
|
h2. Setup
|
166
178
|
|
167
|
-
Installing DryScaffold is easy
|
179
|
+
Installing DryScaffold is easy:
|
168
180
|
|
169
181
|
h3. 1. Installation
|
170
182
|
|
@@ -172,24 +184,21 @@ Install DryScaffold...
|
|
172
184
|
|
173
185
|
h4. Gem (Recommended)
|
174
186
|
|
175
|
-
<pre>gem
|
176
|
-
sudo gem install grimen-dry_scaffold</pre>
|
187
|
+
<pre>sudo gem install grimen-dry_scaffold --source http://gems.github.com</pre>
|
177
188
|
|
178
|
-
|
179
|
-
|
180
|
-
<pre>./script/plugin install git://github.com/grimen/dry_scaffold.git</pre>
|
189
|
+
...and in config: @config/environments/development.rb@
|
181
190
|
|
182
|
-
|
191
|
+
<pre>config.gem 'grimen-dry_scaffold', :lib => 'dry_scaffold', :source => 'http://gems.github.com'</pre>
|
183
192
|
|
184
|
-
|
193
|
+
h4. Plugin
|
185
194
|
|
186
|
-
<pre
|
195
|
+
<pre>./script/plugin install git://github.com/grimen/dry_scaffold.git</pre>
|
187
196
|
|
188
|
-
h3.
|
197
|
+
h3. 2. Install Dependencies (Partly optional)
|
189
198
|
|
190
199
|
Install dependencies to release the full power of dry_scaffold. Only HAML is really required of these, but how could anyone resist candy? =)
|
191
200
|
|
192
|
-
h4. Express
|
201
|
+
h4. Automatic/Express
|
193
202
|
|
194
203
|
For us lazy ones... =)
|
195
204
|
|
@@ -197,23 +206,21 @@ For us lazy ones... =)
|
|
197
206
|
|
198
207
|
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).
|
199
208
|
|
200
|
-
h4.
|
201
|
-
|
202
|
-
Get the gems...
|
209
|
+
h4. Manual
|
203
210
|
|
204
|
-
|
205
|
-
<pre>sudo gem install will_paginate</pre>
|
206
|
-
<pre>sudo gem install justinfrench-formtastic</pre>
|
207
|
-
<pre>sudo gem install josevalim-inherited_resources</pre>
|
211
|
+
Get the gems...you want:
|
208
212
|
|
209
|
-
|
213
|
+
<pre>sudo gem install haml
|
214
|
+
sudo gem install will_paginate
|
215
|
+
sudo gem install justinfrench-formtastic
|
216
|
+
sudo gem install josevalim-inherited_resources</pre>
|
210
217
|
|
211
|
-
|
218
|
+
...and same for the config config: @config/environments/development.rb@
|
212
219
|
|
213
|
-
<pre>config.gem 'haml'
|
214
|
-
|
215
|
-
|
216
|
-
|
220
|
+
<pre>config.gem 'haml'
|
221
|
+
config.gem 'will_paginate'
|
222
|
+
config.gem 'justinfrench-formtastic', :lib => 'formtastic, :source => 'http://gems.github.com'
|
223
|
+
config.gem 'josevalim-inherited_resources', :lib => 'inherited_resources', :source => 'http://gems.github.com'</pre>
|
217
224
|
|
218
225
|
h2. Usage
|
219
226
|
|
@@ -364,7 +371,9 @@ Example:
|
|
364
371
|
|
365
372
|
<pre>--skip-resourceful --layout</pre>
|
366
373
|
|
367
|
-
h4.
|
374
|
+
h4. Scaffold
|
375
|
+
|
376
|
+
These are the options for the scaffold-generator.
|
368
377
|
|
369
378
|
* @--skip-pagination@ - Don't generate pagination of collections in controller and views, i.e. don't use *will_paginate*.
|
370
379
|
* @--skip-resourceful@ - Don't generate resourceful controller, i.e. don't use *inherited_resources*.
|
@@ -374,8 +383,10 @@ h4. General
|
|
374
383
|
* @--skip-tests@ - Don't generate tests (functional/unit/...).
|
375
384
|
* @--skip-builders@ - Don't generate builders.
|
376
385
|
* @--layout@ - Generate layout.
|
386
|
+
|
387
|
+
h4. Model
|
377
388
|
|
378
|
-
|
389
|
+
These are the options for the model/scaffold-generators.
|
379
390
|
|
380
391
|
* @--fixtures@ - Generate fixtures.
|
381
392
|
* @--fgirl@ - Generate *factory_girl* factories.
|
@@ -400,10 +411,10 @@ For your inspiration, you could try the following:
|
|
400
411
|
|
401
412
|
<pre>./script/generate dry_scaffold Zebra name:string about:text --skip-resourceful
|
402
413
|
./script/generate dry_scaffold Kangaroo name:string about:text --skip-formtastic
|
403
|
-
./script/generate
|
404
|
-
./script/generate
|
405
|
-
./script/generate
|
406
|
-
./script/generate
|
414
|
+
./script/generate dscaffold Duck name:string about:text _actions:new,create,index,quack
|
415
|
+
./script/generate dscaffold Parrot name:string about:text _formats:html,xml,yml
|
416
|
+
./script/generate dscaffold GoldFish name:string about:text _indexes:name --fgirl
|
417
|
+
./script/generate dry_model Frog name:string about:text _indexes:name,name+about --fixtures</pre>
|
407
418
|
|
408
419
|
...or just go crazy!
|
409
420
|
|
@@ -413,4 +424,6 @@ If you experience any issues/bugs or have feature requests, just file a GitHub-i
|
|
413
424
|
If you think parts of my implementation could be implemented nicer somehow, please let me know...or just fork it and fix it yourself! =)
|
414
425
|
At last, positive feedback is always appreciated!
|
415
426
|
|
416
|
-
|
427
|
+
h2. License
|
428
|
+
|
429
|
+
Copyright (c) 2009 Jonas Grimfelt, released under the MIT-license.
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ begin
|
|
20
20
|
gem.email = EMAIL
|
21
21
|
|
22
22
|
gem.require_paths = %w{lib}
|
23
|
-
gem.files = %w(MIT-LICENSE Rakefile) + SUPPORT_FILES + Dir.glob(File.join('{bin,generators,rails,tasks}', '**', '*'))
|
23
|
+
gem.files = %w(MIT-LICENSE Rakefile) + SUPPORT_FILES + Dir.glob(File.join('{bin,config,generators,lib,rails,tasks}', '**', '*'))
|
24
24
|
gem.executables = %w(dscaffold dry_scaffold dmodel dry_model)
|
25
25
|
gem.extra_rdoc_files = SUPPORT_FILES
|
26
26
|
end
|
data/TODO.textile
CHANGED
@@ -10,4 +10,4 @@ h2. Maybe later
|
|
10
10
|
* Clean-up: Comment the code a bit more =)
|
11
11
|
* Refactor: Break up in different generators: dry_controller, dry_views, etc., and use as dependencies in dry_scaffold?
|
12
12
|
* Feature: Check for overridden templates in: RAILS_ROOT/lib/dry_scaffold/templates/
|
13
|
-
* Feature: Builder for podcast-feed, similar to RSS/Atom-builders.
|
13
|
+
* Feature: Builder for podcast-feed, similar to RSS/Atom-builders. http://wiki.github.com/radiant/radiant/host-a-podcast
|
@@ -13,8 +13,8 @@ class DryModelGenerator < Rails::Generator::NamedBase
|
|
13
13
|
|
14
14
|
# Load defaults from config file - default or custom.
|
15
15
|
begin
|
16
|
-
default_config_file = File.join(File.dirname(__FILE__), '..', '..', 'config', 'scaffold.yml')
|
17
|
-
custom_config_file = File.join(Rails.root, 'config', 'scaffold.yml')
|
16
|
+
default_config_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'scaffold.yml'))
|
17
|
+
custom_config_file = File.expand_path(File.join(Rails.root, 'config', 'scaffold.yml'))
|
18
18
|
config_file = File.join(File.exist?(custom_config_file) ? custom_config_file : default_config_file)
|
19
19
|
config = YAML::load(File.open(config_file))
|
20
20
|
CONFIG_OPTIONS = config['dry_model']['options'] rescue nil
|
@@ -13,8 +13,8 @@ class DryScaffoldGenerator < Rails::Generator::NamedBase
|
|
13
13
|
|
14
14
|
# Load defaults from config file - default or custom.
|
15
15
|
begin
|
16
|
-
default_config_file = File.join(File.dirname(__FILE__), '..', '..', 'config', 'scaffold.yml')
|
17
|
-
custom_config_file = File.join(Rails.root, 'config', 'scaffold.yml')
|
16
|
+
default_config_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'scaffold.yml'))
|
17
|
+
custom_config_file = File.expand_path(File.join(Rails.root, 'config', 'scaffold.yml'))
|
18
18
|
config_file = File.join(File.exist?(custom_config_file) ? custom_config_file : default_config_file)
|
19
19
|
config = YAML::load(File.open(config_file))
|
20
20
|
CONFIG_ARGS = config['dry_scaffold']['args'] rescue nil
|
@@ -161,7 +161,7 @@ class DryScaffoldGenerator < Rails::Generator::NamedBase
|
|
161
161
|
m.directory File.join(HELPERS_PATH, controller_class_path) unless options[:skip_helpers]
|
162
162
|
m.directory File.join(VIEWS_PATH, controller_class_path, controller_file_name) unless options[:skip_views]
|
163
163
|
m.directory File.join(FUNCTIONAL_TESTS_PATH, controller_class_path) unless options[:skip_tests]
|
164
|
-
m.directory File.join(UNIT_TESTS_PATH, controller_class_path) unless options[:skip_tests]
|
164
|
+
m.directory File.join(UNIT_TESTS_PATH, 'helpers', controller_class_path) unless options[:skip_tests] || options[:skip_helpers]
|
165
165
|
|
166
166
|
# Controllers.
|
167
167
|
controller_template = options[:resourceful] ? 'inherited_resources' : 'action'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grimen-dry_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Grimfelt
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|