vileda-generators 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/lib/generators/vileda/layout/USAGE +25 -0
- data/lib/generators/vileda/layout/layout_generator.rb +36 -0
- data/lib/generators/vileda/layout/templates/apple-touch-icon.png +0 -0
- data/lib/generators/vileda/layout/templates/error_messages_helper.rb +23 -0
- data/lib/generators/vileda/layout/templates/favicon.ico +0 -0
- data/lib/generators/vileda/layout/templates/flash.css +52 -0
- data/lib/generators/vileda/layout/templates/forms.css +22 -0
- data/lib/generators/vileda/layout/templates/handheld.css +8 -0
- data/lib/generators/vileda/layout/templates/js/dd_belatedpng.js +13 -0
- data/lib/generators/vileda/layout/templates/js/jquery.js +154 -0
- data/lib/generators/vileda/layout/templates/js/modernizr-1.5.min.js +28 -0
- data/lib/generators/vileda/layout/templates/js/plugins.js +40 -0
- data/lib/generators/vileda/layout/templates/js/profiling/charts.swf +0 -0
- data/lib/generators/vileda/layout/templates/js/profiling/config.js +59 -0
- data/lib/generators/vileda/layout/templates/js/profiling/yahoo-profiling.css +7 -0
- data/lib/generators/vileda/layout/templates/js/profiling/yahoo-profiling.min.js +39 -0
- data/lib/generators/vileda/layout/templates/js/script.js +26 -0
- data/lib/generators/vileda/layout/templates/layout.html.erb +100 -0
- data/lib/generators/vileda/layout/templates/layout_helper.rb +22 -0
- data/lib/generators/vileda/layout/templates/style.css +279 -0
- data/lib/generators/vileda/scaffold/USAGE +51 -0
- data/lib/generators/vileda/scaffold/scaffold_generator.rb +230 -0
- data/lib/generators/vileda/scaffold/templates/actions/create.rb +9 -0
- data/lib/generators/vileda/scaffold/templates/actions/destroy.rb +6 -0
- data/lib/generators/vileda/scaffold/templates/actions/edit.rb +3 -0
- data/lib/generators/vileda/scaffold/templates/actions/index.rb +3 -0
- data/lib/generators/vileda/scaffold/templates/actions/new.rb +3 -0
- data/lib/generators/vileda/scaffold/templates/actions/show.rb +3 -0
- data/lib/generators/vileda/scaffold/templates/actions/update.rb +9 -0
- data/lib/generators/vileda/scaffold/templates/controller.rb +3 -0
- data/lib/generators/vileda/scaffold/templates/fixtures.yml +9 -0
- data/lib/generators/vileda/scaffold/templates/helper.rb +2 -0
- data/lib/generators/vileda/scaffold/templates/migration.rb +16 -0
- data/lib/generators/vileda/scaffold/templates/model.rb +3 -0
- data/lib/generators/vileda/scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/vileda/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/vileda/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/vileda/scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/vileda/scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/vileda/scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/vileda/scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/vileda/scaffold/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/vileda/scaffold/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/vileda/scaffold/templates/views/erb/_form.html.erb +11 -0
- data/lib/generators/vileda/scaffold/templates/views/erb/edit.html.erb +14 -0
- data/lib/generators/vileda/scaffold/templates/views/erb/index.html.erb +29 -0
- data/lib/generators/vileda/scaffold/templates/views/erb/new.html.erb +7 -0
- data/lib/generators/vileda/scaffold/templates/views/erb/show.html.erb +20 -0
- data/lib/generators/vileda.rb +15 -0
- metadata +115 -0
@@ -0,0 +1,279 @@
|
|
1
|
+
/*
|
2
|
+
style.css contains a reset, font normalization and some base styles.
|
3
|
+
|
4
|
+
credit is left where credit is due.
|
5
|
+
additionally, much inspiration was taken from these projects:
|
6
|
+
yui.yahooapis.com/2.8.1/build/base/base.css
|
7
|
+
camendesign.com/design/
|
8
|
+
praegnanz.de/weblog/htmlcssjs-kickstart
|
9
|
+
*/
|
10
|
+
|
11
|
+
/*
|
12
|
+
html5doctor.com Reset Stylesheet (Eric Meyer's Reset Reloaded + HTML5 baseline)
|
13
|
+
v1.4 2009-07-27 | Authors: Eric Meyer & Richard Clark
|
14
|
+
html5doctor.com/html-5-reset-stylesheet/
|
15
|
+
*/
|
16
|
+
|
17
|
+
html, body, div, span, object, iframe,
|
18
|
+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
19
|
+
abbr, address, cite, code,
|
20
|
+
del, dfn, em, img, ins, kbd, q, samp,
|
21
|
+
small, strong, sub, sup, var,
|
22
|
+
b, i,
|
23
|
+
dl, dt, dd, ol, ul, li,
|
24
|
+
fieldset, form, label, legend,
|
25
|
+
table, caption, tbody, tfoot, thead, tr, th, td,
|
26
|
+
article, aside, canvas, details, figcaption, figure,
|
27
|
+
footer, header, hgroup, menu, nav, section, summary,
|
28
|
+
time, mark, audio, video {
|
29
|
+
margin:0;
|
30
|
+
padding:0;
|
31
|
+
border:0;
|
32
|
+
outline:0;
|
33
|
+
font-size:100%;
|
34
|
+
vertical-align:baseline;
|
35
|
+
background:transparent;
|
36
|
+
}
|
37
|
+
|
38
|
+
article, aside, details, figcaption, figure,
|
39
|
+
footer, header, hgroup, menu, nav, section {
|
40
|
+
display:block;
|
41
|
+
}
|
42
|
+
|
43
|
+
nav ul { list-style:none; }
|
44
|
+
|
45
|
+
blockquote, q { quotes:none; }
|
46
|
+
|
47
|
+
blockquote:before, blockquote:after,
|
48
|
+
q:before, q:after { content:''; content:none; }
|
49
|
+
|
50
|
+
a { margin:0; padding:0; font-size:100%; vertical-align:baseline; background:transparent; }
|
51
|
+
|
52
|
+
ins { background-color:#ff9; color:#000; text-decoration:none; }
|
53
|
+
|
54
|
+
mark { background-color:#ff9; color:#000; font-style:italic; font-weight:bold; }
|
55
|
+
|
56
|
+
del { text-decoration: line-through; }
|
57
|
+
|
58
|
+
abbr[title], dfn[title] { border-bottom:1px dotted; cursor:help; }
|
59
|
+
|
60
|
+
/* tables still need cellspacing="0" in the markup */
|
61
|
+
table { border-collapse:collapse; border-spacing:0; }
|
62
|
+
|
63
|
+
hr { display:block; height:1px; border:0; border-top:1px solid #ccc; margin:1em 0; padding:0; }
|
64
|
+
|
65
|
+
input, select { vertical-align:middle; }
|
66
|
+
/* END RESET CSS */
|
67
|
+
|
68
|
+
|
69
|
+
/* fonts.css from the YUI Library: developer.yahoo.com/yui/
|
70
|
+
Please refer to developer.yahoo.com/yui/fonts/ for font sizing percentages
|
71
|
+
|
72
|
+
There are three custom edits:
|
73
|
+
* remove arial, helvetica from explicit font stack
|
74
|
+
* we normalize monospace styles ourselves
|
75
|
+
* table font-size is reset in the HTML5 reset above so there is no need to repeat
|
76
|
+
*/
|
77
|
+
body { font:13px/1.231 sans-serif; *font-size:small; } /* hack retained to preserve specificity */
|
78
|
+
|
79
|
+
select, input, textarea, button { font:99% sans-serif; }
|
80
|
+
|
81
|
+
/* normalize monospace sizing
|
82
|
+
* en.wikipedia.org/wiki/MediaWiki_talk:Common.css/Archive_11#Teletype_style_fix_for_Chrome
|
83
|
+
*/
|
84
|
+
pre, code, kbd, samp { font-family: monospace, sans-serif; }
|
85
|
+
|
86
|
+
|
87
|
+
/*
|
88
|
+
* minimal base styles
|
89
|
+
*/
|
90
|
+
|
91
|
+
|
92
|
+
body, select, input, textarea {
|
93
|
+
/* #444 looks better than black: twitter.com/H_FJ/statuses/11800719859 */
|
94
|
+
color: #444;
|
95
|
+
/* set your base font here, to apply evenly
|
96
|
+
/* font-family: Georgia, serif; */
|
97
|
+
}
|
98
|
+
|
99
|
+
/* Headers (h1,h2,etc) have no default font-size or margin,
|
100
|
+
you'll want to define those yourself. */
|
101
|
+
h1,h2,h3,h4,h5,h6 { font-weight: bold; }
|
102
|
+
|
103
|
+
/* always force a scrollbar in non-IE */
|
104
|
+
html { overflow-y: scroll; }
|
105
|
+
|
106
|
+
|
107
|
+
/* Accessible focus treatment: people.opera.com/patrickl/experiments/keyboard/test */
|
108
|
+
a:hover, a:active { outline: none; }
|
109
|
+
|
110
|
+
a, a:active, a:visited { color: #607890; }
|
111
|
+
a:hover { color: #036; }
|
112
|
+
|
113
|
+
|
114
|
+
ul, ol { margin-left: 1.8em; }
|
115
|
+
ol { list-style-type: decimal; }
|
116
|
+
|
117
|
+
small { font-size: 85%; }
|
118
|
+
strong, th { font-weight: bold; }
|
119
|
+
|
120
|
+
td, td img { vertical-align: top; }
|
121
|
+
|
122
|
+
sub { vertical-align: sub; font-size: smaller; }
|
123
|
+
sup { vertical-align: super; font-size: smaller; }
|
124
|
+
|
125
|
+
pre {
|
126
|
+
padding: 15px;
|
127
|
+
|
128
|
+
/* www.pathf.com/blogs/2008/05/formatting-quoted-code-in-blog-posts-css21-white-space-pre-wrap/ */
|
129
|
+
white-space: pre; /* CSS2 */
|
130
|
+
white-space: pre-wrap; /* CSS 2.1 */
|
131
|
+
white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */
|
132
|
+
word-wrap: break-word; /* IE */
|
133
|
+
}
|
134
|
+
|
135
|
+
textarea { overflow: auto; } /* thnx ivannikolic! www.sitepoint.com/blogs/2010/08/20/ie-remove-textarea-scrollbars/ */
|
136
|
+
|
137
|
+
.ie6 legend, .ie7 legend { margin-left: -7px; } /* thnx ivannikolic! */
|
138
|
+
|
139
|
+
/* align checkboxes, radios, text inputs with their label
|
140
|
+
by: Thierry Koblentz tjkdesign.com/ez-css/css/base.css */
|
141
|
+
input[type="radio"] { vertical-align: text-bottom; }
|
142
|
+
input[type="checkbox"] { vertical-align: bottom; }
|
143
|
+
.ie7 input[type="checkbox"] { vertical-align: baseline; }
|
144
|
+
.ie6 input { vertical-align: text-bottom; }
|
145
|
+
|
146
|
+
/* hand cursor on clickable input elements */
|
147
|
+
label, input[type=button], input[type=submit], button { cursor: pointer; }
|
148
|
+
|
149
|
+
/* webkit browsers add a 2px margin outside the chrome of form elements */
|
150
|
+
button, input, select, textarea { margin: 0; }
|
151
|
+
|
152
|
+
/* colors for form validity */
|
153
|
+
input:valid, textarea:valid { }
|
154
|
+
input:invalid, textarea:invalid {
|
155
|
+
border-radius: 1px;
|
156
|
+
-moz-box-shadow: 0px 0px 5px red;
|
157
|
+
-webkit-box-shadow: 0px 0px 5px red;
|
158
|
+
box-shadow: 0px 0px 5px red;
|
159
|
+
}
|
160
|
+
.no-boxshadow input:invalid,
|
161
|
+
.no-boxshadow textarea:invalid { background-color: #f0dddd; }
|
162
|
+
|
163
|
+
|
164
|
+
/* These selection declarations have to be separate.
|
165
|
+
No text-shadow: twitter.com/miketaylr/status/12228805301
|
166
|
+
Also: hot pink. */
|
167
|
+
::-moz-selection{ background: #FF5E99; color:#fff; text-shadow: none; }
|
168
|
+
::selection { background:#FF5E99; color:#fff; text-shadow: none; }
|
169
|
+
|
170
|
+
/* j.mp/webkit-tap-highlight-color */
|
171
|
+
a:link { -webkit-tap-highlight-color: #FF5E99; }
|
172
|
+
|
173
|
+
/* make buttons play nice in IE:
|
174
|
+
www.viget.com/inspire/styling-the-button-element-in-internet-explorer/ */
|
175
|
+
button { width: auto; overflow: visible; }
|
176
|
+
|
177
|
+
/* bicubic resizing for non-native sized IMG:
|
178
|
+
code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/ */
|
179
|
+
.ie7 img { -ms-interpolation-mode: bicubic; }
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
/*
|
184
|
+
* Non-semantic helper classes
|
185
|
+
*/
|
186
|
+
|
187
|
+
/* for image replacement */
|
188
|
+
.ir { display: block; text-indent: -999em; overflow: hidden; background-repeat: no-repeat; text-align: left; direction: ltr; }
|
189
|
+
|
190
|
+
/* Hide for both screenreaders and browsers
|
191
|
+
css-discuss.incutio.com/wiki/Screenreader_Visibility */
|
192
|
+
.hidden { display: none; visibility: hidden; }
|
193
|
+
|
194
|
+
/* Hide only visually, but have it available for screenreaders
|
195
|
+
www.webaim.org/techniques/css/invisiblecontent/
|
196
|
+
Solution from: j.mp/visuallyhidden - Thanks Jonathan Neal! */
|
197
|
+
.visuallyhidden { position: absolute !important;
|
198
|
+
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
|
199
|
+
clip: rect(1px, 1px, 1px, 1px); }
|
200
|
+
|
201
|
+
/* Hide visually and from screenreaders, but maintain layout */
|
202
|
+
.invisible { visibility: hidden; }
|
203
|
+
|
204
|
+
/* >> The Magnificent CLEARFIX << j.mp/phayesclearfix */
|
205
|
+
.clearfix:after { content: "\0020"; display: block; height: 0; clear: both; visibility: hidden; }
|
206
|
+
/* Fix clearfix: blueprintcss.lighthouseapp.com/projects/15318/tickets/5-extra-margin-padding-bottom-of-page */
|
207
|
+
.clearfix { zoom: 1; }
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
/* Primary Styles
|
215
|
+
Author:
|
216
|
+
*/
|
217
|
+
|
218
|
+
#container {
|
219
|
+
margin: 0 auto;
|
220
|
+
width: 960px;
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
/*
|
227
|
+
* print styles
|
228
|
+
* inlined to avoid required HTTP connection www.phpied.com/delay-loading-your-print-css/
|
229
|
+
*/
|
230
|
+
@media print {
|
231
|
+
* { background: transparent !important; color: #444 !important; text-shadow: none !important; }
|
232
|
+
|
233
|
+
a, a:visited { color: #444 !important; text-decoration: underline; }
|
234
|
+
|
235
|
+
a:after { content: " (" attr(href) ")"; }
|
236
|
+
|
237
|
+
abbr:after { content: " (" attr(title) ")"; }
|
238
|
+
|
239
|
+
.ir a:after { content: ""; } /* Don't show links for images */
|
240
|
+
|
241
|
+
pre, blockquote { border: 1px solid #999; page-break-inside: avoid; }
|
242
|
+
|
243
|
+
thead { display: table-header-group; } /* css-discuss.incutio.com/wiki/Printing_Tables */
|
244
|
+
|
245
|
+
tr, img { page-break-inside: avoid; }
|
246
|
+
|
247
|
+
@page { margin: 0.5cm; }
|
248
|
+
|
249
|
+
p, h2, h3 { orphans: 3; widows: 3; }
|
250
|
+
|
251
|
+
h2, h3{ page-break-after: avoid; }
|
252
|
+
}
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
/*
|
257
|
+
* Media queries for responsive design
|
258
|
+
*/
|
259
|
+
|
260
|
+
@media all and (orientation:portrait) {
|
261
|
+
/* Style adjustments for portrait mode goes here */
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
@media all and (orientation:landscape) {
|
266
|
+
/* Style adjustments for landscape mode goes here */
|
267
|
+
|
268
|
+
}
|
269
|
+
|
270
|
+
/* Grade-A Mobile Browsers (Opera Mobile, iPhone Safari, Android Chrome)
|
271
|
+
Consider this: www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/ */
|
272
|
+
@media screen and (max-device-width: 480px) {
|
273
|
+
|
274
|
+
|
275
|
+
/* Uncomment if you don't want iOS and WinMobile to mobile-optimize the text for you
|
276
|
+
j.mp/textsizeadjust
|
277
|
+
html { -webkit-text-size-adjust:none; -ms-text-size-adjust:none; } */
|
278
|
+
}
|
279
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
Description:
|
2
|
+
Scaffolds an entire resource, from model and migration to controller and
|
3
|
+
views. The resource is ready to use as a starting point for your restful,
|
4
|
+
resource-oriented application. Tests or specs are also generated depending
|
5
|
+
on if you have a "spec" directory or not.
|
6
|
+
|
7
|
+
IMPORTANT: This generator uses the "title" helper method which is generated
|
8
|
+
by the vileda_layout generator. You may want to run that generator first.
|
9
|
+
|
10
|
+
Usage:
|
11
|
+
Pass the name of the model, either CamelCased or under_scored, as the first
|
12
|
+
argument along with an optional list of attribute pairs and controller actions.
|
13
|
+
|
14
|
+
If no controller actions are specified, they will default to index, show,
|
15
|
+
new, create, edit, update, and destroy.
|
16
|
+
|
17
|
+
IMPORTANT: If no attribute pairs are specified, no model will be generated.
|
18
|
+
It will try to determine the attributes from an existing model.
|
19
|
+
|
20
|
+
Attribute pairs are column_name:sql_type arguments specifying the
|
21
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
22
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
23
|
+
|
24
|
+
For example, `vileda_scaffold post name:string content:text hidden:boolean`
|
25
|
+
gives you a model with those three attributes, a controller that handles
|
26
|
+
the create/show/update/destroy, forms to create and edit your posts, and
|
27
|
+
an index that lists them all, as well as a map.resources :posts
|
28
|
+
declaration in config/routes.rb.
|
29
|
+
|
30
|
+
Adding an "!" in the mix of arguments will invert the passed controller
|
31
|
+
actions. This will include all 7 controller actitons except the ones
|
32
|
+
mentioned. This option doesn't affect model attributes.
|
33
|
+
|
34
|
+
Examples:
|
35
|
+
rails generate vileda:scaffold post
|
36
|
+
|
37
|
+
Will create a controller called "posts" it will contain all seven
|
38
|
+
CRUD actions along with the views. A model will NOT be created,
|
39
|
+
instead it will look for an existing model and use those attributes.
|
40
|
+
|
41
|
+
rails generate vileda:scaffold post name:string content:text index new edit
|
42
|
+
|
43
|
+
Will create a Post model and migration file with the name and content
|
44
|
+
attributes. It will also create a controller with index, new, create,
|
45
|
+
edit, and update actions. Notice the create and update actions are
|
46
|
+
added automatically with new and edit.
|
47
|
+
|
48
|
+
rails generate vileda:scaffold post ! show new
|
49
|
+
|
50
|
+
Creates a posts controller (no model) with index, edit, update, and
|
51
|
+
destroy actions.
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'generators/vileda'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/generated_attribute'
|
4
|
+
|
5
|
+
module Vileda
|
6
|
+
module Generators
|
7
|
+
class ScaffoldGenerator < Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
no_tasks { attr_accessor :model_name, :model_attributes, :controller_actions }
|
10
|
+
|
11
|
+
argument :model_name, :type => :string, :required => true, :banner => 'ModelName'
|
12
|
+
argument :args_for_c_m, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
|
13
|
+
|
14
|
+
class_option :skip_model, :desc => 'Don\'t generate a model or migration file.', :type => :boolean
|
15
|
+
class_option :skip_migration, :desc => 'Dont generate migration file for model.', :type => :boolean
|
16
|
+
class_option :skip_timestamps, :desc => 'Don\'t add timestamps to migration file.', :type => :boolean
|
17
|
+
class_option :skip_controller, :desc => 'Don\'t generate controller, helper, or views.', :type => :boolean
|
18
|
+
class_option :invert, :desc => 'Generate all controller actions except these mentioned.', :type => :boolean
|
19
|
+
|
20
|
+
class_option :testunit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
|
21
|
+
|
22
|
+
def initialize(*args, &block)
|
23
|
+
super
|
24
|
+
|
25
|
+
@controller_actions = []
|
26
|
+
@model_attributes = []
|
27
|
+
|
28
|
+
args_for_c_m.each do |arg|
|
29
|
+
if arg == '!'
|
30
|
+
options[:invert] = true
|
31
|
+
elsif arg.include?(':')
|
32
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
33
|
+
else
|
34
|
+
@controller_actions << arg
|
35
|
+
@controller_actions << 'create' if arg == 'new'
|
36
|
+
@controller_actions << 'update' if arg == 'edit'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@controller_actions.uniq!
|
41
|
+
@model_attributes.uniq!
|
42
|
+
|
43
|
+
if options.invert? || @controller_actions.empty?
|
44
|
+
@controller_actions = all_actions - @controller_actions
|
45
|
+
end
|
46
|
+
|
47
|
+
if @model_attributes.empty?
|
48
|
+
options[:skip_model] = true # default to skipping model if no attributes passed
|
49
|
+
if model_exists?
|
50
|
+
model_columns_for_attributes.each do |column|
|
51
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_model
|
60
|
+
unless options.skip_model?
|
61
|
+
template 'model.rb', "app/models/#{singular_name}.rb"
|
62
|
+
if options.rspec?
|
63
|
+
template "tests/rspec/model.rb", "spec/models/#{singular_name}_spec.rb"
|
64
|
+
template 'fixtures.yml', "spec/fixtures/#{plural_name}.yml"
|
65
|
+
else
|
66
|
+
template "tests/#{test_framework}/model.rb", "test/unit/#{singular_name}_test.rb"
|
67
|
+
template 'fixtures.yml', "test/fixtures/#{plural_name}.yml"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_migration
|
73
|
+
unless options.skip_model? || options.skip_migration?
|
74
|
+
migration_template 'migration.rb', "db/migrate/create_#{plural_name}.rb"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_controller
|
79
|
+
unless options.skip_controller?
|
80
|
+
template 'controller.rb', "app/controllers/#{plural_name}_controller.rb"
|
81
|
+
|
82
|
+
template 'helper.rb', "app/helpers/#{plural_name}_helper.rb"
|
83
|
+
|
84
|
+
controller_actions.each do |action|
|
85
|
+
if %w[index show new edit].include?(action) # Actions with templates
|
86
|
+
template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if form_partial?
|
91
|
+
template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
|
92
|
+
end
|
93
|
+
|
94
|
+
route "resources #{plural_name.to_sym.inspect}"
|
95
|
+
|
96
|
+
template "tests/#{test_framework}/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def form_partial?
|
103
|
+
actions? :new, :edit
|
104
|
+
end
|
105
|
+
|
106
|
+
def all_actions
|
107
|
+
%w[index show new create edit update destroy]
|
108
|
+
end
|
109
|
+
|
110
|
+
def action?(name)
|
111
|
+
controller_actions.include? name.to_s
|
112
|
+
end
|
113
|
+
|
114
|
+
def actions?(*names)
|
115
|
+
names.all? { |name| action? name }
|
116
|
+
end
|
117
|
+
|
118
|
+
def singular_name
|
119
|
+
model_name.underscore
|
120
|
+
end
|
121
|
+
|
122
|
+
def plural_name
|
123
|
+
model_name.underscore.pluralize
|
124
|
+
end
|
125
|
+
|
126
|
+
def class_name
|
127
|
+
model_name.camelize
|
128
|
+
end
|
129
|
+
|
130
|
+
def plural_class_name
|
131
|
+
plural_name.camelize
|
132
|
+
end
|
133
|
+
|
134
|
+
def controller_methods(dir_name)
|
135
|
+
controller_actions.map do |action|
|
136
|
+
read_template("#{dir_name}/#{action}.rb")
|
137
|
+
end.join(" \n").strip
|
138
|
+
end
|
139
|
+
|
140
|
+
def render_form
|
141
|
+
if form_partial?
|
142
|
+
if options.haml?
|
143
|
+
"= render 'form'"
|
144
|
+
else
|
145
|
+
"<%= render 'form' %>"
|
146
|
+
end
|
147
|
+
else
|
148
|
+
read_template("views/#{view_language}/_form.html.#{view_language}")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def items_path(suffix = 'path')
|
153
|
+
if action? :index
|
154
|
+
"#{plural_name}_#{suffix}"
|
155
|
+
else
|
156
|
+
"root_#{suffix}"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def item_path(suffix = 'path')
|
161
|
+
if action? :show
|
162
|
+
"@#{singular_name}"
|
163
|
+
else
|
164
|
+
items_path(suffix)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def item_path_for_spec(suffix = 'path')
|
169
|
+
if action? :show
|
170
|
+
"#{singular_name}_#{suffix}(assigns[:#{singular_name}])"
|
171
|
+
else
|
172
|
+
items_path(suffix)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def item_path_for_test(suffix = 'path')
|
177
|
+
if action? :show
|
178
|
+
"#{singular_name}_#{suffix}(assigns(:#{singular_name}))"
|
179
|
+
else
|
180
|
+
items_path(suffix)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def model_columns_for_attributes
|
185
|
+
class_name.constantize.columns.reject do |column|
|
186
|
+
column.name.to_s =~ /^(id|created_at|updated_at)$/
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def view_language
|
191
|
+
options.haml? ? 'haml' : 'erb'
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_framework
|
195
|
+
return @test_framework if defined?(@test_framework)
|
196
|
+
if options.testunit?
|
197
|
+
return @test_framework = :testunit
|
198
|
+
else
|
199
|
+
return @test_framework = default_test_framework
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def default_test_framework
|
204
|
+
:testunit
|
205
|
+
end
|
206
|
+
|
207
|
+
def model_exists?
|
208
|
+
File.exist? destination_path("app/models/#{singular_name}.rb")
|
209
|
+
end
|
210
|
+
|
211
|
+
def read_template(relative_path)
|
212
|
+
ERB.new(File.read(find_in_source_paths(relative_path)), nil, '-').result(binding)
|
213
|
+
end
|
214
|
+
|
215
|
+
def destination_path(path)
|
216
|
+
File.join(destination_root, path)
|
217
|
+
end
|
218
|
+
|
219
|
+
# FIXME: Should be proxied to ActiveRecord::Generators::Base
|
220
|
+
# Implement the required interface for Rails::Generators::Migration.
|
221
|
+
def self.next_migration_number(dirname) #:nodoc:
|
222
|
+
if ActiveRecord::Base.timestamped_migrations
|
223
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
224
|
+
else
|
225
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
def create
|
2
|
+
@<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
|
3
|
+
if @<%= singular_name %>.save
|
4
|
+
flash[:notice] = "Successfully created <%= model_name.underscore.humanize.downcase %>."
|
5
|
+
redirect_to <%= item_path('url') %>
|
6
|
+
else
|
7
|
+
render :action => 'new'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
def update
|
2
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
3
|
+
if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
|
4
|
+
flash[:notice] = "Successfully updated <%= model_name.underscore.humanize.downcase %>."
|
5
|
+
redirect_to <%= item_path('url') %>
|
6
|
+
else
|
7
|
+
render :action => 'edit'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Create<%= plural_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= plural_name %> do |t|
|
4
|
+
<%- for attribute in model_attributes -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<%- end -%>
|
7
|
+
<%- unless options[:skip_timestamps] -%>
|
8
|
+
t.timestamps
|
9
|
+
<%- end -%>
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :<%= plural_name %>
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
def test_create_invalid
|
2
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
+
post :create
|
4
|
+
assert_template 'new'
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_create_valid
|
8
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
+
post :create
|
10
|
+
assert_redirected_to <%= item_path_for_test('url') %>
|
11
|
+
end
|