splendeo-generators 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/CHANGELOG +119 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +98 -0
  4. data/Rakefile +12 -0
  5. data/lib/nifty_generators.rb +3 -0
  6. data/rails_generators/splendeo_authentication/USAGE +50 -0
  7. data/rails_generators/splendeo_authentication/lib/insert_commands.rb +74 -0
  8. data/rails_generators/splendeo_authentication/splendeo_authentication_generator.rb +128 -0
  9. data/rails_generators/splendeo_authentication/templates/authentication.rb +61 -0
  10. data/rails_generators/splendeo_authentication/templates/authlogic_session.rb +2 -0
  11. data/rails_generators/splendeo_authentication/templates/fixtures.yml +24 -0
  12. data/rails_generators/splendeo_authentication/templates/migration.rb +20 -0
  13. data/rails_generators/splendeo_authentication/templates/sessions_controller.rb +45 -0
  14. data/rails_generators/splendeo_authentication/templates/sessions_helper.rb +2 -0
  15. data/rails_generators/splendeo_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  16. data/rails_generators/splendeo_authentication/templates/tests/rspec/user.rb +83 -0
  17. data/rails_generators/splendeo_authentication/templates/tests/rspec/users_controller.rb +26 -0
  18. data/rails_generators/splendeo_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  19. data/rails_generators/splendeo_authentication/templates/tests/shoulda/user.rb +85 -0
  20. data/rails_generators/splendeo_authentication/templates/tests/shoulda/users_controller.rb +27 -0
  21. data/rails_generators/splendeo_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  22. data/rails_generators/splendeo_authentication/templates/tests/testunit/user.rb +88 -0
  23. data/rails_generators/splendeo_authentication/templates/tests/testunit/users_controller.rb +23 -0
  24. data/rails_generators/splendeo_authentication/templates/user.rb +42 -0
  25. data/rails_generators/splendeo_authentication/templates/users_controller.rb +18 -0
  26. data/rails_generators/splendeo_authentication/templates/users_helper.rb +2 -0
  27. data/rails_generators/splendeo_authentication/templates/views/erb/login.html.erb +30 -0
  28. data/rails_generators/splendeo_authentication/templates/views/erb/signup.html.erb +24 -0
  29. data/rails_generators/splendeo_authentication/templates/views/haml/login.html.haml +30 -0
  30. data/rails_generators/splendeo_authentication/templates/views/haml/signup.html.haml +24 -0
  31. data/rails_generators/splendeo_config/USAGE +23 -0
  32. data/rails_generators/splendeo_config/splendeo_config_generator.rb +32 -0
  33. data/rails_generators/splendeo_config/templates/config.yml +8 -0
  34. data/rails_generators/splendeo_config/templates/load_config.rb +2 -0
  35. data/rails_generators/splendeo_layout/USAGE +25 -0
  36. data/rails_generators/splendeo_layout/splendeo_layout_generator.rb +76 -0
  37. data/rails_generators/splendeo_layout/templates/blueprint-sass/ie.sass +103 -0
  38. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/icons/cross.png +0 -0
  39. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/icons/key.png +0 -0
  40. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/icons/tick.png +0 -0
  41. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/readme.txt +32 -0
  42. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/buttons/screen.sass +104 -0
  43. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/fancy-type/readme.txt +14 -0
  44. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/fancy-type/screen.sass +34 -0
  45. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/doc.png +0 -0
  46. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/email.png +0 -0
  47. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/external.png +0 -0
  48. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/feed.png +0 -0
  49. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/im.png +0 -0
  50. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/pdf.png +0 -0
  51. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/visited.png +0 -0
  52. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/icons/xls.png +0 -0
  53. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/readme.txt +18 -0
  54. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/link-icons/screen.sass +50 -0
  55. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/rtl/readme.txt +10 -0
  56. data/rails_generators/splendeo_layout/templates/blueprint-sass/plugins/rtl/screen.sass +272 -0
  57. data/rails_generators/splendeo_layout/templates/blueprint-sass/print.sass +75 -0
  58. data/rails_generators/splendeo_layout/templates/blueprint-sass/screen.sass +1062 -0
  59. data/rails_generators/splendeo_layout/templates/blueprint/ie.css +35 -0
  60. data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/icons/cross.png +0 -0
  61. data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/icons/key.png +0 -0
  62. data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/icons/tick.png +0 -0
  63. data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/readme.txt +32 -0
  64. data/rails_generators/splendeo_layout/templates/blueprint/plugins/buttons/screen.css +97 -0
  65. data/rails_generators/splendeo_layout/templates/blueprint/plugins/fancy-type/readme.txt +14 -0
  66. data/rails_generators/splendeo_layout/templates/blueprint/plugins/fancy-type/screen.css +71 -0
  67. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/doc.png +0 -0
  68. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/email.png +0 -0
  69. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/external.png +0 -0
  70. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/feed.png +0 -0
  71. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/im.png +0 -0
  72. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  73. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/visited.png +0 -0
  74. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/icons/xls.png +0 -0
  75. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/readme.txt +18 -0
  76. data/rails_generators/splendeo_layout/templates/blueprint/plugins/link-icons/screen.css +40 -0
  77. data/rails_generators/splendeo_layout/templates/blueprint/plugins/rtl/readme.txt +10 -0
  78. data/rails_generators/splendeo_layout/templates/blueprint/plugins/rtl/screen.css +110 -0
  79. data/rails_generators/splendeo_layout/templates/blueprint/print.css +29 -0
  80. data/rails_generators/splendeo_layout/templates/blueprint/screen.css +258 -0
  81. data/rails_generators/splendeo_layout/templates/haml/init.rb +16 -0
  82. data/rails_generators/splendeo_layout/templates/helper.rb +22 -0
  83. data/rails_generators/splendeo_layout/templates/layout.html.erb +34 -0
  84. data/rails_generators/splendeo_layout/templates/layout.html.haml +31 -0
  85. data/rails_generators/splendeo_layout/templates/stylesheet.css +77 -0
  86. data/rails_generators/splendeo_layout/templates/stylesheet.sass +63 -0
  87. data/rails_generators/splendeo_scaffold/USAGE +51 -0
  88. data/rails_generators/splendeo_scaffold/splendeo_scaffold_generator.rb +232 -0
  89. data/rails_generators/splendeo_scaffold/templates/actions/create.rb +9 -0
  90. data/rails_generators/splendeo_scaffold/templates/actions/destroy.rb +6 -0
  91. data/rails_generators/splendeo_scaffold/templates/actions/edit.rb +3 -0
  92. data/rails_generators/splendeo_scaffold/templates/actions/index.rb +3 -0
  93. data/rails_generators/splendeo_scaffold/templates/actions/new.rb +3 -0
  94. data/rails_generators/splendeo_scaffold/templates/actions/show.rb +3 -0
  95. data/rails_generators/splendeo_scaffold/templates/actions/update.rb +9 -0
  96. data/rails_generators/splendeo_scaffold/templates/controller.rb +3 -0
  97. data/rails_generators/splendeo_scaffold/templates/fixtures.yml +9 -0
  98. data/rails_generators/splendeo_scaffold/templates/helper.rb +2 -0
  99. data/rails_generators/splendeo_scaffold/templates/migration.rb +16 -0
  100. data/rails_generators/splendeo_scaffold/templates/model.rb +3 -0
  101. data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  102. data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  103. data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  104. data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  105. data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  106. data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  107. data/rails_generators/splendeo_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  108. data/rails_generators/splendeo_scaffold/templates/tests/rspec/controller.rb +8 -0
  109. data/rails_generators/splendeo_scaffold/templates/tests/rspec/model.rb +7 -0
  110. data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  111. data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  112. data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  113. data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  114. data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  115. data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  116. data/rails_generators/splendeo_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  117. data/rails_generators/splendeo_scaffold/templates/tests/shoulda/controller.rb +5 -0
  118. data/rails_generators/splendeo_scaffold/templates/tests/shoulda/model.rb +7 -0
  119. data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  120. data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  121. data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  122. data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  123. data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  124. data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  125. data/rails_generators/splendeo_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  126. data/rails_generators/splendeo_scaffold/templates/tests/testunit/controller.rb +5 -0
  127. data/rails_generators/splendeo_scaffold/templates/tests/testunit/model.rb +7 -0
  128. data/rails_generators/splendeo_scaffold/templates/views/erb/_form.html.erb +10 -0
  129. data/rails_generators/splendeo_scaffold/templates/views/erb/edit.html.erb +14 -0
  130. data/rails_generators/splendeo_scaffold/templates/views/erb/index.html.erb +29 -0
  131. data/rails_generators/splendeo_scaffold/templates/views/erb/new.html.erb +7 -0
  132. data/rails_generators/splendeo_scaffold/templates/views/erb/show.html.erb +20 -0
  133. data/rails_generators/splendeo_scaffold/templates/views/haml/_form.html.haml +10 -0
  134. data/rails_generators/splendeo_scaffold/templates/views/haml/edit.html.haml +14 -0
  135. data/rails_generators/splendeo_scaffold/templates/views/haml/index.html.haml +25 -0
  136. data/rails_generators/splendeo_scaffold/templates/views/haml/new.html.haml +7 -0
  137. data/rails_generators/splendeo_scaffold/templates/views/haml/show.html.haml +20 -0
  138. data/test/test_helper.rb +119 -0
  139. data/test/test_splendeo_authentication_generator.rb +274 -0
  140. data/test/test_splendeo_config_generator.rb +37 -0
  141. data/test/test_splendeo_layout_generator.rb +42 -0
  142. data/test/test_splendeo_scaffold_generator.rb +534 -0
  143. metadata +212 -0
data/CHANGELOG ADDED
@@ -0,0 +1,119 @@
1
+ 0.3.2 (February 16th, 2010)
2
+
3
+ * Including all files in gem, was missing files in rails_generator directory
4
+
5
+
6
+ 0.3.1 (February 16th, 2010)
7
+
8
+ * improving documentation
9
+
10
+ * fixing name of generated session model for authlogic in nifty_authorization
11
+
12
+ * use "username" instead of "login" for authlogic haml form template in nifty_authorization
13
+
14
+
15
+ 0.3.0 (August 15th, 2009)
16
+
17
+ * adding attr_accessible to models in nifty_scaffold
18
+
19
+ * adding authlogic support with --authlogic option in nifty_authentication
20
+
21
+ * pluralize second argument for controller in nifty_authentication
22
+
23
+ * don't convert javascript/stylesheet arguments to strings in nifty_layout
24
+
25
+ * store request location and redirect to it when logging in under nifty_authentication
26
+
27
+
28
+ 0.2.4 (May 5th, 2009)
29
+
30
+ * using root_url when no index action in nifty_scaffold
31
+
32
+ * making password editable in user model in nifty_authentication
33
+
34
+ * adding filter_parameter_logging :password in nifty_authentication
35
+
36
+
37
+ 0.2.3 (February 20th, 2009)
38
+
39
+ * fixing nifty_authentication to work with Rails 2.3 application_controller.rb
40
+
41
+ * fixing password field in HAML signup page in nifty_authentication
42
+
43
+
44
+ 0.2.2 (November 11th, 2008)
45
+
46
+ * fixing sessions_path reference in nifty_authentication
47
+
48
+ * adding more validations to user model in nifty_authentication
49
+
50
+ * cleaning up nifty_layout stylesheet
51
+
52
+
53
+ 0.2.1 (November 10th, 2008)
54
+
55
+ * adding missing nifty_authentication files
56
+
57
+
58
+ 0.2.0 (November 4th, 2008)
59
+
60
+ * adding nifty_authentication
61
+
62
+
63
+ 0.1.8 (October 3rd, 2008)
64
+
65
+ * compatibility with RubyGems 1.3
66
+
67
+ * using f.error_messages instead of error_messages_for (thanks Zach Langley)
68
+
69
+
70
+ 0.1.7 (August 15th, 2008)
71
+
72
+ * fixing shoulda tests
73
+
74
+
75
+ 0.1.6 (August 7th, 2008)
76
+
77
+ * adding option to specify Shoulda as testing framework in nifty_scaffold generator
78
+
79
+ * adding options to manually specify rspec or testunit framework in nifty_scaffold generator
80
+
81
+
82
+ 0.1.5 (August 7th, 2008)
83
+
84
+ * adding option to nifty layout to generate HAML views and SASS stylesheets
85
+
86
+ * adding option to nifty scaffold to generate HAML views
87
+
88
+
89
+ 0.1.4 (July 21st, 2008)
90
+
91
+ * using same logic as model spec in model test for scaffold
92
+
93
+ * simplifying model spec generated by scaffold
94
+
95
+ * adding error_messages_for to form partial
96
+
97
+
98
+ 0.1.3 (June 20th, 2008)
99
+
100
+ * using _url in controllers instead of _path
101
+
102
+ * improving the nifty_config default example YAML file
103
+
104
+
105
+ 0.1.2 (May 16th, 2008)
106
+
107
+ * mentioning nifty_layout in nifty_scaffold generator
108
+
109
+ * adding nifty_config generator
110
+
111
+
112
+ 0.1.1 (May 9th, 2008)
113
+
114
+ * adding tests and specs to scaffold generator
115
+
116
+
117
+ 0.1.0 (May 8th, 2008)
118
+
119
+ * initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Ryan Bates
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,98 @@
1
+ = Splendeo Generators
2
+
3
+ A collection of useful Rails generator scripts for scaffolding, layout files, authentication, and more.
4
+
5
+
6
+ == Install
7
+
8
+ gem install splendeo-generators
9
+
10
+
11
+ == Usage
12
+
13
+ Once you install the gem, the generators will be available to all Rails applications on your system. If you run script/generate without any additional arguments you should see the available generators listed.
14
+
15
+ To run the generator, go to your rails project directory and call it using the script/generate or script/destroy command.
16
+
17
+ script/generate splendeo_scaffold Recipe name:string index new
18
+
19
+
20
+ == Included Generators
21
+
22
+ * splendeo_layout: generates generic layout, stylesheet, and helper files.
23
+ * splendeo_scaffold: generates a controller and optional model/migration.
24
+ * splendeo_config: generates a config YAML file and loader.
25
+ * splendeo_authentication: generates user model with sign up and log in.
26
+
27
+ To view the README for each generator, run it with the +--help+ option.
28
+
29
+ script/generate splendeo_layout --help
30
+
31
+
32
+ == Troubleshooting and FAQs
33
+
34
+ <b>What is the difference between splendeo_scaffold and built-in scaffold?</b>
35
+
36
+ One of the primary differences is that splendeo_scaffold allows you to choose which controller actions to generate.
37
+
38
+ script/generate splendeo_scaffold post name:string index new edit
39
+
40
+ There are a few changes to the generated code as well, such as no XML format by default.
41
+
42
+ It also offers support for HAML, Shoulda, and RSpec.
43
+
44
+
45
+ <b>I get "undefined method 'title'" error.</b>
46
+
47
+ Try running splendeo_layout, that will generate this helper method. Or you can just change the templates to whatever approach you prefer for setting the title.
48
+
49
+
50
+ <b>I can't set new attributes in my model.</b>
51
+
52
+ Add the attribute to the attr_accessible line in the model.
53
+
54
+
55
+ <b>I get "undefined method 'root_url'" error.</b>
56
+
57
+ Some generators default redirecting to the root_url. Set this in your routes.rb file like this (substituting your controller name).
58
+
59
+ map.root :controller => 'foo'
60
+
61
+
62
+ <b>I get a missing database error.</b>
63
+
64
+ Run <tt>rake db:migrate</tt>.
65
+
66
+
67
+ <b>I get a routing error when I try to submit a form.</b>
68
+
69
+ Try restarting your development server. Sometimes it doesn't detect the change in the routing.
70
+
71
+
72
+ <b>The tests/specs don't work.</b>
73
+
74
+ Make sure you have mocha installed and require it in your spec/test helper.
75
+
76
+ gem install mocha
77
+
78
+ # in spec_helper.rb
79
+ config.mock_with :mocha
80
+
81
+ # in test_helper.rb
82
+ require 'mocha'
83
+
84
+ Also, make sure you're using Rails 2.1 or greater.
85
+
86
+
87
+ == Found a bug?
88
+
89
+ If you are having a problem with Splendeo Generators, first look at the FAQs above. If you still cannot resolve it, please submit an issue here.
90
+
91
+ http://github.com/ryanb/splendeo-generators/issues
92
+
93
+
94
+ == Rails 3
95
+
96
+ Splendeo Generators does not yet officially work with Rails 3, but a fork is available here.
97
+
98
+ http://github.com/dvyjones/splendeo-generators
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ desc "Run tests."
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList['test/test*.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module SplendeoGenerators
2
+ # nothing to see here, the real action is under rails_generators
3
+ end
@@ -0,0 +1,50 @@
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 splendeo_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 splendeo_authentication
22
+
23
+ Creates user model, users_controller, and sessions_controller.
24
+
25
+ script/generate splendeo_authentication account
26
+
27
+ Creates account model, accounts_controller, and sessions_controller.
28
+
29
+ script/generate splendeo_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.
@@ -0,0 +1,74 @@
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
@@ -0,0 +1,128 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
+ class SplendeoAuthenticationGenerator < 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
+ @session_name = @args[1] || (options[:authlogic] ? @user_name + '_session' : 'session')
10
+ end
11
+
12
+ def manifest
13
+ record do |m|
14
+ m.directory "app/models"
15
+ m.directory "app/controllers"
16
+ m.directory "app/helpers"
17
+ m.directory "app/views"
18
+ m.directory "lib"
19
+
20
+ m.directory "app/views/#{user_plural_name}"
21
+ m.template "user.rb", "app/models/#{user_singular_name}.rb"
22
+ m.template "authlogic_session.rb", "app/models/#{session_singular_name}.rb" if options[:authlogic]
23
+ m.template "users_controller.rb", "app/controllers/#{user_plural_name}_controller.rb"
24
+ m.template "users_helper.rb", "app/helpers/#{user_plural_name}_helper.rb"
25
+ m.template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
26
+
27
+ m.directory "app/views/#{session_plural_name}"
28
+ m.template "sessions_controller.rb", "app/controllers/#{session_plural_name}_controller.rb"
29
+ m.template "sessions_helper.rb", "app/helpers/#{session_plural_name}_helper.rb"
30
+ m.template "views/#{view_language}/login.html.#{view_language}", "app/views/#{session_plural_name}/new.html.#{view_language}"
31
+
32
+ m.template "authentication.rb", "lib/authentication.rb"
33
+ m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{user_plural_name}"
34
+
35
+ m.route_resources user_plural_name
36
+ m.route_resources session_plural_name
37
+ m.route_name :login, 'login', :controller => session_plural_name, :action => 'new'
38
+ m.route_name :logout, 'logout', :controller => session_plural_name, :action => 'destroy'
39
+ m.route_name :signup, 'signup', :controller => user_plural_name, :action => 'new'
40
+
41
+ m.insert_into "app/controllers/#{application_controller_name}.rb", 'include Authentication'
42
+
43
+ if test_framework == :rspec
44
+ m.directory "spec"
45
+ m.directory "spec/fixtures"
46
+ m.directory "spec/controllers"
47
+ m.directory "spec/models"
48
+ m.template "fixtures.yml", "spec/fixtures/#{user_plural_name}.yml"
49
+ m.template "tests/rspec/user.rb", "spec/models/#{user_singular_name}_spec.rb"
50
+ m.template "tests/rspec/users_controller.rb", "spec/controllers/#{user_plural_name}_controller_spec.rb"
51
+ m.template "tests/rspec/sessions_controller.rb", "spec/controllers/#{session_plural_name}_controller_spec.rb"
52
+ else
53
+ m.directory "test"
54
+ m.directory "test/fixtures"
55
+ m.directory "test/functional"
56
+ m.directory "test/unit"
57
+ m.template "fixtures.yml", "test/fixtures/#{user_plural_name}.yml"
58
+ m.template "tests/#{test_framework}/user.rb", "test/unit/#{user_singular_name}_test.rb"
59
+ m.template "tests/#{test_framework}/users_controller.rb", "test/functional/#{user_plural_name}_controller_test.rb"
60
+ m.template "tests/#{test_framework}/sessions_controller.rb", "test/functional/#{session_plural_name}_controller_test.rb"
61
+ end
62
+ end
63
+ end
64
+
65
+ def user_singular_name
66
+ user_name.underscore
67
+ end
68
+
69
+ def user_plural_name
70
+ user_singular_name.pluralize
71
+ end
72
+
73
+ def user_class_name
74
+ user_name.camelize
75
+ end
76
+
77
+ def user_plural_class_name
78
+ user_plural_name.camelize
79
+ end
80
+
81
+ def session_singular_name
82
+ session_name.underscore
83
+ end
84
+
85
+ def session_plural_name
86
+ session_singular_name.pluralize
87
+ end
88
+
89
+ def session_class_name
90
+ session_name.camelize
91
+ end
92
+
93
+ def session_plural_class_name
94
+ session_plural_name.camelize
95
+ end
96
+
97
+ def application_controller_name
98
+ Rails.version >= '2.3.0' ? 'application_controller' : 'application'
99
+ end
100
+
101
+ protected
102
+
103
+ def view_language
104
+ options[:haml] ? 'haml' : 'erb'
105
+ end
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("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = true }
118
+ opt.on("--authlogic", "Use Authlogic for authentication.") { |v| options[:authlogic] = true }
119
+ end
120
+
121
+ def banner
122
+ <<-EOS
123
+ Creates user model and controllers to handle registration and authentication.
124
+
125
+ USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
126
+ EOS
127
+ end
128
+ end