localized_scaffold 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Gemfile +6 -0
  2. data/README.rdoc +273 -0
  3. data/generators/locales/standard.de-FO.yml +106 -0
  4. data/generators/locales/standard.de.yml +106 -0
  5. data/generators/locales/standard.en.yml +106 -0
  6. data/generators/localized_devise_views_generator.rb +100 -0
  7. data/generators/localized_scaffold_generator.rb +624 -0
  8. data/generators/templates/devise/locales/devise.de-FO.yml +45 -0
  9. data/generators/templates/devise/locales/devise.de.yml +60 -0
  10. data/generators/templates/devise/locales/devise_views.de.yml +78 -0
  11. data/generators/templates/devise/locales/devise_views.en.yml +79 -0
  12. data/generators/templates/devise/views/confirmations/new.html.erb +23 -0
  13. data/generators/templates/devise/views/mailer/confirmation_instructions.html.erb +6 -0
  14. data/generators/templates/devise/views/mailer/reset_password_instructions.html.erb +8 -0
  15. data/generators/templates/devise/views/mailer/unlock_instructions.html.erb +6 -0
  16. data/generators/templates/devise/views/passwords/edit.html.erb +30 -0
  17. data/generators/templates/devise/views/passwords/new.html.erb +23 -0
  18. data/generators/templates/devise/views/registrations/edit.html.erb +54 -0
  19. data/generators/templates/devise/views/registrations/new.html.erb +34 -0
  20. data/generators/templates/devise/views/sessions/new.html.erb +32 -0
  21. data/generators/templates/devise/views/shared/_links.erb +25 -0
  22. data/generators/templates/devise/views/unlocks/new.html.erb +23 -0
  23. data/generators/templates/erb/scaffold/_form.html.erb +11 -0
  24. data/generators/templates/erb/scaffold/_index.html.erb +54 -0
  25. data/generators/templates/erb/scaffold/edit.html.erb +20 -0
  26. data/generators/templates/erb/scaffold/index.html.erb +73 -0
  27. data/generators/templates/erb/scaffold/layout.html.erb +51 -0
  28. data/generators/templates/erb/scaffold/new.html.erb +18 -0
  29. data/generators/templates/erb/scaffold/scaffold_generator.rb +57 -0
  30. data/generators/templates/erb/scaffold/show.html.erb +22 -0
  31. data/generators/templates/locales/de.yml +61 -0
  32. data/generators/templates/locales/en.yml +61 -0
  33. data/generators/templates/rails/helper/helper.rb +118 -0
  34. data/generators/templates/rails/helper/scaffold_helper.rb +53 -0
  35. data/generators/templates/rails/scaffold_controller/controller.rb +338 -0
  36. data/generators/templates/rails/stylesheets/templates/scaffold.css +203 -0
  37. data/generators/templates/test_unit/scaffold/templates/functional_test.rb +117 -0
  38. data/init.rb +3 -0
  39. data/install.rb +1 -0
  40. data/lib/tasks/localized_scaffold.rake +39 -0
  41. data/localized_scaffold.rb +7 -0
  42. data/rails/init.rb +3 -0
  43. data/test/localized_scaffold_test.rb +8 -0
  44. data/test/test_helper.rb +3 -0
  45. data/uninstall.rb +1 -0
  46. metadata +120 -0
@@ -0,0 +1,338 @@
1
+ # The code in this file implements controller class <%= controller_class_name %>Controller.
2
+
3
+ <%- if has_will_paginate? -%>
4
+ require 'will_paginate'
5
+
6
+ <%- end -%>
7
+ # The <%= controller_class_name %>Controller implements the user interface for handling
8
+ # <%= class_name %> objects<% if has_belongsto? -%> of a <%= belongsto.class_name %> object<% end %>.
9
+
10
+ class <%= controller_class_name %>Controller < ApplicationController
11
+ <% if has_belongsto? -%>
12
+ before_filter :setup_<%= belongsto.file_name %>
13
+
14
+ <% end -%>
15
+ before_filter :setup_<%= file_name %>, :except => [ <% unless options[:singleton] %>:index, <% end %>:new, :create ]
16
+ <%- if has_searchbar? %>
17
+ # Helper classes wrapping search term and matching chars.
18
+
19
+ Searchbar = Struct.new(:chars, :term)
20
+ <% end -%>
21
+ <%- unless options[:singleton] %>
22
+ # Action listing all <%= table_name %><% if has_belongsto? -%> of a certain <%= belongsto.file_name %><% end %>.
23
+ #
24
+ <%- if has_belongsto? or has_searchbar? or has_will_paginate? -%>
25
+ # Action parameters:
26
+ #
27
+ <%- end -%>
28
+ <%- if has_belongsto? -%>
29
+ # [:<%= belongsto.file_name %>_id] ID of parent <%= belongsto.file_name %>
30
+ <%- end -%>
31
+ <%- if has_searchbar? -%>
32
+ # [:q] Chars a matching <%= file_name %> has to start with
33
+ <%- end -%>
34
+ <%- if has_will_paginate? -%>
35
+ # [:page] Page to display (defaults to 1)
36
+ <%- end -%>
37
+ #
38
+ # Routes:
39
+ #
40
+ # GET <%= belongsto_route_prefix_if_any %>/<%= table_name %>
41
+ # GET <%= belongsto_route_prefix_if_any %>/<%= table_name %>.xml
42
+
43
+ def index
44
+ <%- if has_searchbar? -%>
45
+ <%- if has_belongsto? -%>
46
+ chars = <%= class_name %>.<%= searchbar %>_chars(@<%= belongsto.file_name %>.id).collect { |i| i[0] }
47
+ <%- else -%>
48
+ chars = <%= class_name %>.<%= searchbar %>_chars.collect { |i| i[0] }
49
+ <%- end -%>
50
+
51
+ term = params[:q]
52
+ term = chars.first if term.blank? or term == t('standard.cmds.search')
53
+ term = 'a' if term.blank?
54
+
55
+ @searchbar = Searchbar.new(chars, term)
56
+
57
+ <%- extraargs = ":order => '#{table_name}.#{searchbar} asc',
58
+ :conditions => ['lower(#{table_name}.#{searchbar}) like ?',
59
+ term.downcase + '%']" -%>
60
+ <%- else -%>
61
+ <%- extraargs = '' -%>
62
+ <%- end -%>
63
+ <%- if has_belongsto? -%>
64
+ <%- if has_will_paginate? -%>
65
+ @<%= table_name %> = @<%= belongsto.file_name %>.<%= table_name %>.paginate(:all, :page => current_page<%= extraargs.blank? ? '' : ", #{extraargs}" %>)
66
+ <%- else -%>
67
+ @<%= table_name %> = @<%= belongsto.file_name %>.<%= table_name %>.all<%= extraargs.blank? ? '' : "(#{extraargs})" %>
68
+ <%- end -%>
69
+ <%- else -%>
70
+ <%- if has_will_paginate? -%>
71
+ @<%= table_name %> = <%= class_name %>.paginate(:all, :page => current_page<%= extraargs.blank? ? '' : ", #{extraargs}" %>)
72
+ <%- else -%>
73
+ @<%= table_name %> = <%= class_name %>.all<%= extraargs.blank? ? '' : "(#{extraargs})" %>
74
+ <%- end -%>
75
+ <%- end -%>
76
+
77
+ respond_to do |format|
78
+ <%- if not has_belongsto? or has_searchbar? or not embed? -%>
79
+ format.html { redirect_to(<%= path_of_with_belongsto_if_any %>) if not params[:q].blank? and @<%= table_name %>.empty? }
80
+ <%- else -%>
81
+ format.html { flash.keep && redirect_to(<%= belongsto.singular_name %>_path(@<%= belongsto.singular_name %>)) if @<%= table_name %>.count <= <%= class_name %>::PARENT_EMBED }
82
+ <%- end -%>
83
+ format.xml { render :xml => @<%= table_name %> }
84
+ format.json { render :json => json_wrap({ :records => @<%= table_name %>,
85
+ :ids => @<%= table_name %>.map(&:id),
86
+ :count => @<%= table_name %>.count }) }
87
+ end
88
+ end
89
+ <%- end -%>
90
+
91
+ # Action displaying a single <%= file_name %>.
92
+ #
93
+ # Action parameters:
94
+ #
95
+ <%- if has_belongsto? -%>
96
+ # [:<%= belongsto.file_name %>_id] ID of parent <%= belongsto.file_name %>
97
+ <%- end -%>
98
+ # [:id] ID of the <%= file_name %> to display
99
+ #
100
+ # Routes:
101
+ #
102
+ # GET <%= belongsto_route_prefix_if_any %>/<%= table_name %>/1
103
+ # GET <%= belongsto_route_prefix_if_any %>/<%= table_name %>/1.xml
104
+
105
+ def show
106
+ respond_to do |format|
107
+ <%- if generate_showview? -%>
108
+ format.html # show.html.erb
109
+ <%- else -%>
110
+ format.html { flash.keep && redirect_to(<%= path_of_with_belongsto_if_any(:extraargs => (has_searchbar? ? ":q => @#{file_name}.#{searchbar}.first" : nil)) %>) }
111
+ <%- end -%>
112
+ format.xml { render :xml => @<%= file_name %> }
113
+ format.json { render :json => json_wrap(@<%= file_name %>) }
114
+ end
115
+ end
116
+
117
+ # Action displaying a form for creating a new <%= file_name %>.
118
+ #
119
+ <%- if has_belongsto? -%>
120
+ # Action parameters:
121
+ #
122
+ # [:<%= belongsto.file_name %>_id] ID of parent <%= belongsto.file_name %>
123
+ #
124
+ <%- end -%>
125
+ # Routes:
126
+ #
127
+ # GET <%= belongsto_route_prefix_if_any %>/<%= table_name %>/new
128
+ # GET <%= belongsto_route_prefix_if_any %>/<%= table_name %>/new.xml
129
+
130
+ def new
131
+ <%- if has_belongsto? -%>
132
+ @<%= file_name %> = @<%= belongsto.file_name %>.<%= table_name %>.new
133
+ <%- else -%>
134
+ @<%= file_name %> = <%= class_name %>.new
135
+ <%- end -%>
136
+
137
+ respond_to do |format|
138
+ format.html # new.html.erb
139
+ format.xml { render :xml => @<%= file_name %> }
140
+ format.json { render :json => json_wrap(@<%= file_name %>) }
141
+ end
142
+ end
143
+
144
+ # Action displaying an edit form for a <%= file_name %>.
145
+ #
146
+ # Action parameters:
147
+ #
148
+ <%- if has_belongsto? -%>
149
+ # [:<%= belongsto.file_name %>_id] ID of parent <%= belongsto.file_name %>
150
+ <%- end -%>
151
+ # [:id] ID of the <%= file_name %> to edit
152
+ #
153
+ # Routes:
154
+ #
155
+ # GET <%= belongsto_route_prefix_if_any %>/<%= table_name %>/1/edit
156
+
157
+ def edit
158
+ end
159
+
160
+ # Action creating a new <%= file_name %>.
161
+ #
162
+ # Action parameters:
163
+ #
164
+ <%- if has_belongsto? -%>
165
+ # [:<%= belongsto.file_name %>_id] ID of parent <%= belongsto.file_name %>
166
+ <%- end -%>
167
+ # [:<%= file_name %>[]] Form data
168
+ #
169
+ # Routes:
170
+ #
171
+ # POST <%= belongsto_route_prefix_if_any %>/<%= table_name %>
172
+ # POST <%= belongsto_route_prefix_if_any %>/<%= table_name %>.xml
173
+
174
+ def create
175
+ data = params[:<%= file_name %>].slice(<%= shell.base.attributes.collect { |a|
176
+ a.name == 'id' or (has_belongsto? and a.name == "#{belongsto.file_name}_id") ? nil : ":#{a.name}" }.compact.join(', ') %>)
177
+
178
+ <%- if has_belongsto? -%>
179
+ @<%= file_name %> = @<%= belongsto.file_name %>.<%= table_name %>.new(data)
180
+ <%- else -%>
181
+ @<%= file_name %> = <%= class_name %>.new(data)
182
+ <%- end -%>
183
+
184
+ respond_to do |format|
185
+ if @<%= file_name %>.save
186
+ flash[:notice] = t('<%= file_name %>.create.flash')
187
+
188
+ format.html { redirect_to(<%= path_of_with_belongsto_if_any(:method => :show) %>) }
189
+ format.xml { render :xml => @<%= file_name %>, :status => :created,
190
+ :location => @<%= file_name %> }
191
+ format.json { render :json => json_wrap(@<%= file_name %>) }
192
+ else
193
+ format.html { render :action => 'new' }
194
+ format.xml { render :xml => @<%= file_name %>.errors,
195
+ :status => :unprocessable_entity }
196
+ format.json { render :json => json_wrap(@<%= file_name %>.errors),
197
+ :status => :unprocessable_entity }
198
+ end
199
+ end
200
+ end
201
+
202
+ # Action updating a <%= file_name %>.
203
+ #
204
+ # Action parameters:
205
+ #
206
+ <%- if has_belongsto? -%>
207
+ # [:<%= belongsto.file_name %>_id] ID of parent <%= belongsto.file_name %>
208
+ <%- end -%>
209
+ # [:id] ID of the <%= file_name %> to update
210
+ # [:<%= file_name %>[]] Form data
211
+ #
212
+ # Routes:
213
+ #
214
+ # PUT <%= belongsto_route_prefix_if_any %>/<%= table_name %>/1
215
+ # PUT <%= belongsto_route_prefix_if_any %>/<%= table_name %>/1.xml
216
+
217
+ def update
218
+ data = params[:<%= file_name %>].slice(<%= shell.base.attributes.collect { |a|
219
+ a.name == 'id' or (has_belongsto? and a.name == "#{belongsto.file_name}_id") ? nil : ":#{a.name}" }.compact.join(', ') %>)
220
+
221
+ respond_to do |format|
222
+ if @<%= file_name %>.update_attributes(data)
223
+ flash[:notice] = t('<%= file_name %>.update.flash')
224
+
225
+ format.html { redirect_to(<%= path_of_with_belongsto_if_any(:method => :show) %>) }
226
+ format.xml { head :ok }
227
+ format.json { head :ok }
228
+ else
229
+ format.html { render :action => 'edit' }
230
+ format.xml { render :xml => @<%= file_name %>.errors,
231
+ :status => :unprocessable_entity }
232
+ format.json { render :json => json_wrap(@<%= file_name %>.errors),
233
+ :status => :unprocessable_entity }
234
+ end
235
+ end
236
+ end
237
+
238
+ # Action deleting a <%= file_name %>.
239
+ #
240
+ # Action parameters:
241
+ #
242
+ <%- if has_belongsto? -%>
243
+ # [:<%= belongsto.file_name %>_id] ID of parent <%= belongsto.file_name %>
244
+ <%- end -%>
245
+ # [:id] ID of the <%= file_name %> to delete
246
+ #
247
+ # Routes:
248
+ #
249
+ # DELETE <%= belongsto_route_prefix_if_any %>/<%= table_name %>/1
250
+ # DELETE <%= belongsto_route_prefix_if_any %>/<%= table_name %>/1.xml
251
+
252
+ def destroy
253
+ @<%= file_name %>.destroy
254
+
255
+ respond_to do |format|
256
+ flash[:notice] = t('<%= file_name %>.destroy.flash')
257
+
258
+ format.html { redirect_to(<%= path_of_with_belongsto_if_any(:extraargs => (has_searchbar? ? ":q => @#{file_name}.#{searchbar}.first" : nil)) %>) }
259
+ format.xml { head :ok }
260
+ format.json { head :ok }
261
+ end
262
+ end
263
+
264
+ protected
265
+
266
+ # Before filter setting up @<%= file_name %> needed by most actions.
267
+
268
+ def setup_<%= file_name %>
269
+ <%- if has_belongsto? -%>
270
+ @<%= file_name %> = @<%= belongsto.file_name %>.<%= table_name %>.find(params[:id])
271
+ <%- else -%>
272
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
273
+ <%- end -%>
274
+
275
+ if @<%= file_name %>.nil?
276
+ flash[:error] = t('<%= file_name %>.errors.not_found')
277
+
278
+ respond_to do |format|
279
+ format.html { redirect_to(defined?(home_path) ? home_path : '/') }
280
+ format.xml { head 404 }
281
+ format.json { head 404 }
282
+ end
283
+
284
+ return false
285
+ end
286
+
287
+ return true
288
+ end
289
+ <%- if has_belongsto? -%>
290
+
291
+ # Before filter setting up "parent" belongs_to object @<%= belongsto.file_name %>
292
+ # needed by most actions.
293
+
294
+ def setup_<%= belongsto.file_name %>
295
+ @<%= belongsto.file_name %> = <%= belongsto.class_name %>.find(params[:<%= belongsto.file_name %>_id])
296
+
297
+ if @<%= belongsto.file_name %>.nil?
298
+ flash[:error] = _('<%= belongsto.file_name %>.errors.not_found')
299
+
300
+ respond_to do |format|
301
+ format.html { redirect_to(defined?(home_path) ? home_path : '/') }
302
+ format.xml { head 404 }
303
+ format.json { head 404 }
304
+ end
305
+
306
+ return false
307
+ end
308
+ end
309
+ <%- end -%>
310
+ <%- if has_will_paginate? -%>
311
+
312
+ # Returns the current page number for pagination.
313
+
314
+ def current_page
315
+ return (@page ||= params[:page].blank? ? 1 : params[:page].to_i)
316
+ end
317
+ <%- end -%>
318
+
319
+ # Returns a JSON version of the provided data optionally wrapped with a
320
+ # callback method (if action parameter :jsoncallback exists) or variable
321
+ # assignment (if action parameter :jsonvar) as expected by many toolkits.
322
+ #
323
+ # Parameters:
324
+ #
325
+ # [data] Data to marshal
326
+
327
+ def json_wrap(data)
328
+ if not (callback = params[:jsoncallback]).blank?
329
+ return callback + '(' + data.to_json + ')'
330
+ end
331
+
332
+ if not (var = params[:jsonvar]).blank?
333
+ return var + '=' + data.to_json
334
+ end
335
+
336
+ return data.to_json
337
+ end
338
+ end
@@ -0,0 +1,203 @@
1
+ body {
2
+ background-color: #ffffff;
3
+ color: #222222;
4
+ }
5
+
6
+ body, p, ol, ul, table, td, th {
7
+ font-family: 'Lucida Grande', Tahoma, Arial, Helvetica, sans-serif;
8
+ font-size: 13px;
9
+ line-height: 18px;
10
+ }
11
+
12
+ pre {
13
+ background-color: #f0f0f0;
14
+ padding: 10px;
15
+ font-size: 11px;
16
+ }
17
+
18
+ a {
19
+ color: #000000;
20
+ }
21
+ a:visited {
22
+ color: #000000;
23
+ }
24
+ a:hover {
25
+ color: #ffffff;
26
+ background-color: #000000;
27
+ }
28
+
29
+ h1 {
30
+ clear: both
31
+ }
32
+
33
+ label {
34
+ color: #666666;
35
+ }
36
+
37
+ #breadcrumbs
38
+ {
39
+ list-style: none;
40
+ font-size: 80%;
41
+ padding: 0;
42
+ margin: 0;
43
+ }
44
+
45
+ #breadcrumbs li
46
+ {
47
+ display: inline;
48
+ padding: 0;
49
+ margin: 0;
50
+ }
51
+
52
+ #breadcrumbs li:before { content: " > "; }
53
+ #breadcrumbs li:first-child:before { content: ""; }
54
+
55
+ table.noborder td {
56
+ border: 0px;
57
+ }
58
+ table.nopad td {
59
+ padding-left: 0px;
60
+ }
61
+ table {
62
+ border-collapse: collapse;
63
+ }
64
+ table.wide {
65
+ width: 100%;
66
+ }
67
+ table tr th {
68
+ background: none;
69
+ text-align: left;
70
+ font-size: 0.9em;
71
+ padding: 2px 0px;
72
+ }
73
+ table tr {
74
+ border-bottom: 1px solid #dddddd;
75
+ }
76
+ table tr td {
77
+ padding: 3px 0px;
78
+ }
79
+ table.top tr td {
80
+ vertical-align: top;
81
+ }
82
+ table tr td.last {
83
+ background: #f0f0f0;
84
+ font-size: 0.9em;
85
+ padding: 3px 8px;
86
+ width: 25%;
87
+ }
88
+
89
+ div.pagination {
90
+ display: inline;
91
+ }
92
+
93
+ table.searchbar, table.searchbar td, table.searchbar tr {
94
+ border: none;
95
+ }
96
+
97
+ table.searchbar td {
98
+ padding: 0px 5px 10px 0px;
99
+ vertical-align: baseline;
100
+ }
101
+ table.searchbar td a {
102
+ font-weight: bold;
103
+ }
104
+ table.searchbar td.selected strong {
105
+ font-size: 130%;
106
+ }
107
+
108
+ div.pagination a {
109
+ border: 1px solid gray;
110
+ padding: 1px 3px;
111
+ text-decoration: none;
112
+ }
113
+ div.pagination a:hover {
114
+ }
115
+ div.pagination a.previous_page, div.pagination a.next_page {
116
+ border: none;
117
+ }
118
+ div.pagination em {
119
+ font-style: normal;
120
+ }
121
+ div.pagination span.disabled {
122
+ color: #808080;
123
+ }
124
+
125
+ .decent, .decent a, a.decent {
126
+ color: #808080;
127
+ }
128
+
129
+ a.small {
130
+ font-size: 10px;
131
+ font-weight: normal !important;
132
+ }
133
+
134
+ a.small:hover {
135
+ text-decoration: underline;
136
+ }
137
+
138
+ #flashMessages {
139
+ width: 80%;
140
+ padding: 0px;
141
+ display: table;
142
+ color: #ffffff;
143
+ }
144
+ #flashMessages div {
145
+ padding: 7px;
146
+ margin-top: 7px;
147
+ margin-bottom: 10px;
148
+ }
149
+ #flashMessages div.notice {
150
+ border: 2px solid #008000;
151
+ background-color: #00a000;
152
+ }
153
+ #flashMessages div.warning {
154
+ border: 2px solid #eebb22;
155
+ background-color: #ffcc33;
156
+ }
157
+ #flashMessages div.error {
158
+ border: 2px solid #bb0000;
159
+ background-color: #cc0000;
160
+ }
161
+
162
+ .fieldWithErrors {
163
+ display: inline;
164
+ }
165
+ .fieldWithErrors > label {
166
+ }
167
+ .fieldWithErrors > input, .fieldWithErrors > textarea, .fieldWithErrors > select {
168
+ padding: 2px;
169
+ background-color: #ffe0e0;
170
+ display: inline;
171
+ }
172
+
173
+ #errorExplanation {
174
+ width: 80%;
175
+ border: 2px solid #cc0000;
176
+ padding: 7px;
177
+ padding-bottom: 12px;
178
+ margin-bottom: 20px;
179
+ background-color: #f0f0f0;
180
+ }
181
+ #errorExplanation h2 {
182
+ text-align: left;
183
+ font-weight: bold;
184
+ padding: 5px 5px 5px 7px;
185
+ font-size: 110%;
186
+ margin: -7px;
187
+ background-color: #cc0000;
188
+ color: #ffffff;
189
+ }
190
+ #errorExplanation p {
191
+ color: #333333;
192
+ margin-bottom: 0;
193
+ }
194
+
195
+ #errorExplanation ul {
196
+ margin-left: 15px;
197
+ padding-left: 0px;
198
+ }
199
+
200
+ #errorExplanation ul li {
201
+ font-size: 12px;
202
+ list-style: square;
203
+ }
@@ -0,0 +1,117 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+ setup do
5
+ @<%= file_name %> = <%= plural_name %>(:one)
6
+ <%- if has_belongsto? -%>
7
+ @<%= belongsto.file_name %> = <%= belongsto.plural_name %>(:one)
8
+
9
+ @<%= belongsto.file_name %>.save!
10
+
11
+ @<%= file_name %>.<%= belongsto.file_name %>_id = @<%= belongsto.file_name %>.id
12
+
13
+ <%- end -%>
14
+ @<%= file_name %>.save!
15
+ end
16
+
17
+ <% unless options[:singleton] -%>
18
+ test "should get index" do
19
+ <%- if has_belongsto? -%>
20
+ get :index, :<%= belongsto.file_name %>_id => @<%= belongsto.file_name %>.to_param
21
+ <%- else -%>
22
+ get :index
23
+ <%- end -%>
24
+
25
+ assert_response :success
26
+ assert_not_nil assigns(:<%= table_name %>)
27
+ end
28
+
29
+ <%- end -%>
30
+ test "should get new" do
31
+ <%- if has_belongsto? -%>
32
+ get :new, :<%= belongsto.file_name %>_id => @<%= belongsto.file_name %>.to_param
33
+ <%- else -%>
34
+ get :new
35
+ <%- end -%>
36
+
37
+ assert_response :success
38
+ end
39
+
40
+ test "should create <%= file_name %>" do
41
+ assert_difference('<%= class_name %>.count') do
42
+ <%- if has_belongsto? -%>
43
+ data = { :<%= belongsto.file_name %>_id => @<%= belongsto.file_name %>.to_param }
44
+ <%- else -%>
45
+ data = {}
46
+ <%- end -%>
47
+ <%- if has_searchbar? -%>
48
+ data[:<%= searchbar %>] = "Some <%= searchbar %>"
49
+ <%- end -%>
50
+
51
+ <%- if has_belongsto? -%>
52
+ post :create, :<%= belongsto.file_name %>_id => @<%= belongsto.file_name %>.to_param, :<%= file_name %> => data
53
+ <%- else -%>
54
+ post :create, :<%= file_name %> => data
55
+ <%- end -%>
56
+ end
57
+
58
+ <%- if has_belongsto? -%>
59
+ assert_redirected_to <%= path_of_with_belongsto_if_any(:method => :show, :value1 => "assigns(:#{file_name})", :value2 => "assigns(:#{belongsto.file_name})") %>
60
+ <%- else -%>
61
+ assert_redirected_to <%= path_of_with_belongsto_if_any(:method => :show, :value1 => "assigns(:#{file_name})") %>
62
+ <%- end -%>
63
+ end
64
+
65
+ test "should show <%= file_name %>" do
66
+ <%- if has_belongsto? -%>
67
+ get :show, :id => @<%= file_name %>.to_param, :<%= belongsto.file_name %>_id => @<%= belongsto.file_name %>.to_param
68
+ <%- else -%>
69
+ get :show, :id => @<%= file_name %>.to_param
70
+ <%- end -%>
71
+
72
+ assert_response :success
73
+ end
74
+
75
+ test "should get edit" do
76
+ <%- if has_belongsto? -%>
77
+ get :edit, :id => @<%= file_name %>.to_param, :<%= belongsto.file_name %>_id => @<%= belongsto.file_name %>.to_param
78
+ <%- else -%>
79
+ get :edit, :id => @<%= file_name %>.to_param
80
+ <%- end -%>
81
+
82
+ assert_response :success
83
+ end
84
+
85
+ test "should update <%= file_name %>" do
86
+ <%- if has_belongsto? -%>
87
+ put :update, :id => @<%= file_name %>.to_param, :<%= file_name %> => { :<%= belongsto.file_name %>_id => @<%= belongsto.file_name %>.to_param },
88
+ :<%= belongsto.file_name %>_id => @<%= belongsto.file_name %>.to_param
89
+ <%- else -%>
90
+ put :update, :id => @<%= file_name %>.to_param, :<%= file_name %> => { }
91
+ <%- end -%>
92
+
93
+ <%- if has_belongsto? -%>
94
+ assert_redirected_to <%= path_of_with_belongsto_if_any(:method => :show, :value1 => "assigns(:#{file_name})", :value2 => "assigns(:#{belongsto.file_name})") %>
95
+ <%- else -%>
96
+ assert_redirected_to <%= path_of_with_belongsto_if_any(:method => :show, :value1 => "assigns(:#{file_name})") %>
97
+ <%- end -%>
98
+ end
99
+
100
+ test "should destroy <%= file_name %>" do
101
+ destroyed = @<%= file_name %>
102
+
103
+ assert_difference('<%= class_name %>.count', -1) do
104
+ <%- if has_belongsto? -%>
105
+ delete :destroy, :id => @<%= file_name %>.to_param, :<%= belongsto.file_name %>_id => @<%= belongsto.file_name %>.to_param
106
+ <%- else -%>
107
+ delete :destroy, :id => @<%= file_name %>.to_param
108
+ <%- end -%>
109
+ end
110
+
111
+ <%- if has_belongsto? -%>
112
+ assert_redirected_to <%= path_of_with_belongsto_if_any(:value1 => "assigns(:#{file_name})", :value2 => "assigns(:#{belongsto.file_name})") %><%= has_searchbar? ? ' + "?q=#{destroyed.' + searchbar + '.first}"' : '' %>
113
+ <%- else -%>
114
+ assert_redirected_to <%= path_of_with_belongsto_if_any %><%= has_searchbar? ? ' + "?q=#{destroyed.' + searchbar + '.first}"' : '' %>
115
+ <%- end -%>
116
+ end
117
+ end
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Localized Rails scaffolding with style...
2
+
3
+ require File.join(File.dirname(__FILE__), 'localized_scaffold.rb')
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Localized Rails scaffolding with style...
@@ -0,0 +1,39 @@
1
+ namespace :localized_scaffold do
2
+ desc 'Downloads all available locales from git://github.com/svenfuchs/rails-i18n.git to "lib/locale".'
3
+ task :download_locales => [:environment] do
4
+ `rm -rf /tmp/rails-i18n`
5
+
6
+ puts 'Downloading locale files...'
7
+
8
+ `git clone git://github.com/svenfuchs/rails-i18n.git /tmp/rails-i18n 2> /dev/null`
9
+
10
+ if $? != 0
11
+ $stderr.puts '!!Missing git or network access to git://github.com/svenfuchs/rails-i18n.git'
12
+ else
13
+ `mkdir -p config/locales`
14
+ `cp -r /tmp/rails-i18n/rails/locale/* config/locales`
15
+
16
+ `rm -rf /tmp/rails-i18n`
17
+ end
18
+
19
+ puts 'Done'
20
+ end
21
+
22
+ desc 'Adds i18n config to Rails::Initializer section of environment.rb.'
23
+ task :configure => [:environment] do
24
+ patch = <<EOF
25
+ config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')]
26
+ config.i18n.default_locale = :en
27
+ EOF
28
+ path = File.expand_path(File.join(RAILS_ROOT, 'config', 'application.rb'))
29
+ content = File.read(path)
30
+
31
+ if content.match(/^\s+config.i18n.load_path/)
32
+ puts 'Configuration seems already done. Please check manually!'
33
+ else
34
+ content.gsub!(/(Application < Rails::Application.*)$/) { |match| "#{match}\n#{patch}" }
35
+
36
+ File.open(path, 'wb') { |file| file.write(content) }
37
+ end
38
+ end
39
+ end