flexi_generators 0.1.0

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.
Files changed (137) hide show
  1. data/README.textile +71 -0
  2. data/Rakefile +38 -0
  3. data/VERSION +1 -0
  4. data/flexi_generators.gemspec +176 -0
  5. data/flexi_template.rb +28 -0
  6. data/generators/flexi_authentication/USAGE +50 -0
  7. data/generators/flexi_authentication/flexi_authentication_generator.rb +127 -0
  8. data/generators/flexi_authentication/lib/insert_commands.rb +74 -0
  9. data/generators/flexi_authentication/templates/admin_users_controller.rb +60 -0
  10. data/generators/flexi_authentication/templates/authentication.rb +61 -0
  11. data/generators/flexi_authentication/templates/authlogic_session.rb +2 -0
  12. data/generators/flexi_authentication/templates/fixtures.yml +24 -0
  13. data/generators/flexi_authentication/templates/migration.rb +30 -0
  14. data/generators/flexi_authentication/templates/sessions_controller.rb +52 -0
  15. data/generators/flexi_authentication/templates/sessions_helper.rb +2 -0
  16. data/generators/flexi_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  17. data/generators/flexi_authentication/templates/tests/rspec/user.rb +83 -0
  18. data/generators/flexi_authentication/templates/tests/rspec/users_controller.rb +26 -0
  19. data/generators/flexi_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  20. data/generators/flexi_authentication/templates/tests/shoulda/user.rb +85 -0
  21. data/generators/flexi_authentication/templates/tests/shoulda/users_controller.rb +27 -0
  22. data/generators/flexi_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  23. data/generators/flexi_authentication/templates/tests/testunit/user.rb +88 -0
  24. data/generators/flexi_authentication/templates/tests/testunit/users_controller.rb +23 -0
  25. data/generators/flexi_authentication/templates/user.rb +43 -0
  26. data/generators/flexi_authentication/templates/users_helper.rb +2 -0
  27. data/generators/flexi_authentication/templates/views/erb/admin_user_edit.html.erb +23 -0
  28. data/generators/flexi_authentication/templates/views/erb/admin_user_index.html.erb +33 -0
  29. data/generators/flexi_authentication/templates/views/erb/admin_user_new.html.erb +23 -0
  30. data/generators/flexi_authentication/templates/views/erb/login.html.erb +38 -0
  31. data/generators/flexi_layout/USAGE +18 -0
  32. data/generators/flexi_layout/flexi_layout_generator.rb +51 -0
  33. data/generators/flexi_layout/lib/insert_commands.rb +28 -0
  34. data/generators/flexi_layout/templates/add.png +0 -0
  35. data/generators/flexi_layout/templates/admin_home_controller.rb +6 -0
  36. data/generators/flexi_layout/templates/admin_home_index.html.erb +16 -0
  37. data/generators/flexi_layout/templates/bg.png +0 -0
  38. data/generators/flexi_layout/templates/custom_field_error.rb +12 -0
  39. data/generators/flexi_layout/templates/helper.rb +19 -0
  40. data/generators/flexi_layout/templates/home_controller.rb +9 -0
  41. data/generators/flexi_layout/templates/home_helper.rb +2 -0
  42. data/generators/flexi_layout/templates/home_index.html.erb +17 -0
  43. data/generators/flexi_layout/templates/inflector_portuguese.rb +62 -0
  44. data/generators/flexi_layout/templates/layout.html.erb +47 -0
  45. data/generators/flexi_layout/templates/layout_login.html.erb +27 -0
  46. data/generators/flexi_layout/templates/layout_site.html.erb +22 -0
  47. data/generators/flexi_layout/templates/logo.png +0 -0
  48. data/generators/flexi_layout/templates/pt-BR.yml +143 -0
  49. data/generators/flexi_layout/templates/stylesheet.css +132 -0
  50. data/generators/flexi_layout/templates/stylesheet_login.css +73 -0
  51. data/generators/flexi_layout/templates/stylesheet_site.css +63 -0
  52. data/generators/flexi_layout/templates/users.png +0 -0
  53. data/generators/flexi_resource_scaffold/USAGE +29 -0
  54. data/generators/flexi_resource_scaffold/flexi_resource_scaffold_generator.rb +179 -0
  55. data/generators/flexi_resource_scaffold/templates/controller.rb +29 -0
  56. data/generators/flexi_resource_scaffold/templates/fixtures.yml +10 -0
  57. data/generators/flexi_resource_scaffold/templates/functional_test.rb +57 -0
  58. data/generators/flexi_resource_scaffold/templates/helper.rb +2 -0
  59. data/generators/flexi_resource_scaffold/templates/migration.rb +15 -0
  60. data/generators/flexi_resource_scaffold/templates/model.rb +2 -0
  61. data/generators/flexi_resource_scaffold/templates/old_migration.rb +13 -0
  62. data/generators/flexi_resource_scaffold/templates/rspec/functional_spec.rb +255 -0
  63. data/generators/flexi_resource_scaffold/templates/rspec/helper_spec.rb +11 -0
  64. data/generators/flexi_resource_scaffold/templates/rspec/routing_spec.rb +61 -0
  65. data/generators/flexi_resource_scaffold/templates/rspec/unit_spec.rb +11 -0
  66. data/generators/flexi_resource_scaffold/templates/rspec/views/edit_spec.rb +28 -0
  67. data/generators/flexi_resource_scaffold/templates/rspec/views/index_spec.rb +26 -0
  68. data/generators/flexi_resource_scaffold/templates/rspec/views/new_spec.rb +30 -0
  69. data/generators/flexi_resource_scaffold/templates/rspec/views/show_spec.rb +25 -0
  70. data/generators/flexi_resource_scaffold/templates/shoulda_functional_test.rb +19 -0
  71. data/generators/flexi_resource_scaffold/templates/unit_test.rb +7 -0
  72. data/generators/flexi_resource_scaffold/templates/view__form.erb +6 -0
  73. data/generators/flexi_resource_scaffold/templates/view__form.haml +5 -0
  74. data/generators/flexi_resource_scaffold/templates/view_edit.erb +8 -0
  75. data/generators/flexi_resource_scaffold/templates/view_edit.haml +11 -0
  76. data/generators/flexi_resource_scaffold/templates/view_index.erb +27 -0
  77. data/generators/flexi_resource_scaffold/templates/view_index.haml +19 -0
  78. data/generators/flexi_resource_scaffold/templates/view_new.erb +9 -0
  79. data/generators/flexi_resource_scaffold/templates/view_new.haml +9 -0
  80. data/generators/flexi_resource_scaffold/templates/view_show.erb +10 -0
  81. data/generators/flexi_resource_scaffold/templates/view_show.haml +9 -0
  82. data/generators/flexi_scaffold/USAGE +51 -0
  83. data/generators/flexi_scaffold/flexi_scaffold_generator.rb +232 -0
  84. data/generators/flexi_scaffold/templates/actions/create.rb +9 -0
  85. data/generators/flexi_scaffold/templates/actions/destroy.rb +6 -0
  86. data/generators/flexi_scaffold/templates/actions/edit.rb +3 -0
  87. data/generators/flexi_scaffold/templates/actions/index.rb +4 -0
  88. data/generators/flexi_scaffold/templates/actions/new.rb +3 -0
  89. data/generators/flexi_scaffold/templates/actions/show.rb +3 -0
  90. data/generators/flexi_scaffold/templates/actions/update.rb +9 -0
  91. data/generators/flexi_scaffold/templates/controller.rb +5 -0
  92. data/generators/flexi_scaffold/templates/fixtures.yml +9 -0
  93. data/generators/flexi_scaffold/templates/helper.rb +2 -0
  94. data/generators/flexi_scaffold/templates/migration.rb +16 -0
  95. data/generators/flexi_scaffold/templates/model.rb +3 -0
  96. data/generators/flexi_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  97. data/generators/flexi_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  98. data/generators/flexi_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  99. data/generators/flexi_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  100. data/generators/flexi_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  101. data/generators/flexi_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  102. data/generators/flexi_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  103. data/generators/flexi_scaffold/templates/tests/rspec/controller.rb +8 -0
  104. data/generators/flexi_scaffold/templates/tests/rspec/model.rb +7 -0
  105. data/generators/flexi_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  106. data/generators/flexi_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  107. data/generators/flexi_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  108. data/generators/flexi_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  109. data/generators/flexi_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  110. data/generators/flexi_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  111. data/generators/flexi_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  112. data/generators/flexi_scaffold/templates/tests/shoulda/controller.rb +5 -0
  113. data/generators/flexi_scaffold/templates/tests/shoulda/model.rb +7 -0
  114. data/generators/flexi_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  115. data/generators/flexi_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  116. data/generators/flexi_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  117. data/generators/flexi_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  118. data/generators/flexi_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  119. data/generators/flexi_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  120. data/generators/flexi_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  121. data/generators/flexi_scaffold/templates/tests/testunit/controller.rb +5 -0
  122. data/generators/flexi_scaffold/templates/tests/testunit/model.rb +7 -0
  123. data/generators/flexi_scaffold/templates/views/erb/_form.html.erb +6 -0
  124. data/generators/flexi_scaffold/templates/views/erb/edit.html.erb +8 -0
  125. data/generators/flexi_scaffold/templates/views/erb/index.html.erb +41 -0
  126. data/generators/flexi_scaffold/templates/views/erb/new.html.erb +10 -0
  127. data/generators/flexi_scaffold/templates/views/erb/show.html.erb +19 -0
  128. data/generators/flexi_scaffold/templates/views/haml/_form.html.haml +10 -0
  129. data/generators/flexi_scaffold/templates/views/haml/edit.html.haml +14 -0
  130. data/generators/flexi_scaffold/templates/views/haml/index.html.haml +25 -0
  131. data/generators/flexi_scaffold/templates/views/haml/new.html.haml +7 -0
  132. data/generators/flexi_scaffold/templates/views/haml/show.html.haml +20 -0
  133. data/init.rb +2 -0
  134. data/lib/flexi_generators.rb +4 -0
  135. data/test/flexi_generators_test.rb +8 -0
  136. data/test/test_helper.rb +3 -0
  137. metadata +203 -0
@@ -0,0 +1,132 @@
1
+ /* Basic ---------------------------------------- */
2
+ a {text-decoration: none;}
3
+ a:hover {text-decoration: underline;}
4
+ body {
5
+ background-color: #E6E6E6;
6
+ font-family: Arial,Helvetica,sans-serif;
7
+ font-size: 13px;
8
+ color: #333333;
9
+ background-image:url(../images/bg.png);
10
+ background-repeat:repeat-x;
11
+ }
12
+ input[type=text]{ border:1px solid #CCCCCC; }
13
+ input[type=password] { border:1px solid #CCCCCC; }
14
+ select{ border:1px solid #CCCCCC;}
15
+ textarea{ border:1px solid #CCCCCC; }
16
+ .logout{ color:#D30000; font-weight:bold;}
17
+ .login { font-weight:bold; }
18
+ .view{color: #55a34a;}
19
+ .back{color: #0085CF;}
20
+ .edit{color:#C5A059;}
21
+ .delete{color:#A02B2B;}
22
+ .new{
23
+ background: url(../images/add.png) no-repeat;
24
+ text-align: center;
25
+ font-size: 14px;
26
+ font-weight: bold;
27
+ padding-left: 17px;
28
+ color: #55A34A
29
+ }
30
+ .pagination{ margin-top: 15px; text-align: center; }
31
+ label { font-weight:bold;}
32
+ h1, h2 { padding:2px; margin:2px; }
33
+ a img { border: none; }
34
+ a { color: #0000FF; }
35
+ .clear { clear: both; height: 0; overflow: hidden; }
36
+ div#control_box {
37
+ background-color:#F3F3F3;
38
+ border:1px solid #E5E5E5;
39
+ padding:1px;
40
+ text-align:center;
41
+ }
42
+ div#title_box {
43
+ background-color:#F3F3F3;
44
+ border:1px solid #E5E5E5;
45
+ padding:1px;
46
+ text-align:center;
47
+ }
48
+ div#new_box { padding:15px 5px 5px 5px; }
49
+
50
+ /* Navigation ---------------------------------------- */
51
+ #sidenav {
52
+ width: 156px;
53
+ float:left;
54
+ background-color: #F3F3F3;
55
+ padding: 0px 0px 0px 0px;
56
+ font-size: 14px;
57
+ font-weight: bold;
58
+ margin: 0px 0px 0px 0px;
59
+ }
60
+ #sidenav ul {
61
+ list-style-type:none;
62
+ list-style-position:outside;
63
+ list-style-image: none;
64
+ padding:0px 0px 0px 0px;
65
+ margin:0px 0px 0px 0px;
66
+ }
67
+ #sidenav li { }
68
+ #sidenav li a {
69
+ width: 156px;
70
+ display:block;
71
+ width:93%;
72
+ height: 100%;
73
+ line-height: 25px;
74
+ border-bottom: 1px solid #DDDDDD;
75
+ padding-left: 10px;
76
+ color: #4E5660;
77
+ }
78
+ #sidenav li a:hover { background: #FFFADF; }
79
+ #sidenav li.current a {background: #DFF6FF; color: #000; }
80
+
81
+ div#top_nav{
82
+ text-align: right;
83
+ width: 920px;
84
+ margin: 0 auto;
85
+ border-bottom:1px solid #E5E5E5;
86
+ margin-bottom: 10px;
87
+ }
88
+
89
+ /* Content ---------------------------------------- */
90
+ div#header{ width: 920px; margin: 0 auto; }
91
+ #container {
92
+ width: 900px;
93
+ overflow: auto;
94
+ margin: 0 auto;
95
+ background-color: #FFF;
96
+ margin-top: 10px;
97
+ padding: 10px;
98
+ border: solid 5px #E4E2E2;
99
+ }
100
+
101
+ #main{
102
+ width: 733px;
103
+ float:right;
104
+ padding: 0 ;
105
+ margin:0;
106
+ }
107
+
108
+ #main table { width: 100%; }
109
+ #main table th { background-color: #F3F3F3 }
110
+ #main table tr td { border-bottom: 1px solid #DDDDDD; }
111
+ #main table tr:hover td { background: #FFFADF none repeat scroll 0 0; }
112
+
113
+ /* Notices ---------------------------------------- */
114
+ #flash_notice, #flash_error {
115
+ padding: 10px ;
116
+ margin: 10px 0 0 0;
117
+ font-weight: bold;
118
+ text-align: center;
119
+ }
120
+ #flash_notice {
121
+ background-color: #CFC;
122
+ border: dashed 1px #6C6;
123
+ color: #1E5F1D;
124
+ }
125
+ #flash_error {
126
+ background-color: #FCC;
127
+ border: dashed 1px #C66;
128
+ color:#9E0B0F;
129
+ }
130
+
131
+ .fieldWithErrors { display: inline; }
132
+ #errorExplanation { background-color: #FCC; border: solid 1px #C66; }
@@ -0,0 +1,73 @@
1
+ a {text-decoration: none;}
2
+ a:hover {text-decoration: underline;}
3
+
4
+ body {
5
+ background-color: #E6E6E6;
6
+ font-family: Arial,Helvetica,sans-serif;
7
+ font-size: 13px;
8
+ color: #333333;
9
+ background-image:url(../images/bg.png);
10
+ background-repeat:repeat-x;
11
+ }
12
+
13
+ input[type=text]{ border:1px solid #CCCCCC; }
14
+
15
+ input[type=password] { border:1px solid #CCCCCC; }
16
+
17
+ div#control_box {
18
+ background-color:#F3F3F3;
19
+ border:1px solid #E5E5E5;
20
+ padding:1px;
21
+ text-align:center;
22
+ }
23
+
24
+ div#title_box {
25
+ background-color:#F3F3F3;
26
+ border:1px solid #E5E5E5;
27
+ padding:1px;
28
+ text-align:center;
29
+ }
30
+
31
+ label { font-weight:bold;}
32
+
33
+ h1, h2 { padding:2px; margin:2px; }
34
+
35
+ a img { border: none; }
36
+
37
+ a { color: #0000FF; }
38
+
39
+ .clear { clear: both; height: 0; overflow: hidden; }
40
+
41
+ #main{
42
+ width: 633px;
43
+ float:right;
44
+ padding: 0 ;
45
+ margin:0;
46
+ }
47
+
48
+ #container {
49
+ width: 350px;
50
+ overflow: auto;
51
+ margin: 0 auto;
52
+ background-color: #FFF;
53
+ margin-top: 10px;
54
+ padding: 10px;
55
+ border: solid 5px #E4E2E2;
56
+ }
57
+
58
+ #flash_notice, #flash_error {
59
+ padding: 10px ;
60
+ margin: 10px 0 0 0;
61
+ font-weight: bold;
62
+ text-align: center;
63
+ }
64
+ #flash_notice {
65
+ background-color: #CFC;
66
+ border: dashed 1px #6C6;
67
+ color: #1E5F1D;
68
+ }
69
+ #flash_error {
70
+ background-color: #FCC;
71
+ border: dashed 1px #C66;
72
+ color:#9E0B0F;
73
+ }
@@ -0,0 +1,63 @@
1
+ /** { padding: 2px; margin: 2px; }*/
2
+ a {text-decoration: none;}
3
+ a:hover {text-decoration: underline;}
4
+
5
+ body {
6
+ background-color: #E6E6E6;
7
+ font-family: Arial,Helvetica,sans-serif;
8
+ font-size: 13px;
9
+ color: #333333;
10
+ background-image:url(../images/bg.png);
11
+ background-repeat:repeat-x;
12
+ }
13
+
14
+ div#header{ width: 830px; margin: 0 auto; }
15
+
16
+ div#control_box {
17
+ background-color:#F3F3F3;
18
+ border:1px solid #E5E5E5;
19
+ padding:1px;
20
+ text-align:center;
21
+ }
22
+
23
+ div#title_box {
24
+ background-color:#F3F3F3;
25
+ border:1px solid #E5E5E5;
26
+ padding:1px;
27
+ text-align:center;
28
+ }
29
+
30
+ div#new_box { padding:15px 5px 5px 5px; }
31
+
32
+ .edit{color:#C5A059;}
33
+ .delete{color:#A02B2B;}
34
+ .new{
35
+ background: url(../images/add.png) no-repeat;
36
+ text-align: center;
37
+ font-size: 14px;
38
+ font-weight: bold;
39
+ padding-left: 17px;
40
+ color: #55A34A
41
+ }
42
+
43
+ .pagination{ margin-top: 15px; text-align: center; }
44
+
45
+ label { font-weight:bold; }
46
+
47
+ h1, h2 { padding:2px; margin:2px; }
48
+
49
+ a img { border: none; }
50
+
51
+ a { color: #0000FF; }
52
+
53
+ .clear { clear: both; height: 0; overflow: hidden; }
54
+
55
+ #container {
56
+ width: 800px;
57
+ overflow: auto;
58
+ margin: 0 auto;
59
+ background-color: #FFF;
60
+ margin-top: 10px;
61
+ padding: 10px;
62
+ border: solid 5px #E4E2E2;
63
+ }
@@ -0,0 +1,29 @@
1
+ Description:
2
+ The scaffold resource generator creates a model, a controller, and a set of templates that's ready to use as the
3
+ starting point for your REST-like, resource-oriented application. This basically means that it follows a set of
4
+ conventions to exploit the full set of HTTP verbs (GET/POST/PUT/DELETE) and is prepared for multi-client access
5
+ (like one view for HTML, one for an XML API, one for ATOM, etc). Everything comes with sample unit and functional
6
+ tests as well.
7
+
8
+ The generator takes the name of the model as its first argument. This model name is then pluralized to get the
9
+ controller name. So "flexi_resource_scaffold post" will generate a Post model and a PostsController and will be intended
10
+ for URLs like /posts and /posts/45.
11
+
12
+ As additional parameters, the generator will take attribute pairs described by name and type. These attributes will
13
+ be used to prepopulate the migration to create the table for the model and to give you a set of templates for the
14
+ view. For example, "flexi_resource_scaffold post title:string created_on:date body:text published:boolean" will give
15
+ you a model with those four attributes, forms to create and edit those models from, and an index that'll list them
16
+ all.
17
+
18
+ You don't have to think up all attributes up front, but it's a good idea of adding just the baseline of what's
19
+ needed to start really working with the resource.
20
+
21
+ Once the generator has run, you'll need to add a declaration to your config/routes.rb file to hook up the rules
22
+ that'll point URLs to this new resource. If you create a resource like "flexi_scaffold post", you'll need to
23
+ add "map.resources :posts" (notice the plural form) in the routes file. Then your new resource is accessible from
24
+ /posts.
25
+
26
+ Examples:
27
+ ./script/generate flexi_resource_scaffold post # no attributes, view will be anemic
28
+ ./script/generate flexi_resource_scaffold post title:string created_on:date body:text published:boolean
29
+ ./script/generate flexi_resource_scaffold purchase order_id:integer created_at:datetime amount:decimal
@@ -0,0 +1,179 @@
1
+ class FlexiResourceScaffoldGenerator < Rails::Generator::NamedBase
2
+ attr_reader :controller_name,
3
+ :controller_class_path,
4
+ :controller_file_path,
5
+ :controller_class_nesting,
6
+ :controller_class_nesting_depth,
7
+ :controller_class_name,
8
+ :controller_singular_name,
9
+ :controller_plural_name,
10
+ :resource_edit_path,
11
+ :default_file_extension,
12
+ :generator_default_file_extension
13
+ alias_method :controller_file_name, :controller_singular_name
14
+ alias_method :controller_table_name, :controller_plural_name
15
+
16
+ def initialize(runtime_args, runtime_options = {})
17
+ super
18
+
19
+ if @rspec = has_rspec?
20
+ if ActionController::Base.respond_to?(:resource_action_separator)
21
+ @resource_edit_path = "/edit"
22
+ else
23
+ @resource_edit_path = ";edit"
24
+ end
25
+ end
26
+
27
+ @generator_default_file_extension = (defined? Haml )? "haml" : "erb"
28
+
29
+ # we want to call erb templates .rhtml or .haml if this is rails 1
30
+ if RAILS_GEM_VERSION.to_i == 1
31
+ @default_file_extension = @generator_default_file_extension == 'erb' ? 'rhtml' : @generator_default_file_extension
32
+ else
33
+ @default_file_extension = "html.#{@generator_default_file_extension}"
34
+ end
35
+
36
+ @controller_name = @name.pluralize
37
+
38
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
39
+ @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
40
+
41
+ if @controller_class_nesting.empty?
42
+ @controller_class_name = @controller_class_name_without_nesting
43
+ else
44
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
45
+ end
46
+ end
47
+
48
+ def manifest
49
+ record do |m|
50
+ # Check for class naming collisions.
51
+ m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
52
+ m.class_collisions(class_path, "#{class_name}")
53
+
54
+ # Controller, helper, views, and test directories.
55
+ m.directory(File.join('app/models', class_path))
56
+ m.directory(File.join('app/controllers', controller_class_path))
57
+ m.directory(File.join('app/helpers', controller_class_path))
58
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
59
+
60
+ if @rspec
61
+ m.directory(File.join('spec/controllers', controller_class_path))
62
+ m.directory(File.join('spec/helpers', class_path))
63
+ m.directory(File.join('spec/models', class_path))
64
+ m.directory File.join('spec/views', controller_class_path, controller_file_name)
65
+ m.directory(File.join('spec/fixtures', class_path))
66
+ else
67
+ m.directory(File.join('test/functional', controller_class_path))
68
+ m.directory(File.join('test/unit', class_path))
69
+ end
70
+
71
+ scaffold_views.each do |action|
72
+ m.template(
73
+ "view_#{action}.#{generator_default_file_extension}",
74
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.#{default_file_extension}")
75
+ )
76
+ end
77
+
78
+ m.template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
79
+ m.template('controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb"))
80
+ m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
81
+
82
+ if @rspec
83
+ m.template('rspec/functional_spec.rb', File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb"))
84
+ m.template('rspec/routing_spec.rb', File.join('spec/controllers', controller_class_path, "#{controller_file_name}_routing_spec.rb"))
85
+ m.template('rspec/helper_spec.rb', File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb"))
86
+ m.template('rspec/unit_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb"))
87
+ m.template('fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml"))
88
+
89
+ rspec_views.each do |action|
90
+ m.template(
91
+ "rspec/views/#{action}_spec.rb",
92
+ File.join('spec/views', controller_class_path, controller_file_name, "#{action}_spec.rb")
93
+ )
94
+ end
95
+
96
+ else
97
+ functional_test = (defined? ThoughtBot::Shoulda) ? "shoulda_functional_test.rb" : "functional_test.rb"
98
+
99
+ m.template("#{functional_test}", File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
100
+ m.template('unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"))
101
+ m.template('fixtures.yml', File.join('test/fixtures', "#{table_name}.yml"))
102
+ end
103
+
104
+
105
+ unless options[:skip_migration]
106
+ migration_template = RAILS_GEM_VERSION.to_i == 1 ? 'old_migration.rb' : 'migration.rb'
107
+
108
+ m.migration_template(
109
+ migration_template, 'db/migrate',
110
+ :assigns => {
111
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
112
+ :attributes => attributes
113
+ },
114
+ :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
115
+ )
116
+ end
117
+
118
+ m.route_resources controller_file_name
119
+ end
120
+ end
121
+
122
+ # Lifted from Rick Olson's restful_authentication
123
+ def has_rspec?
124
+ options[:rspec] || (File.exist?('spec') && File.directory?('spec'))
125
+ end
126
+
127
+ protected
128
+ # Override with your own usage banner.
129
+ def banner
130
+ "Usage: #{$0} scaffold_resource ModelName [field:type, field:type]"
131
+ end
132
+
133
+ def rspec_views
134
+ %w[ index show new edit ]
135
+ end
136
+
137
+ def scaffold_views
138
+ rspec_views + %w[ _form ]
139
+ end
140
+
141
+ def model_name
142
+ class_name.demodulize
143
+ end
144
+
145
+ def add_options!(opt)
146
+ opt.separator ''
147
+ opt.separator 'Options:'
148
+ opt.on("--rspec", "Force rspec mode (checks for RAILS_ROOT/spec by default)") { |v| options[:rspec] = true }
149
+ end
150
+ end
151
+
152
+ module Rails
153
+ module Generator
154
+ class GeneratedAttribute
155
+ def default_value
156
+ @default_value ||= case type
157
+ when :int, :integer then "\"1\""
158
+ when :float then "\"1.5\""
159
+ when :decimal then "\"9.99\""
160
+ when :datetime, :timestamp, :time then "Time.now"
161
+ when :date then "Date.today"
162
+ when :string then "\"MyString\""
163
+ when :text then "\"MyText\""
164
+ when :boolean then "false"
165
+ else
166
+ ""
167
+ end
168
+ end
169
+
170
+ def input_type
171
+ @input_type ||= case type
172
+ when :text then "textarea"
173
+ else
174
+ "input"
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,29 @@
1
+ class <%= controller_class_name %>Controller < ResourceController::Base
2
+ current_tab :<%= plural_name %>
3
+
4
+ private
5
+ def collection
6
+ @collection ||= end_of_association_chain.paginate :page => params[:page],
7
+ :per_page => 15
8
+ end
9
+
10
+ create do
11
+ flash "<%= singular_name.capitalize %> adicionada com sucesso!"
12
+ end
13
+
14
+ update do
15
+ flash "<%= singular_name.capitalize %> alterada com sucesso!"
16
+ end
17
+
18
+ destroy do
19
+ flash "<%= singular_name.capitalize %> excluída com sucesso!"
20
+ end
21
+
22
+ create.response do |wants|
23
+ wants.html { redirect_to(collection_url) }
24
+ end
25
+
26
+ update.response do |wants|
27
+ wants.html { redirect_to(collection_url) }
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ one:
2
+ id: 1
3
+ <% for attribute in attributes -%>
4
+ <%= attribute.name %>: <%= attribute.default %>
5
+ <% end -%>
6
+ two:
7
+ id: 2
8
+ <% for attribute in attributes -%>
9
+ <%= attribute.name %>: <%= attribute.default %>
10
+ <% end -%>
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * controller_class_nesting_depth %>/../test_helper'
2
+ require '<%= controller_file_path %>_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
6
+
7
+ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
8
+ fixtures :<%= table_name %>
9
+
10
+ def setup
11
+ @controller = <%= controller_class_name %>Controller.new
12
+ @request = ActionController::TestRequest.new
13
+ @response = ActionController::TestResponse.new
14
+ end
15
+
16
+ def test_should_get_index
17
+ get :index
18
+ assert_response :success
19
+ assert assigns(:<%= table_name %>)
20
+ end
21
+
22
+ def test_should_get_new
23
+ get :new
24
+ assert_response :success
25
+ end
26
+
27
+ def test_should_create_<%= file_name %>
28
+ old_count = <%= class_name %>.count
29
+ post :create, :<%= file_name %> => { }
30
+ assert_equal old_count+1, <%= class_name %>.count
31
+
32
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
33
+ end
34
+
35
+ def test_should_show_<%= file_name %>
36
+ get :show, :id => 1
37
+ assert_response :success
38
+ end
39
+
40
+ def test_should_get_edit
41
+ get :edit, :id => 1
42
+ assert_response :success
43
+ end
44
+
45
+ def test_should_update_<%= file_name %>
46
+ put :update, :id => 1, :<%= file_name %> => { }
47
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
48
+ end
49
+
50
+ def test_should_destroy_<%= file_name %>
51
+ old_count = <%= class_name %>.count
52
+ delete :destroy, :id => 1
53
+ assert_equal old_count-1, <%= class_name %>.count
54
+
55
+ assert_redirected_to <%= table_name %>_path
56
+ end
57
+ end
@@ -0,0 +1,2 @@
1
+ module <%= controller_class_name %>Helper
2
+ end
@@ -0,0 +1,15 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %>, :force => true do |t|
4
+ <% for attribute in attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :<%= table_name %>
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1,13 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %>, :force => true do |t|
4
+ <% for attribute in attributes -%>
5
+ t.column :<%= attribute.name %>, :<%= attribute.type %>
6
+ <% end -%>
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :<%= table_name %>
12
+ end
13
+ end