radiant-templates-extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/HELP_designer.textile +79 -0
  2. data/README.textile +123 -0
  3. data/Rakefile +136 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/admin/part_types_controller.rb +8 -0
  6. data/app/controllers/admin/templates_controller.rb +38 -0
  7. data/app/helpers/admin/part_types_helper.rb +26 -0
  8. data/app/helpers/admin/templates_helper.rb +108 -0
  9. data/app/models/part_type.rb +14 -0
  10. data/app/models/template.rb +80 -0
  11. data/app/models/template_part.rb +21 -0
  12. data/app/views/admin/pages/_edit_template.html.haml +32 -0
  13. data/app/views/admin/pages/_edit_template_part.html.haml +20 -0
  14. data/app/views/admin/pages/_switch_templates.html.haml +23 -0
  15. data/app/views/admin/pages/_template_column.html.haml +3 -0
  16. data/app/views/admin/pages/_template_column_header.html.haml +1 -0
  17. data/app/views/admin/part_types/_form.html.haml +36 -0
  18. data/app/views/admin/part_types/_list.html.haml +23 -0
  19. data/app/views/admin/part_types/edit.html.haml +5 -0
  20. data/app/views/admin/part_types/index.html.haml +7 -0
  21. data/app/views/admin/part_types/new.html.haml +2 -0
  22. data/app/views/admin/part_types/remove.html.haml +15 -0
  23. data/app/views/admin/templates/_form.html.haml +65 -0
  24. data/app/views/admin/templates/_template_part.html.haml +21 -0
  25. data/app/views/admin/templates/_templates_css.html.haml +12 -0
  26. data/app/views/admin/templates/edit.html.haml +10 -0
  27. data/app/views/admin/templates/index.html.haml +47 -0
  28. data/app/views/admin/templates/new.html.haml +9 -0
  29. data/app/views/admin/templates/remove.html.haml +15 -0
  30. data/config/initializers/radiant_config.rb +3 -0
  31. data/config/locales/en.yml +32 -0
  32. data/config/routes.rb +7 -0
  33. data/db/migrate/001_create_templates.rb +17 -0
  34. data/db/migrate/002_create_template_parts.rb +15 -0
  35. data/db/migrate/003_rename_sublayout_column.rb +9 -0
  36. data/db/migrate/004_add_position_to_templates.rb +13 -0
  37. data/db/migrate/005_create_part_types.rb +17 -0
  38. data/db/migrate/006_add_description_to_template_parts.rb +9 -0
  39. data/db/migrate/007_add_page_class_name_to_templates.rb +9 -0
  40. data/db/migrate/008_add_index_to_templates.rb +9 -0
  41. data/db/migrate/009_create_default_part_types.rb +23 -0
  42. data/db/migrate/010_update_boolean_part_type.rb +9 -0
  43. data/db/migrate/011_add_timestamps.rb +19 -0
  44. data/lib/file_system/model/part_type_extensions.rb +19 -0
  45. data/lib/file_system/model/template_extensions.rb +52 -0
  46. data/lib/tasks/templates_extension_tasks.rake +28 -0
  47. data/lib/templates/associations.rb +7 -0
  48. data/lib/templates/controller_extensions.rb +20 -0
  49. data/lib/templates/helper.rb +75 -0
  50. data/lib/templates/page_extensions.rb +43 -0
  51. data/lib/templates/tags.rb +43 -0
  52. data/public/images/admin/menu_arrow.png +0 -0
  53. data/public/images/admin/move_higher.png +0 -0
  54. data/public/images/admin/move_lower.png +0 -0
  55. data/public/images/admin/move_to_bottom.png +0 -0
  56. data/public/images/admin/move_to_top.png +0 -0
  57. data/public/images/admin/part_type.png +0 -0
  58. data/public/images/admin/template.png +0 -0
  59. data/spec/controllers/admin_page_controller_extensions_spec.rb +61 -0
  60. data/spec/controllers/part_types_controller_spec.rb +89 -0
  61. data/spec/controllers/templates_controller_spec.rb +322 -0
  62. data/spec/datasets/part_types_dataset.rb +15 -0
  63. data/spec/datasets/templates_dataset.rb +34 -0
  64. data/spec/helpers/templates_helper_spec.rb +56 -0
  65. data/spec/models/page_extensions_spec.rb +9 -0
  66. data/spec/models/part_type_spec.rb +28 -0
  67. data/spec/models/tags_spec.rb +44 -0
  68. data/spec/models/template_part_spec.rb +37 -0
  69. data/spec/models/template_spec.rb +88 -0
  70. data/spec/spec.opts +6 -0
  71. data/spec/spec_helper.rb +39 -0
  72. data/templates_extension.rb +83 -0
  73. data/vendor/plugins/acts_as_list/README +23 -0
  74. data/vendor/plugins/acts_as_list/init.rb +3 -0
  75. data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  76. data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
  77. data/vendor/plugins/make_resourceful/DEFAULTS +148 -0
  78. data/vendor/plugins/make_resourceful/LICENSE +7 -0
  79. data/vendor/plugins/make_resourceful/README +239 -0
  80. data/vendor/plugins/make_resourceful/Rakefile +42 -0
  81. data/vendor/plugins/make_resourceful/VERSION +1 -0
  82. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +87 -0
  83. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb +5 -0
  84. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml +10 -0
  85. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +57 -0
  86. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb +2 -0
  87. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb +13 -0
  88. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb +2 -0
  89. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb +7 -0
  90. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml +5 -0
  91. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml +11 -0
  92. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml +5 -0
  93. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml +9 -0
  94. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml +12 -0
  95. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml +14 -0
  96. data/vendor/plugins/make_resourceful/init.rb +3 -0
  97. data/vendor/plugins/make_resourceful/lib/resourceful/base.rb +52 -0
  98. data/vendor/plugins/make_resourceful/lib/resourceful/builder.rb +354 -0
  99. data/vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb +346 -0
  100. data/vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb +92 -0
  101. data/vendor/plugins/make_resourceful/lib/resourceful/default/callbacks.rb +51 -0
  102. data/vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb +118 -0
  103. data/vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb +137 -0
  104. data/vendor/plugins/make_resourceful/lib/resourceful/maker.rb +83 -0
  105. data/vendor/plugins/make_resourceful/lib/resourceful/response.rb +33 -0
  106. data/vendor/plugins/make_resourceful/lib/resourceful/serialize.rb +181 -0
  107. data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +473 -0
  108. data/vendor/plugins/make_resourceful/spec/actions_spec.rb +283 -0
  109. data/vendor/plugins/make_resourceful/spec/base_spec.rb +12 -0
  110. data/vendor/plugins/make_resourceful/spec/builder_spec.rb +332 -0
  111. data/vendor/plugins/make_resourceful/spec/callbacks_spec.rb +71 -0
  112. data/vendor/plugins/make_resourceful/spec/integration_spec.rb +396 -0
  113. data/vendor/plugins/make_resourceful/spec/maker_spec.rb +91 -0
  114. data/vendor/plugins/make_resourceful/spec/response_spec.rb +37 -0
  115. data/vendor/plugins/make_resourceful/spec/responses_spec.rb +314 -0
  116. data/vendor/plugins/make_resourceful/spec/rspec_on_rails/LICENSE +35 -0
  117. data/vendor/plugins/make_resourceful/spec/rspec_on_rails/redirect_to.rb +81 -0
  118. data/vendor/plugins/make_resourceful/spec/rspec_on_rails/render_template.rb +28 -0
  119. data/vendor/plugins/make_resourceful/spec/serialize_spec.rb +133 -0
  120. data/vendor/plugins/make_resourceful/spec/spec_helper.rb +279 -0
  121. data/vendor/plugins/make_resourceful/spec/urls_spec.rb +276 -0
  122. metadata +214 -0
@@ -0,0 +1,148 @@
1
+ There's a rough equivalence between a basic @make_resourceful@ call
2
+ and a hand-made controller.
3
+ This:
4
+
5
+ class PostsController < ApplicationController
6
+ make_resourceful { actions :all }
7
+ end
8
+
9
+ Creates a controller that works more or less like the one that follows.
10
+ Note that the real code generated by make_resourceful
11
+ is more extensible in various ways.
12
+ Thus whenever possible, there are comments in the following controller
13
+ indicating how to customize various bits of the controller.
14
+
15
+ class PostsController < ApplicationController
16
+ def index
17
+ # Override #current_objects to change this
18
+ @posts = Post.find(:all)
19
+
20
+ # Use before :index to add something here
21
+
22
+ # Use response_for :index to change this
23
+ respond_to { |f| f.html; f.js }
24
+ end
25
+
26
+ def show
27
+ # Override #current_object to change this
28
+ @post = Post.find(params[:id])
29
+
30
+ # Use before :show to add something here
31
+
32
+ # Use response_for :show to change this
33
+ respond_to { |f| f.html; f.js }
34
+ end
35
+
36
+ def create
37
+ # Override #build_object to change this
38
+ @post = Post.new(params[:post])
39
+
40
+ # Use before :create to add something here
41
+
42
+ if @post.save
43
+ # Use after :create to add something here
44
+
45
+ # Use response_for :create to change this
46
+ respond_to do |f|
47
+ f.html do
48
+ flash[:notice] = "Create successful!"
49
+ redirect_to post_path(@post)
50
+ end
51
+ f.js
52
+ end
53
+ else
54
+ # Use after :create_fails to add something here
55
+
56
+ # Use response_for :create_fails to change this
57
+ respond_to do |f|
58
+ format.html
59
+ flash[:error] = "There was a problem!"
60
+ render :action => :new, :status => 422
61
+ end
62
+ format.js
63
+ end
64
+ end
65
+ end
66
+
67
+ def update
68
+ # Override #current_object to change this
69
+ @post = Post.find(params[:id])
70
+
71
+ # Use before :update to do something here
72
+
73
+ if @post.update_attributes params[:post]
74
+ # Use after :update to add something here
75
+
76
+ # Use response_for :update to change this
77
+ respond_to do |f|
78
+ f.html do
79
+ flash[:notice] = "Save successful!"
80
+ redirect_to post_path(@post)
81
+ end
82
+ f.js
83
+ end
84
+ else
85
+ # Use after :update_fails to add something here
86
+
87
+ # Use response_for :update_fails to change this
88
+ respond_to do |f|
89
+ format.html
90
+ flash[:error] = "There was a problem saving!"
91
+ render :action => :edit, :status => 422
92
+ end
93
+ format.js
94
+ end
95
+ end
96
+ end
97
+
98
+ def new
99
+ # Override #build_object to change this
100
+ @post = Post.new(params[:post])
101
+
102
+ # Use before :new to add something here
103
+
104
+ # Use response_for :new to change this
105
+ respond_to { |f| f.html; f.js }
106
+ end
107
+
108
+ def edit
109
+ # Override #current_object to change this
110
+ @post = Post.find(params[:id])
111
+
112
+ # Use before :edit to add something here
113
+
114
+ # Use response_for :edit to change this
115
+ respond_to { |f| f.html; f.js }
116
+ end
117
+
118
+ def destroy
119
+ # Override #current_object to change this
120
+ @post = Post.find(params[:id])
121
+
122
+ # Use before :destroy to do something here
123
+
124
+ if @post.destroy
125
+ # Use after :destroy to add something here
126
+
127
+ # Use response_for :destroy to change this
128
+ respond_to do |f|
129
+ f.html do
130
+ flash[:notice] = "Record deleted!"
131
+ redirect_to posts_path(@post)
132
+ end
133
+ f.js
134
+ end
135
+ else
136
+ # Use after :destroy_fails to add something here
137
+
138
+ # Use response_for :destroy_fails to change this
139
+ respond_to do |f|
140
+ format.html
141
+ flash[:error] = "There was a problem deleting!"
142
+ render :back
143
+ end
144
+ format.js
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2007 Hampton Catlin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,239 @@
1
+ = make_resourceful
2
+ ===== Take back control of your Controllers. Make them awesome. Make them sleek. Make them resourceful.
3
+
4
+ REST is a fine pattern for designing controllers,
5
+ but it can be pretty repetitive.
6
+ Who wants to write out the same actions and copy the same model lookup logic
7
+ all over their application?
8
+
9
+ make_resourceful handles all that for you.
10
+ It sets up all your RESTful actions and responses with next to no code.
11
+ Everything has full, sensible default functionality.
12
+
13
+ Of course, no controller _only_ uses the defaults.
14
+ So make_resourceful can be massively customized,
15
+ while still keeping your controllers trim and readable.
16
+
17
+ == Get it!
18
+
19
+ Rails
20
+
21
+ $ ruby script/plugin install http://svn.hamptoncatlin.com/make_resourceful/trunk
22
+ $ mv vendor/plugins/trunk vendor/plugins/make_resourceful
23
+
24
+ Subversion
25
+
26
+ $ svn co http://svn.hamptoncatlin.com/make_resourceful/trunk make_resourceful
27
+
28
+ == Use it!
29
+
30
+ The easiest way to start with make_resourceful
31
+ is to run the resource_scaffold generator.
32
+ It uses the same syntax as the Rails scaffold_resource generator:
33
+
34
+ $ script/generate resource_scaffold post title:string body:text
35
+
36
+ It does, however, require Haml[http://haml.hamptoncatlin.com].
37
+ You _are_ using Haml, right? No?
38
+ I'll wait here while you go fall in love with it.
39
+
40
+ If you want to try make_resourceful on one of your current controllers,
41
+ just replace the mess of repetition with this:
42
+
43
+ class FooController < ApplicationController
44
+ make_resourceful do
45
+ actions :all
46
+ end
47
+ end
48
+
49
+ Those three lines will replace the entire default controller
50
+ that comes out of the scaffold_resource generator.
51
+
52
+ === Really?
53
+
54
+ Yes.
55
+
56
+ === Can I do nested resources?
57
+
58
+ make_resourceful do
59
+ actions :all
60
+ belongs_to :post
61
+ end
62
+
63
+ === What if I want to use fancy permalinks?
64
+
65
+ def current_object
66
+ @current_object ||= current_model.find_by_permalink(params[:id])
67
+ end
68
+
69
+ === What about paging?
70
+
71
+ def current_objects
72
+ @current_object ||= current_model.find(:all,
73
+ :order => "created_at DESC", :page => {:current => params[:page], :size => 10 } )
74
+ end
75
+
76
+ === What if I want to do something in the middle of an action?
77
+
78
+ before :show, :index do
79
+ @page_title = "Awesome!"
80
+ end
81
+
82
+ after :create_fails do
83
+ @page_title = "Not So Awesome!"
84
+ end
85
+
86
+ === What about all of my awesome respond_to blocks for my XML APIs and RJS responses?
87
+
88
+ response_for :show do |format|
89
+ format.html
90
+ format.js
91
+ format.xml
92
+ end
93
+
94
+ response_for :update_fails do |format|
95
+ format.html { render :action => 'edit' }
96
+ format.json { render :json => false.to_json, :status => 422 }
97
+ end
98
+
99
+ === So I guess I have to write responses for all my actions?
100
+
101
+ Nope! make_resourceful makes them do the right thing by default.
102
+ You only need to customize them if you want to do something special.
103
+
104
+ === Seriously?!
105
+
106
+ Yes!
107
+
108
+ == Grok it!
109
+
110
+ === +make_resourceful+ the Method
111
+
112
+ The +make_resourceful+ block is where most of the action happens.
113
+ Here you specify which actions you want to auto-generate,
114
+ what code you want to run for given callbacks,
115
+ and so forth.
116
+
117
+ You also use the block to declare various bits of information about your controller.
118
+ For instance, if the controller is nested, you'd call +belongs_to+.
119
+ If you wanted to expose your models as some sort of text format,
120
+ you'd call +publish+.
121
+
122
+ Check out the documentation of Resourceful::Builder
123
+ for more information on the methods you can call here.
124
+
125
+ === Helper Methods
126
+
127
+ make_resourceful provides lots of useful methods
128
+ that can be used in your callbacks and in your views.
129
+ They range from accessing the records you're looking up
130
+ to easily generating URLs for a record
131
+ to getting information about the action itself.
132
+
133
+ Two of the most useful methods are +current_object+ and +current_objects+
134
+ (note the subtle plurality difference).
135
+ +current_objects+ only works for +index+,
136
+ and returns all the records in the current model.
137
+ +current_object+ works for all actions other than +index+,
138
+ and returns the record that's currently being dealt with.
139
+
140
+ The full documentation of the helper methods
141
+ is in Resourceful::Default::Accessors and Resourceful::Default::URLs.
142
+
143
+ === Nested Resources
144
+
145
+ make_resourceful supports easy management of nested resources.
146
+ This is set up with the Resourceful::Builder#belongs_to declaration.
147
+ Pass in the name of the parent model,
148
+
149
+ belongs_to :user
150
+
151
+ and everything will be taken care of.
152
+ When +index+ is run for GET /users/12/albums,
153
+ parent_object[link:classes/Resourceful/Accessors.html#M000024]
154
+ will get <tt>User.find(params[:user_id])</tt>,
155
+ and current_objects[link:classes/Resourceful/Default/Accessors.html#M000010]
156
+ will get <tt>parent_object.albums</tt>.
157
+ When +create+ is run for POST /users/12/albums,
158
+ the newly created Album will automatically belong to the user
159
+ with id 12.
160
+
161
+ The normal non-scoped actions still work, too.
162
+ GET /albums/15 runs just fine.
163
+ make_resourceful knows that since there's no <tt>params[:user_id]</tt>,
164
+ you just want to deal with the album.
165
+
166
+ You can even have a single resource nested under several different resources.
167
+ Just pass multiple parent names to the Resourceful::Builder#belongs_to, like
168
+
169
+ belongs_to :user, :artist
170
+
171
+ Then /users/15/albums and /artists/7/albums will both work.
172
+
173
+ This does, however, mean that make_resourceful only supports one level of nesting.
174
+ There's no automatic handling of /users/15/collections/437/albums.
175
+ However, this is really the best way to organize most resources anyway;
176
+ see this article[http://weblog.jamisbuck.org/2007/2/5/nesting-resources].
177
+
178
+ If you really need a deeply nested controller,
179
+ it should be easy enough to set up on your own.
180
+ Just override current_model[link:classes/Resourceful/Default/Accessors.html#M000018].
181
+ See the next section for more details.
182
+
183
+ === Overriding Methods
184
+
185
+ Not only are helper methods useful to the developer to use,
186
+ they're used internally by the actions created by make_resourceful.
187
+ Thus one of the main ways make_resourceful can be customized
188
+ is by overriding accessors.
189
+
190
+ For instance, if you want to only look up the 10 most recent records for +index+,
191
+ you're override +current_objects+.
192
+ If you wanted to use a different model than that suggested by the name of the controller,
193
+ you'd override +current_model+.
194
+
195
+ When you're overriding methods that do SQL lookups, though, be a little cautious.
196
+ By default, these methods cache their values in instance variables
197
+ so that multiple SQL queries aren't run on multiple calls.
198
+ When overriding them, it's wise for you to do the same.
199
+ For instance,
200
+
201
+ def current_object
202
+ @current_object ||= current_model.find_by_name(params[:name])
203
+ end
204
+
205
+ === For More Information...
206
+
207
+ Haven't found all the information you need in the RDoc?
208
+ Still a little confused about something?
209
+ Don't despair, there are still more resources available!
210
+
211
+ * Nathan Weizenbaum periodically makes blog posts about new features and versions of make_resourceful.
212
+ They may be a little outdated, but they should still be useful and explanatory.
213
+ * On nesting and associations: here[http://nex-3.com/posts/55-nesting-and-make_resourceful].
214
+ * An overview of make_resourceful 0.2.0 and 0.2.2: here[http://localhost:3000/posts/54-make_resourceful-0-2-0].
215
+ * On Resourceful::Builder#publish[link:classes/Resourceful/Builder.html#M000061]
216
+ and Resourceful::Serialize:
217
+ here[http://nex-3.com/posts/35-make_resourceful-the-basics-of-publish] and
218
+ here[http://nex-3.com/posts/36-make_resourceful-publish-extras].
219
+ * There's an excellent, active Google Group (link[http://groups.google.com/group/make_resourceful])
220
+ where people will be happy to answer your questions.
221
+ * Read the source code!
222
+ It's very straightforward,
223
+ and make_resourceful is built to encourage overriding methods
224
+ and hacking the source.
225
+
226
+ ---
227
+
228
+ Copyright 2007 Hampton Catlin, Nathan Weizenbaum, and Jeff Hardy.
229
+
230
+ Contributions by:
231
+
232
+ * Russell Norris
233
+ * Jonathan Linowes
234
+ * Cristi Balan
235
+ * Mike Ferrier
236
+ * James Golick
237
+ * Don Petersen
238
+ * Alex Ross
239
+ * Tom Stuart
@@ -0,0 +1,42 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'spec/rake/spectask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ spec_files = Rake::FileList["spec/**/*_spec.rb"]
10
+
11
+ desc "Run specs"
12
+ Spec::Rake::SpecTask.new do |t|
13
+ t.spec_files = spec_files
14
+ t.spec_opts = ["-c"]
15
+ end
16
+
17
+ desc "Generate code coverage"
18
+ Spec::Rake::SpecTask.new(:coverage) do |t|
19
+ t.spec_files = spec_files
20
+ t.rcov = true
21
+ t.rcov_opts = ['--exclude', 'spec,/var/lib/gems']
22
+ end
23
+
24
+ desc 'Test the make_resourceful plugin.'
25
+ task :test do
26
+ Dir.chdir(File.dirname(__FILE__) + '/test')
27
+ tests = IO.popen('rake test')
28
+
29
+ while byte = tests.read(1)
30
+ print byte
31
+ end
32
+ end
33
+
34
+ desc 'Generate documentation for the make_resourceful plugin.'
35
+ Rake::RDocTask.new(:rdoc) do |rdoc|
36
+ rdoc.rdoc_dir = 'rdoc'
37
+ rdoc.title = 'make_resourceful'
38
+ rdoc.options << '--line-numbers' << '--inline-source'
39
+ rdoc.main = 'README'
40
+ rdoc.rdoc_files.include(FileList.new('*').exclude(/[^A-Z0-9]/))
41
+ rdoc.rdoc_files.include('lib/**/*.rb')
42
+ end
@@ -0,0 +1 @@
1
+ 0.2.3.0
@@ -0,0 +1,87 @@
1
+ class ResourcefulScaffoldGenerator < Rails::Generator::NamedBase
2
+ attr_reader :controller_class_path,
3
+ :controller_file_path,
4
+ :controller_class_nesting,
5
+ :controller_class_nesting_depth,
6
+ :controller_class_name,
7
+ :controller_underscore_name,
8
+ :controller_plural_name
9
+ alias_method :controller_file_name, :controller_underscore_name
10
+ alias_method :controller_table_name, :controller_plural_name
11
+
12
+ def initialize(runtime_args, runtime_options = {})
13
+ super
14
+
15
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@name.pluralize)
16
+ @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
17
+
18
+ if @controller_class_nesting.empty?
19
+ @controller_class_name = @controller_class_name_without_nesting
20
+ else
21
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
22
+ end
23
+ end
24
+
25
+ def manifest
26
+ record do |m|
27
+ # Check for class naming collisions.
28
+ m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
29
+ m.class_collisions(class_path, "#{class_name}")
30
+
31
+ # Controller, helper, views, and test directories.
32
+ m.directory(File.join('app/models', class_path))
33
+ m.directory(File.join('app/controllers', controller_class_path))
34
+ m.directory(File.join('app/helpers', controller_class_path))
35
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
36
+ m.directory(File.join('test/functional', controller_class_path))
37
+ m.directory(File.join('test/unit', class_path))
38
+ m.directory(File.join('test/fixtures', class_path))
39
+
40
+ # Views
41
+ for action in scaffold_views
42
+ m.template("view_#{action}.haml", File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.haml"))
43
+ end
44
+ m.template('view_partial.haml', File.join('app/views', controller_class_path, controller_file_name, "_#{singular_name}.html.haml"))
45
+
46
+ # Helper
47
+ m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
48
+
49
+ # Model
50
+ m.template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
51
+
52
+ unless options[:skip_migration]
53
+ m.migration_template('migration.rb', 'db/migrate',
54
+ :assigns => {
55
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
56
+ :attributes => attributes
57
+ },
58
+ :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}")
59
+ end
60
+
61
+ # Controller
62
+ m.template('controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb"))
63
+
64
+ # Tests
65
+ m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
66
+ m.template('unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"))
67
+ m.template('fixtures.yml', File.join('test/fixtures', "#{table_name}.yml"))
68
+
69
+ # Route
70
+ m.route_resources controller_file_name
71
+ end
72
+ end
73
+
74
+ protected
75
+
76
+ def banner
77
+ "Usage: #{$0} resourcefulscaffold ModelName [field:type, field:type]"
78
+ end
79
+
80
+ def scaffold_views
81
+ %w[ index show new edit _form ]
82
+ end
83
+
84
+ def model_name
85
+ class_name.demodulize
86
+ end
87
+ end