flexi_generators 0.1.0 → 0.2.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 (192) hide show
  1. data/README.textile +83 -70
  2. data/Rakefile +0 -22
  3. data/VERSION +1 -1
  4. data/flexi_generators.gemspec +75 -136
  5. data/init.rb +0 -1
  6. data/lib/flexi_generators.rb +2 -4
  7. data/lib/generators/flexi_auth/USAGE +5 -0
  8. data/lib/generators/flexi_auth/flexi_auth_generator.rb +117 -0
  9. data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/authentication.rb +2 -9
  10. data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/authlogic_session.rb +0 -0
  11. data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/fixtures.yml +0 -0
  12. data/lib/generators/flexi_auth/templates/migration.rb +16 -0
  13. data/lib/generators/flexi_auth/templates/sessions_controller.rb +25 -0
  14. data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/sessions_helper.rb +0 -0
  15. data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/tests/testunit/sessions_controller.rb +1 -17
  16. data/lib/generators/flexi_auth/templates/tests/testunit/user.rb +4 -0
  17. data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/tests/testunit/users_controller.rb +1 -1
  18. data/lib/generators/flexi_auth/templates/user.rb +3 -0
  19. data/lib/generators/flexi_auth/templates/users_controller.rb +42 -0
  20. data/{generators/flexi_authentication → lib/generators/flexi_auth}/templates/users_helper.rb +0 -0
  21. data/lib/generators/flexi_auth/templates/views/erb/_error_messages.html.erb +11 -0
  22. data/lib/generators/flexi_auth/templates/views/erb/edit.html.erb +24 -0
  23. data/lib/generators/flexi_auth/templates/views/erb/index.html.erb +27 -0
  24. data/lib/generators/flexi_auth/templates/views/erb/login.html.erb +22 -0
  25. data/lib/generators/flexi_auth/templates/views/erb/new.html.erb +24 -0
  26. data/lib/generators/flexi_auth/templates/views/erb/show.html.erb +16 -0
  27. data/lib/generators/flexi_prepare/USAGE +6 -0
  28. data/lib/generators/flexi_prepare/flexi_prepare_generator.rb +56 -0
  29. data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/add.png +0 -0
  30. data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/admin_home_controller.rb +0 -0
  31. data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/admin_home_index.html.erb +1 -1
  32. data/lib/generators/flexi_prepare/templates/application.css +278 -0
  33. data/lib/generators/flexi_prepare/templates/application.html.erb +57 -0
  34. data/lib/generators/flexi_prepare/templates/application_helper.rb +42 -0
  35. data/lib/generators/flexi_prepare/templates/back.png +0 -0
  36. data/lib/generators/flexi_prepare/templates/bg.png +0 -0
  37. data/lib/generators/flexi_prepare/templates/bg2.png +0 -0
  38. data/lib/generators/flexi_prepare/templates/boxheader.gif +0 -0
  39. data/lib/generators/flexi_prepare/templates/btn-bg-hover.png +0 -0
  40. data/lib/generators/flexi_prepare/templates/btn-bg.png +0 -0
  41. data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/custom_field_error.rb +1 -1
  42. data/lib/generators/flexi_prepare/templates/delete.png +0 -0
  43. data/lib/generators/flexi_prepare/templates/edit.png +0 -0
  44. data/lib/generators/flexi_prepare/templates/inflector_portuguese.rb +59 -0
  45. data/lib/generators/flexi_prepare/templates/login.css +142 -0
  46. data/lib/generators/flexi_prepare/templates/login.html.erb +26 -0
  47. data/lib/generators/flexi_prepare/templates/logo.png +0 -0
  48. data/lib/generators/flexi_prepare/templates/menu.png +0 -0
  49. data/lib/generators/flexi_prepare/templates/messages/Thumbs.db +0 -0
  50. data/lib/generators/flexi_prepare/templates/messages/error.png +0 -0
  51. data/lib/generators/flexi_prepare/templates/messages/info.png +0 -0
  52. data/lib/generators/flexi_prepare/templates/messages/success.png +0 -0
  53. data/lib/generators/flexi_prepare/templates/messages/tip.png +0 -0
  54. data/lib/generators/flexi_prepare/templates/messages/warning.png +0 -0
  55. data/lib/generators/flexi_prepare/templates/pt-BR.yml +204 -0
  56. data/lib/generators/flexi_prepare/templates/show.png +0 -0
  57. data/{generators/flexi_layout/templates/stylesheet_site.css → lib/generators/flexi_prepare/templates/site.css} +32 -23
  58. data/lib/generators/flexi_prepare/templates/site.html.erb +20 -0
  59. data/{generators/flexi_layout/templates/home_controller.rb → lib/generators/flexi_prepare/templates/site_controller.rb} +1 -1
  60. data/lib/generators/flexi_prepare/templates/site_helper.rb +2 -0
  61. data/lib/generators/flexi_prepare/templates/site_index.html.erb +27 -0
  62. data/{generators/flexi_layout → lib/generators/flexi_prepare}/templates/users.png +0 -0
  63. data/lib/generators/flexi_scaffold/USAGE +8 -0
  64. data/lib/generators/flexi_scaffold/flexi_scaffold_generator.rb +98 -0
  65. data/lib/generators/flexi_scaffold/templates/controller.rb +42 -0
  66. data/{generators → lib/generators}/flexi_scaffold/templates/fixtures.yml +3 -3
  67. data/{generators → lib/generators}/flexi_scaffold/templates/helper.rb +1 -1
  68. data/{generators → lib/generators}/flexi_scaffold/templates/migration.rb +3 -5
  69. data/lib/generators/flexi_scaffold/templates/model.rb +3 -0
  70. data/lib/generators/flexi_scaffold/templates/tests/controller.rb +50 -0
  71. data/lib/generators/flexi_scaffold/templates/tests/helper.rb +4 -0
  72. data/{test/flexi_generators_test.rb → lib/generators/flexi_scaffold/templates/tests/model.rb} +2 -2
  73. data/lib/generators/flexi_scaffold/templates/views/erb/_error_messages.html.erb +11 -0
  74. data/lib/generators/flexi_scaffold/templates/views/erb/_form.html.erb +13 -0
  75. data/lib/generators/flexi_scaffold/templates/views/erb/edit.html.erb +3 -0
  76. data/lib/generators/flexi_scaffold/templates/views/erb/index.html.erb +29 -0
  77. data/lib/generators/flexi_scaffold/templates/views/erb/new.html.erb +3 -0
  78. data/lib/generators/flexi_scaffold/templates/views/erb/show.html.erb +15 -0
  79. data/template.rb +6 -0
  80. metadata +79 -137
  81. data/flexi_template.rb +0 -28
  82. data/generators/flexi_authentication/USAGE +0 -50
  83. data/generators/flexi_authentication/flexi_authentication_generator.rb +0 -127
  84. data/generators/flexi_authentication/lib/insert_commands.rb +0 -74
  85. data/generators/flexi_authentication/templates/admin_users_controller.rb +0 -60
  86. data/generators/flexi_authentication/templates/migration.rb +0 -30
  87. data/generators/flexi_authentication/templates/sessions_controller.rb +0 -52
  88. data/generators/flexi_authentication/templates/tests/rspec/sessions_controller.rb +0 -39
  89. data/generators/flexi_authentication/templates/tests/rspec/user.rb +0 -83
  90. data/generators/flexi_authentication/templates/tests/rspec/users_controller.rb +0 -26
  91. data/generators/flexi_authentication/templates/tests/shoulda/sessions_controller.rb +0 -40
  92. data/generators/flexi_authentication/templates/tests/shoulda/user.rb +0 -85
  93. data/generators/flexi_authentication/templates/tests/shoulda/users_controller.rb +0 -27
  94. data/generators/flexi_authentication/templates/tests/testunit/user.rb +0 -88
  95. data/generators/flexi_authentication/templates/user.rb +0 -43
  96. data/generators/flexi_authentication/templates/views/erb/admin_user_edit.html.erb +0 -23
  97. data/generators/flexi_authentication/templates/views/erb/admin_user_index.html.erb +0 -33
  98. data/generators/flexi_authentication/templates/views/erb/admin_user_new.html.erb +0 -23
  99. data/generators/flexi_authentication/templates/views/erb/login.html.erb +0 -38
  100. data/generators/flexi_layout/USAGE +0 -18
  101. data/generators/flexi_layout/flexi_layout_generator.rb +0 -51
  102. data/generators/flexi_layout/lib/insert_commands.rb +0 -28
  103. data/generators/flexi_layout/templates/bg.png +0 -0
  104. data/generators/flexi_layout/templates/helper.rb +0 -19
  105. data/generators/flexi_layout/templates/home_helper.rb +0 -2
  106. data/generators/flexi_layout/templates/home_index.html.erb +0 -17
  107. data/generators/flexi_layout/templates/inflector_portuguese.rb +0 -62
  108. data/generators/flexi_layout/templates/layout.html.erb +0 -47
  109. data/generators/flexi_layout/templates/layout_login.html.erb +0 -27
  110. data/generators/flexi_layout/templates/layout_site.html.erb +0 -22
  111. data/generators/flexi_layout/templates/logo.png +0 -0
  112. data/generators/flexi_layout/templates/pt-BR.yml +0 -143
  113. data/generators/flexi_layout/templates/stylesheet.css +0 -132
  114. data/generators/flexi_layout/templates/stylesheet_login.css +0 -73
  115. data/generators/flexi_resource_scaffold/USAGE +0 -29
  116. data/generators/flexi_resource_scaffold/flexi_resource_scaffold_generator.rb +0 -179
  117. data/generators/flexi_resource_scaffold/templates/controller.rb +0 -29
  118. data/generators/flexi_resource_scaffold/templates/fixtures.yml +0 -10
  119. data/generators/flexi_resource_scaffold/templates/functional_test.rb +0 -57
  120. data/generators/flexi_resource_scaffold/templates/helper.rb +0 -2
  121. data/generators/flexi_resource_scaffold/templates/migration.rb +0 -15
  122. data/generators/flexi_resource_scaffold/templates/model.rb +0 -2
  123. data/generators/flexi_resource_scaffold/templates/old_migration.rb +0 -13
  124. data/generators/flexi_resource_scaffold/templates/rspec/functional_spec.rb +0 -255
  125. data/generators/flexi_resource_scaffold/templates/rspec/helper_spec.rb +0 -11
  126. data/generators/flexi_resource_scaffold/templates/rspec/routing_spec.rb +0 -61
  127. data/generators/flexi_resource_scaffold/templates/rspec/unit_spec.rb +0 -11
  128. data/generators/flexi_resource_scaffold/templates/rspec/views/edit_spec.rb +0 -28
  129. data/generators/flexi_resource_scaffold/templates/rspec/views/index_spec.rb +0 -26
  130. data/generators/flexi_resource_scaffold/templates/rspec/views/new_spec.rb +0 -30
  131. data/generators/flexi_resource_scaffold/templates/rspec/views/show_spec.rb +0 -25
  132. data/generators/flexi_resource_scaffold/templates/shoulda_functional_test.rb +0 -19
  133. data/generators/flexi_resource_scaffold/templates/unit_test.rb +0 -7
  134. data/generators/flexi_resource_scaffold/templates/view__form.erb +0 -6
  135. data/generators/flexi_resource_scaffold/templates/view__form.haml +0 -5
  136. data/generators/flexi_resource_scaffold/templates/view_edit.erb +0 -8
  137. data/generators/flexi_resource_scaffold/templates/view_edit.haml +0 -11
  138. data/generators/flexi_resource_scaffold/templates/view_index.erb +0 -27
  139. data/generators/flexi_resource_scaffold/templates/view_index.haml +0 -19
  140. data/generators/flexi_resource_scaffold/templates/view_new.erb +0 -9
  141. data/generators/flexi_resource_scaffold/templates/view_new.haml +0 -9
  142. data/generators/flexi_resource_scaffold/templates/view_show.erb +0 -10
  143. data/generators/flexi_resource_scaffold/templates/view_show.haml +0 -9
  144. data/generators/flexi_scaffold/USAGE +0 -51
  145. data/generators/flexi_scaffold/flexi_scaffold_generator.rb +0 -232
  146. data/generators/flexi_scaffold/templates/actions/create.rb +0 -9
  147. data/generators/flexi_scaffold/templates/actions/destroy.rb +0 -6
  148. data/generators/flexi_scaffold/templates/actions/edit.rb +0 -3
  149. data/generators/flexi_scaffold/templates/actions/index.rb +0 -4
  150. data/generators/flexi_scaffold/templates/actions/new.rb +0 -3
  151. data/generators/flexi_scaffold/templates/actions/show.rb +0 -3
  152. data/generators/flexi_scaffold/templates/actions/update.rb +0 -9
  153. data/generators/flexi_scaffold/templates/controller.rb +0 -5
  154. data/generators/flexi_scaffold/templates/model.rb +0 -3
  155. data/generators/flexi_scaffold/templates/tests/rspec/actions/create.rb +0 -11
  156. data/generators/flexi_scaffold/templates/tests/rspec/actions/destroy.rb +0 -6
  157. data/generators/flexi_scaffold/templates/tests/rspec/actions/edit.rb +0 -4
  158. data/generators/flexi_scaffold/templates/tests/rspec/actions/index.rb +0 -4
  159. data/generators/flexi_scaffold/templates/tests/rspec/actions/new.rb +0 -4
  160. data/generators/flexi_scaffold/templates/tests/rspec/actions/show.rb +0 -4
  161. data/generators/flexi_scaffold/templates/tests/rspec/actions/update.rb +0 -11
  162. data/generators/flexi_scaffold/templates/tests/rspec/controller.rb +0 -8
  163. data/generators/flexi_scaffold/templates/tests/rspec/model.rb +0 -7
  164. data/generators/flexi_scaffold/templates/tests/shoulda/actions/create.rb +0 -13
  165. data/generators/flexi_scaffold/templates/tests/shoulda/actions/destroy.rb +0 -8
  166. data/generators/flexi_scaffold/templates/tests/shoulda/actions/edit.rb +0 -6
  167. data/generators/flexi_scaffold/templates/tests/shoulda/actions/index.rb +0 -6
  168. data/generators/flexi_scaffold/templates/tests/shoulda/actions/new.rb +0 -6
  169. data/generators/flexi_scaffold/templates/tests/shoulda/actions/show.rb +0 -6
  170. data/generators/flexi_scaffold/templates/tests/shoulda/actions/update.rb +0 -13
  171. data/generators/flexi_scaffold/templates/tests/shoulda/controller.rb +0 -5
  172. data/generators/flexi_scaffold/templates/tests/shoulda/model.rb +0 -7
  173. data/generators/flexi_scaffold/templates/tests/testunit/actions/create.rb +0 -11
  174. data/generators/flexi_scaffold/templates/tests/testunit/actions/destroy.rb +0 -6
  175. data/generators/flexi_scaffold/templates/tests/testunit/actions/edit.rb +0 -4
  176. data/generators/flexi_scaffold/templates/tests/testunit/actions/index.rb +0 -4
  177. data/generators/flexi_scaffold/templates/tests/testunit/actions/new.rb +0 -4
  178. data/generators/flexi_scaffold/templates/tests/testunit/actions/show.rb +0 -4
  179. data/generators/flexi_scaffold/templates/tests/testunit/actions/update.rb +0 -11
  180. data/generators/flexi_scaffold/templates/tests/testunit/controller.rb +0 -5
  181. data/generators/flexi_scaffold/templates/tests/testunit/model.rb +0 -7
  182. data/generators/flexi_scaffold/templates/views/erb/_form.html.erb +0 -6
  183. data/generators/flexi_scaffold/templates/views/erb/edit.html.erb +0 -8
  184. data/generators/flexi_scaffold/templates/views/erb/index.html.erb +0 -41
  185. data/generators/flexi_scaffold/templates/views/erb/new.html.erb +0 -10
  186. data/generators/flexi_scaffold/templates/views/erb/show.html.erb +0 -19
  187. data/generators/flexi_scaffold/templates/views/haml/_form.html.haml +0 -10
  188. data/generators/flexi_scaffold/templates/views/haml/edit.html.haml +0 -14
  189. data/generators/flexi_scaffold/templates/views/haml/index.html.haml +0 -25
  190. data/generators/flexi_scaffold/templates/views/haml/new.html.haml +0 -7
  191. data/generators/flexi_scaffold/templates/views/haml/show.html.haml +0 -20
  192. data/test/test_helper.rb +0 -3
@@ -1,50 +0,0 @@
1
- Description:
2
- Generates a user model, users controller, and sessions controller. The
3
- users controller handles the registration and the sessions controller
4
- handles authentication. This is similar to restful_authentication, but
5
- simpler.
6
-
7
- IMPORTANT: This generator uses the "title" helper method which is generated
8
- by the flexi_layout generator. You may want to run that generator first.
9
-
10
- Usage:
11
- If you do not pass any arguments, the model name will default to "user", and
12
- the authentication controller will default to "session". You can override
13
- each of these respectively by passing one or two arguments. Either name can
14
- be CamelCased or under_scored.
15
-
16
- Make sure to setup the authlogic gem if you are using that option.
17
-
18
- config.gem "authlogic"
19
-
20
- Examples:
21
- script/generate flexi_authentication
22
-
23
- Creates user model, users_controller, and sessions_controller.
24
-
25
- script/generate flexi_authentication account
26
-
27
- Creates account model, accounts_controller, and sessions_controller.
28
-
29
- script/generate flexi_authentication Account UserSession
30
-
31
- Creates account model, accounts_controller, and user_sessions_controller.
32
-
33
- Methods:
34
- There are several methods generated which you can use in your application.
35
- Here's a common example of what you might add to your layout.
36
-
37
- <% if logged_in? %>
38
- Welcome <%= current_user.username %>! Not you?
39
- <%= link_to "Log out", logout_path %>
40
- <% else %>
41
- <%= link_to "Sign up", signup_path %> or
42
- <%= link_to "log in", login_path %>.
43
- <% end %>
44
-
45
- You can also restrict unregistered users from accessing a controller using
46
- a before filter. For example.
47
-
48
- before_filter :login_required, :except => [:index, :show]
49
-
50
- See the generated file lib/authentication.rb for details.
@@ -1,127 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
- class FlexiAuthenticationGenerator < Rails::Generator::Base
3
- attr_accessor :user_name, :session_name
4
-
5
- def initialize(runtime_args, runtime_options = {})
6
- super
7
-
8
- #@user_name = @args[0] || 'user'
9
- @user_name = 'user'
10
- @session_name = @args[1] || (options[:authlogic] ? @user_name + '_session' : 'session')
11
- end
12
-
13
- def manifest
14
- record do |m|
15
- m.directory "app/models"
16
- m.directory "app/controllers"
17
- m.directory "app/controllers/admin"
18
- m.directory "app/helpers"
19
- m.directory "app/views"
20
- m.directory "app/views/admin"
21
- m.directory "lib"
22
- m.directory "app/views/admin/#{user_plural_name}"
23
- m.template "user.rb", "app/models/#{user_singular_name}.rb"
24
- m.template "authlogic_session.rb", "app/models/#{user_singular_name}_session.rb" if options[:authlogic]
25
- m.template "users_helper.rb", "app/helpers/#{user_plural_name}_helper.rb"
26
- #admin_user
27
- m.template "admin_users_controller.rb", "app/controllers/admin/#{user_plural_name}_controller.rb"
28
- m.template "views/erb/admin_user_index.html.erb", "app/views/admin/#{user_plural_name}/index.html.erb"
29
- m.template "views/erb/admin_user_new.html.erb", "app/views/admin/#{user_plural_name}/new.html.erb"
30
- m.template "views/erb/admin_user_edit.html.erb", "app/views/admin/#{user_plural_name}/edit.html.erb"
31
-
32
- m.directory "app/views/#{session_plural_name}"
33
- m.template "sessions_controller.rb", "app/controllers/#{session_plural_name}_controller.rb"
34
- m.template "sessions_helper.rb", "app/helpers/#{session_plural_name}_helper.rb"
35
- m.template "views/erb/login.html.erb", "app/views/#{session_plural_name}/new.html.erb"
36
-
37
- m.template "authentication.rb", "lib/authentication.rb"
38
- m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{user_plural_name}"
39
-
40
- m.route_resources session_plural_name
41
- m.route_name :login, 'login', :controller => session_plural_name, :action => 'new'
42
- m.route_name :logout, 'logout', :controller => session_plural_name, :action => 'destroy'
43
-
44
- m.insert_into "app/controllers/#{application_controller_name}.rb", 'include Authentication'
45
- m.insert_into "app/controllers/#{application_controller_name}.rb", 'before_filter :login_required'
46
-
47
- if test_framework == :rspec
48
- m.directory "spec"
49
- m.directory "spec/fixtures"
50
- m.directory "spec/controllers"
51
- m.directory "spec/models"
52
- m.template "fixtures.yml", "spec/fixtures/#{user_plural_name}.yml"
53
- m.template "tests/rspec/user.rb", "spec/models/#{user_singular_name}_spec.rb"
54
- m.template "tests/rspec/users_controller.rb", "spec/controllers/#{user_plural_name}_controller_spec.rb"
55
- m.template "tests/rspec/sessions_controller.rb", "spec/controllers/#{session_plural_name}_controller_spec.rb"
56
- else
57
- m.directory "test"
58
- m.directory "test/fixtures"
59
- m.directory "test/functional"
60
- m.directory "test/unit"
61
- m.template "fixtures.yml", "test/fixtures/#{user_plural_name}.yml"
62
- m.template "tests/#{test_framework}/user.rb", "test/unit/#{user_singular_name}_test.rb"
63
- m.template "tests/#{test_framework}/users_controller.rb", "test/functional/#{user_plural_name}_controller_test.rb"
64
- m.template "tests/#{test_framework}/sessions_controller.rb", "test/functional/#{session_plural_name}_controller_test.rb"
65
- end
66
- end
67
- end
68
-
69
- def user_singular_name
70
- user_name.underscore
71
- end
72
-
73
- def user_plural_name
74
- user_singular_name.pluralize
75
- end
76
-
77
- def user_class_name
78
- user_name.camelize
79
- end
80
-
81
- def user_plural_class_name
82
- user_plural_name.camelize
83
- end
84
-
85
- def session_singular_name
86
- session_name.underscore
87
- end
88
-
89
- def session_plural_name
90
- session_singular_name.pluralize
91
- end
92
-
93
- def session_class_name
94
- session_name.camelize
95
- end
96
-
97
- def session_plural_class_name
98
- session_plural_name.camelize
99
- end
100
-
101
- def application_controller_name
102
- Rails.version >= '2.3.0' ? 'application_controller' : 'application'
103
- end
104
-
105
- protected
106
-
107
- def test_framework
108
- options[:test_framework] ||= File.exist?(destination_path("spec")) ? :rspec : :testunit
109
- end
110
-
111
- def add_options!(opt)
112
- opt.separator ''
113
- opt.separator 'Options:'
114
- opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
115
- opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
116
- opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
117
- #opt.on("--authlogic", "Use Authlogic for authentication.") { |v| options[:authlogic] = true }
118
- end
119
-
120
- def banner
121
- <<-EOS
122
- Creates user model and controllers to handle registration and authentication.
123
-
124
- USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
125
- EOS
126
- end
127
- end
@@ -1,74 +0,0 @@
1
- Rails::Generator::Commands::Create.class_eval do
2
- def route_resource(*resources)
3
- resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
4
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
5
-
6
- logger.route "map.resource #{resource_list}"
7
- unless options[:pretend]
8
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
9
- "#{match}\n map.resource #{resource_list}\n"
10
- end
11
- end
12
- end
13
-
14
- def route_name(name, path, route_options = {})
15
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
16
-
17
- logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
18
- unless options[:pretend]
19
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
20
- "#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
21
- end
22
- end
23
- end
24
-
25
- def insert_into(file, line)
26
- logger.insert "#{line} into #{file}"
27
- unless options[:pretend]
28
- gsub_file file, /^(class|module) .+$/ do |match|
29
- "#{match}\n #{line}"
30
- end
31
- end
32
- end
33
- end
34
-
35
- Rails::Generator::Commands::Destroy.class_eval do
36
- def route_resource(*resources)
37
- resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
38
- look_for = "\n map.resource #{resource_list}\n"
39
- logger.route "map.resource #{resource_list}"
40
- unless options[:pretend]
41
- gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
42
- end
43
- end
44
-
45
- def route_name(name, path, route_options = {})
46
- look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
47
- logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
48
- unless options[:pretend]
49
- gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
50
- end
51
- end
52
-
53
- def insert_into(file, line)
54
- logger.remove "#{line} from #{file}"
55
- unless options[:pretend]
56
- gsub_file file, "\n #{line}", ''
57
- end
58
- end
59
- end
60
-
61
- Rails::Generator::Commands::List.class_eval do
62
- def route_resource(*resources)
63
- resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
64
- logger.route "map.resource #{resource_list}"
65
- end
66
-
67
- def route_name(name, path, options = {})
68
- logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
69
- end
70
-
71
- def insert_into(file, line)
72
- logger.insert "#{line} into #{file}"
73
- end
74
- end
@@ -1,60 +0,0 @@
1
- class Admin::UsersController < ApplicationController
2
- current_tab :users
3
-
4
- def index
5
- @users = User.paginate :page => params[:page], :per_page => 15
6
-
7
- respond_to do |format|
8
- format.html
9
- end
10
- end
11
-
12
- def new
13
- @user = User.new
14
-
15
- respond_to do |format|
16
- format.html
17
- end
18
- end
19
-
20
- def edit
21
- @user = User.find(params[:id])
22
- end
23
-
24
- def create
25
- @user = User.new(params[:user])
26
-
27
- respond_to do |format|
28
- if @user.save
29
- #session[:user_id] = @user.id
30
- flash[:notice] = "Usuário adicionado com sucesso!"
31
- format.html { redirect_to(admin_users_url) }
32
- else
33
- format.html { render :action => "new" }
34
- end
35
- end
36
- end
37
-
38
- def update
39
- @user = User.find(params[:id])
40
-
41
- respond_to do |format|
42
- if @user.update_attributes(params[:user])
43
- flash[:notice] = 'Usuário foi alterado com sucesso!'
44
- format.html { redirect_to(admin_users_url) }
45
- else
46
- format.html { render :action => "edit" }
47
- end
48
- end
49
- end
50
-
51
- def destroy
52
- @user = User.find(params[:id])
53
- @user.destroy
54
-
55
- respond_to do |format|
56
- format.html { redirect_to(login_url) }
57
- end
58
- end
59
-
60
- end
@@ -1,30 +0,0 @@
1
- class Create<%= user_plural_class_name %> < ActiveRecord::Migration
2
- def self.up
3
- create_table :<%= user_plural_name %> do |t|
4
- t.string :username
5
- t.string :email
6
- <%- if options[:authlogic] -%>
7
- t.string :persistence_token
8
- t.string :crypted_password
9
- <%- else -%>
10
- t.string :password_hash
11
- <%- end -%>
12
- t.string :password_salt
13
- t.timestamps
14
- end
15
-
16
- <%- if options[:authlogic] -%>
17
- # ...
18
- <%- else -%>
19
- execute "INSERT INTO <%= user_plural_name %> (username,email,password_hash,password_salt) VALUES ('admin','admin@admin.com','3dad6da7754a5de4c3d46fc3901adf1a1ae9ce18','4207a4c0006e0b01da91693066d91a5e34fa7fb9')"
20
- puts ""
21
- puts "Username: admin"
22
- puts "Password: admin123"
23
- puts ""
24
- <%- end -%>
25
- end
26
-
27
- def self.down
28
- drop_table :<%= user_plural_name %>
29
- end
30
- end
@@ -1,52 +0,0 @@
1
- class <%= session_plural_class_name %>Controller < ApplicationController
2
- <%- if options[:authlogic] -%>
3
- skip_before_filter :login_required
4
-
5
- layout 'login'
6
-
7
- def new
8
- @<%= session_singular_name %> = <%= session_class_name %>.new
9
- end
10
-
11
- def create
12
- @<%= session_singular_name %> = <%= session_class_name %>.new(params[:<%= session_singular_name %>])
13
- if @<%= session_singular_name %>.save
14
- flash[:notice] = "Bem-vindo!"
15
- redirect_to_target_or_default(root_url)
16
- else
17
- flash.now[:error] = "Usuário/E-mail ou senha inválidos."
18
- render :action => 'new'
19
- end
20
- end
21
-
22
- def destroy
23
- @<%= session_singular_name %> = <%= session_class_name %>.find
24
- @<%= session_singular_name %>.destroy
25
- redirect_to root_url
26
- end
27
- <%- else -%>
28
- skip_before_filter :login_required
29
-
30
- layout 'login'
31
-
32
- def new
33
- end
34
-
35
- def create
36
- <%= user_singular_name %> = <%= user_class_name %>.authenticate(params[:login], params[:password])
37
- if <%= user_singular_name %>
38
- session[:<%= user_singular_name %>_id] = <%= user_singular_name %>.id
39
- flash[:notice] = "Bem-vindo!"
40
- redirect_to admin_home_url
41
- else
42
- flash.now[:error] = "Usuário/E-mail ou senha inválidos."
43
- render :action => 'new'
44
- end
45
- end
46
-
47
- def destroy
48
- session[:<%= user_singular_name %>_id] = nil
49
- redirect_to root_url
50
- end
51
- <%- end -%>
52
- end
@@ -1,39 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe <%= session_plural_class_name %>Controller do
4
- fixtures :all
5
- integrate_views
6
-
7
- it "new action should render new template" do
8
- get :new
9
- response.should render_template(:new)
10
- end
11
-
12
- <%- if options[:authlogic] -%>
13
- it "create action should render new template when authentication is invalid" do
14
- post :create, :<%= session_singular_name %> => { :username => "foo", :password => "badpassword" }
15
- response.should render_template(:new)
16
- <%= session_class_name %>.find.should be_nil
17
- end
18
-
19
- it "create action should redirect when authentication is valid" do
20
- post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
21
- response.should redirect_to(root_url)
22
- <%= session_class_name %>.find.<%= user_singular_name %>.should == <%= user_plural_name %>(:foo)
23
- end
24
- <%- else -%>
25
- it "create action should render new template when authentication is invalid" do
26
- <%= user_class_name %>.stubs(:authenticate).returns(nil)
27
- post :create
28
- response.should render_template(:new)
29
- session['<%= user_singular_name %>_id'].should be_nil
30
- end
31
-
32
- it "create action should redirect when authentication is valid" do
33
- <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
34
- post :create
35
- response.should redirect_to(root_url)
36
- session['<%= user_singular_name %>_id'].should == <%= user_class_name %>.first.id
37
- end
38
- <%- end -%>
39
- end
@@ -1,83 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe <%= user_class_name %> do
4
- <%- unless options[:authlogic] -%>
5
- def new_<%= user_singular_name %>(attributes = {})
6
- attributes[:username] ||= 'foo'
7
- attributes[:email] ||= 'foo@example.com'
8
- attributes[:password] ||= 'abc123'
9
- attributes[:password_confirmation] ||= attributes[:password]
10
- <%= user_class_name %>.new(attributes)
11
- end
12
-
13
- before(:each) do
14
- <%= user_class_name %>.delete_all
15
- end
16
-
17
- it "should be valid" do
18
- new_<%= user_singular_name %>.should be_valid
19
- end
20
-
21
- it "should require username" do
22
- new_<%= user_singular_name %>(:username => '').should have(1).error_on(:username)
23
- end
24
-
25
- it "should require password" do
26
- new_<%= user_singular_name %>(:password => '').should have(1).error_on(:password)
27
- end
28
-
29
- it "should require well formed email" do
30
- new_<%= user_singular_name %>(:email => 'foo@bar@example.com').should have(1).error_on(:email)
31
- end
32
-
33
- it "should validate uniqueness of email" do
34
- new_<%= user_singular_name %>(:email => 'bar@example.com').save!
35
- new_<%= user_singular_name %>(:email => 'bar@example.com').should have(1).error_on(:email)
36
- end
37
-
38
- it "should validate uniqueness of username" do
39
- new_<%= user_singular_name %>(:username => 'uniquename').save!
40
- new_<%= user_singular_name %>(:username => 'uniquename').should have(1).error_on(:username)
41
- end
42
-
43
- it "should not allow odd characters in username" do
44
- new_<%= user_singular_name %>(:username => 'odd ^&(@)').should have(1).error_on(:username)
45
- end
46
-
47
- it "should validate password is longer than 3 characters" do
48
- new_<%= user_singular_name %>(:password => 'bad').should have(1).error_on(:password)
49
- end
50
-
51
- it "should require matching password confirmation" do
52
- new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').should have(1).error_on(:password)
53
- end
54
-
55
- it "should generate password hash and salt on create" do
56
- <%= user_singular_name %> = new_<%= user_singular_name %>
57
- <%= user_singular_name %>.save!
58
- <%= user_singular_name %>.password_hash.should_not be_nil
59
- <%= user_singular_name %>.password_salt.should_not be_nil
60
- end
61
-
62
- it "should authenticate by username" do
63
- <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
64
- <%= user_singular_name %>.save!
65
- <%= user_class_name %>.authenticate('foobar', 'secret').should == <%= user_singular_name %>
66
- end
67
-
68
- it "should authenticate by email" do
69
- <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
70
- <%= user_singular_name %>.save!
71
- <%= user_class_name %>.authenticate('foo@bar.com', 'secret').should == <%= user_singular_name %>
72
- end
73
-
74
- it "should not authenticate bad username" do
75
- <%= user_class_name %>.authenticate('nonexisting', 'secret').should be_nil
76
- end
77
-
78
- it "should not authenticate bad password" do
79
- new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
80
- <%= user_class_name %>.authenticate('foobar', 'badpassword').should be_nil
81
- end
82
- <%- end -%>
83
- end
@@ -1,26 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe <%= user_plural_class_name %>Controller do
4
- fixtures :all
5
- integrate_views
6
-
7
- it "new action should render new template" do
8
- get :new
9
- response.should render_template(:new)
10
- end
11
-
12
- it "create action should render new template when model is invalid" do
13
- <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
14
- post :create
15
- response.should render_template(:new)
16
- end
17
-
18
- it "create action should redirect when model is valid" do
19
- <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
20
- post :create
21
- response.should redirect_to(root_url)
22
- <%- unless options[:authlogic] -%>
23
- session['<%= user_singular_name %>_id'].should == assigns['<%= user_singular_name %>'].id
24
- <%- end -%>
25
- end
26
- end
@@ -1,40 +0,0 @@
1
- require 'test_helper'
2
-
3
- class <%= session_plural_class_name %>ControllerTest < ActionController::TestCase
4
- context "new action" do
5
- should "render new template" do
6
- get :new
7
- assert_template 'new'
8
- end
9
- end
10
-
11
- context "create action" do
12
- <%- if options[:authlogic] -%>
13
- should "render new template when authentication is invalid" do
14
- post :create, :<%= session_singular_name %> => { :username => "foo", :password => "badpassword" }
15
- assert_template 'new'
16
- assert_nil <%= session_class_name %>.find
17
- end
18
-
19
- should "redirect when authentication is valid" do
20
- post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
21
- assert_redirected_to root_url
22
- assert_equal <%= user_plural_name %>(:foo), <%= session_class_name %>.find.<%= user_singular_name %>
23
- end
24
- <%- else -%>
25
- should "render new template when authentication is invalid" do
26
- <%= user_class_name %>.stubs(:authenticate).returns(nil)
27
- post :create
28
- assert_template 'new'
29
- assert_nil session['<%= user_singular_name %>_id']
30
- end
31
-
32
- should "redirect when authentication is valid" do
33
- <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
34
- post :create
35
- assert_redirected_to root_url
36
- assert_equal <%= user_class_name %>.first.id, session['<%= user_singular_name %>_id']
37
- end
38
- <%- end -%>
39
- end
40
- end
@@ -1,85 +0,0 @@
1
- require 'test_helper'
2
-
3
- class <%= user_class_name %>Test < ActiveSupport::TestCase
4
- <%- unless options[:authlogic] -%>
5
- def new_<%= user_singular_name %>(attributes = {})
6
- attributes[:username] ||= 'foo'
7
- attributes[:email] ||= 'foo@example.com'
8
- attributes[:password] ||= 'abc123'
9
- attributes[:password_confirmation] ||= attributes[:password]
10
- <%= user_singular_name %> = <%= user_class_name %>.new(attributes)
11
- <%= user_singular_name %>.valid? # run validations
12
- <%= user_singular_name %>
13
- end
14
-
15
- def setup
16
- <%= user_class_name %>.delete_all
17
- end
18
-
19
- should "be valid" do
20
- assert new_<%= user_singular_name %>.valid?
21
- end
22
-
23
- should "require username" do
24
- assert new_<%= user_singular_name %>(:username => '').errors.on(:username)
25
- end
26
-
27
- should "require password" do
28
- assert new_<%= user_singular_name %>(:password => '').errors.on(:password)
29
- end
30
-
31
- should "require well formed email" do
32
- assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors.on(:email)
33
- end
34
-
35
- should "validate uniqueness of email" do
36
- new_<%= user_singular_name %>(:email => 'bar@example.com').save!
37
- assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors.on(:email)
38
- end
39
-
40
- should "validate uniqueness of username" do
41
- new_<%= user_singular_name %>(:username => 'uniquename').save!
42
- assert new_<%= user_singular_name %>(:username => 'uniquename').errors.on(:username)
43
- end
44
-
45
- should "not allow odd characters in username" do
46
- assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors.on(:username)
47
- end
48
-
49
- should "validate password is longer than 3 characters" do
50
- assert new_<%= user_singular_name %>(:password => 'bad').errors.on(:password)
51
- end
52
-
53
- should "require matching password confirmation" do
54
- assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors.on(:password)
55
- end
56
-
57
- should "generate password hash and salt on create" do
58
- <%= user_singular_name %> = new_<%= user_singular_name %>
59
- <%= user_singular_name %>.save!
60
- assert <%= user_singular_name %>.password_hash
61
- assert <%= user_singular_name %>.password_salt
62
- end
63
-
64
- should "authenticate by username" do
65
- <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
66
- <%= user_singular_name %>.save!
67
- assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
68
- end
69
-
70
- should "authenticate by email" do
71
- <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
72
- <%= user_singular_name %>.save!
73
- assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
74
- end
75
-
76
- should "not authenticate bad username" do
77
- assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
78
- end
79
-
80
- should "not authenticate bad password" do
81
- new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
82
- assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
83
- end
84
- <%- end -%>
85
- end