devisable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/Devisable.gemspec +117 -0
  2. data/Gemfile +13 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.rdoc +111 -0
  5. data/Rakefile +56 -0
  6. data/VERSION +1 -0
  7. data/lib/generators/devisable/USAGE +57 -0
  8. data/lib/generators/devisable/devisable_generator.rb +484 -0
  9. data/lib/generators/devisable/templates/app/controllers/registrations_controller.erb +19 -0
  10. data/lib/generators/devisable/templates/app/controllers/users_controller.erb +152 -0
  11. data/lib/generators/devisable/templates/app/controllers/welcome_controller.erb +11 -0
  12. data/lib/generators/devisable/templates/app/helpers/roles_helper.erb +63 -0
  13. data/lib/generators/devisable/templates/app/models/permission.erb +12 -0
  14. data/lib/generators/devisable/templates/app/models/role.erb +5 -0
  15. data/lib/generators/devisable/templates/app/views/roles/_form.erb +29 -0
  16. data/lib/generators/devisable/templates/app/views/roles/edit.erb +6 -0
  17. data/lib/generators/devisable/templates/app/views/roles/index.erb +28 -0
  18. data/lib/generators/devisable/templates/app/views/roles/new.erb +5 -0
  19. data/lib/generators/devisable/templates/app/views/roles/show.erb +10 -0
  20. data/lib/generators/devisable/templates/app/views/shared/_admin_nav.erb +7 -0
  21. data/lib/generators/devisable/templates/app/views/users/_form.erb +23 -0
  22. data/lib/generators/devisable/templates/app/views/users/edit.erb +6 -0
  23. data/lib/generators/devisable/templates/app/views/users/index.erb +27 -0
  24. data/lib/generators/devisable/templates/app/views/users/new.erb +5 -0
  25. data/lib/generators/devisable/templates/app/views/users/show.erb +55 -0
  26. data/lib/generators/devisable/templates/app/views/welcome/welcome_index.erb +3 -0
  27. data/lib/generators/devisable/templates/config/initializers/devise_initializer.erb +239 -0
  28. data/lib/generators/devisable/templates/cucumber/_rake_partial.rb +19 -0
  29. data/lib/generators/devisable/templates/cucumber/devise.feature +78 -0
  30. data/lib/generators/devisable/templates/cucumber/role.feature +79 -0
  31. data/lib/generators/devisable/templates/cucumber/step_definitions/authentication_steps.rb +33 -0
  32. data/lib/generators/devisable/templates/cucumber/step_definitions/generic_steps.rb +23 -0
  33. data/lib/generators/devisable/templates/cucumber/step_definitions/role_steps.rb +32 -0
  34. data/lib/generators/devisable/templates/cucumber/step_definitions/user_steps.rb +30 -0
  35. data/lib/generators/devisable/templates/cucumber/support/_env_partial.rb +57 -0
  36. data/lib/generators/devisable/templates/cucumber/support/_paths_partial.rb +20 -0
  37. data/lib/generators/devisable/templates/cucumber/user.feature +45 -0
  38. data/lib/generators/devisable/templates/partials/_ability_class.rb +53 -0
  39. data/lib/generators/devisable/templates/partials/_access_denied_flash.rb +4 -0
  40. data/lib/generators/devisable/templates/partials/_accessible_permissions_controller.rb +8 -0
  41. data/lib/generators/devisable/templates/partials/_accessible_permissions_model.rb +43 -0
  42. data/lib/generators/devisable/templates/partials/_application_controller_methods.erb +3 -0
  43. data/lib/generators/devisable/templates/partials/_application_controller_methods2.erb +11 -0
  44. data/lib/generators/devisable/templates/partials/_application_current_tab.rb +8 -0
  45. data/lib/generators/devisable/templates/partials/_application_flash.html.erb +4 -0
  46. data/lib/generators/devisable/templates/partials/_environments_development.erb +10 -0
  47. data/lib/generators/devisable/templates/partials/_login_links.erb +18 -0
  48. data/lib/generators/devisable/templates/partials/_migration_down.rb +2 -0
  49. data/lib/generators/devisable/templates/partials/_migration_up.rb +7 -0
  50. data/lib/generators/devisable/templates/partials/_oauth_user_table_fields.erb +1 -0
  51. data/lib/generators/devisable/templates/partials/_permission_equals.rb +8 -0
  52. data/lib/generators/devisable/templates/partials/_permission_manage.js +18 -0
  53. data/lib/generators/devisable/templates/partials/_role_permission.rb +72 -0
  54. data/lib/generators/devisable/templates/partials/_roles_index_delete.erb +7 -0
  55. data/lib/generators/devisable/templates/partials/_user_model_methods.erb +21 -0
  56. data/lib/generators/devisable/templates/partials/_user_role.rb +7 -0
  57. data/lib/generators/devisable/templates/spec/helpers/roles_helper_spec.erb +50 -0
  58. data/lib/generators/devisable/templates/spec/models/ability_spec.erb +69 -0
  59. data/lib/generators/devisable/templates/spec/models/permission_spec.erb +22 -0
  60. data/lib/generators/devisable/templates/spec/models/role_spec.erb +45 -0
  61. data/lib/generators/devisable/templates/spec/models/user_spec.erb +65 -0
  62. data/pkg/devisable-0.1.0.gem +0 -0
  63. data/pkg/devise_generator-0.1.0.gem +0 -0
  64. data/test/helper.rb +18 -0
  65. data/test/test_devise_generator.rb +7 -0
  66. metadata +169 -0
@@ -0,0 +1,117 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{devisable}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Scott Sampson", "Jeremiah Hemphill"]
12
+ s.date = %q{2011-03-23}
13
+ s.description = %q{Generates initial code for a devise install. Gives the options for oauth, using cancan, and creating a user tool to manage the users.}
14
+ s.email = %q{scott@cloudspace.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Devisable.gemspec",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/generators/devisable/USAGE",
27
+ "lib/generators/devisable/devisable_generator.rb",
28
+ "lib/generators/devisable/templates/app/controllers/registrations_controller.erb",
29
+ "lib/generators/devisable/templates/app/controllers/users_controller.erb",
30
+ "lib/generators/devisable/templates/app/controllers/welcome_controller.erb",
31
+ "lib/generators/devisable/templates/app/helpers/roles_helper.erb",
32
+ "lib/generators/devisable/templates/app/models/permission.erb",
33
+ "lib/generators/devisable/templates/app/models/role.erb",
34
+ "lib/generators/devisable/templates/app/views/roles/_form.erb",
35
+ "lib/generators/devisable/templates/app/views/roles/edit.erb",
36
+ "lib/generators/devisable/templates/app/views/roles/index.erb",
37
+ "lib/generators/devisable/templates/app/views/roles/new.erb",
38
+ "lib/generators/devisable/templates/app/views/roles/show.erb",
39
+ "lib/generators/devisable/templates/app/views/shared/_admin_nav.erb",
40
+ "lib/generators/devisable/templates/app/views/users/_form.erb",
41
+ "lib/generators/devisable/templates/app/views/users/edit.erb",
42
+ "lib/generators/devisable/templates/app/views/users/index.erb",
43
+ "lib/generators/devisable/templates/app/views/users/new.erb",
44
+ "lib/generators/devisable/templates/app/views/users/show.erb",
45
+ "lib/generators/devisable/templates/app/views/welcome/welcome_index.erb",
46
+ "lib/generators/devisable/templates/config/initializers/devise_initializer.erb",
47
+ "lib/generators/devisable/templates/cucumber/_rake_partial.rb",
48
+ "lib/generators/devisable/templates/cucumber/devise.feature",
49
+ "lib/generators/devisable/templates/cucumber/role.feature",
50
+ "lib/generators/devisable/templates/cucumber/step_definitions/authentication_steps.rb",
51
+ "lib/generators/devisable/templates/cucumber/step_definitions/generic_steps.rb",
52
+ "lib/generators/devisable/templates/cucumber/step_definitions/role_steps.rb",
53
+ "lib/generators/devisable/templates/cucumber/step_definitions/user_steps.rb",
54
+ "lib/generators/devisable/templates/cucumber/support/_env_partial.rb",
55
+ "lib/generators/devisable/templates/cucumber/support/_paths_partial.rb",
56
+ "lib/generators/devisable/templates/cucumber/user.feature",
57
+ "lib/generators/devisable/templates/partials/_ability_class.rb",
58
+ "lib/generators/devisable/templates/partials/_access_denied_flash.rb",
59
+ "lib/generators/devisable/templates/partials/_accessible_permissions_controller.rb",
60
+ "lib/generators/devisable/templates/partials/_accessible_permissions_model.rb",
61
+ "lib/generators/devisable/templates/partials/_application_controller_methods.erb",
62
+ "lib/generators/devisable/templates/partials/_application_controller_methods2.erb",
63
+ "lib/generators/devisable/templates/partials/_application_current_tab.rb",
64
+ "lib/generators/devisable/templates/partials/_application_flash.html.erb",
65
+ "lib/generators/devisable/templates/partials/_environments_development.erb",
66
+ "lib/generators/devisable/templates/partials/_login_links.erb",
67
+ "lib/generators/devisable/templates/partials/_migration_down.rb",
68
+ "lib/generators/devisable/templates/partials/_migration_up.rb",
69
+ "lib/generators/devisable/templates/partials/_oauth_user_table_fields.erb",
70
+ "lib/generators/devisable/templates/partials/_permission_equals.rb",
71
+ "lib/generators/devisable/templates/partials/_permission_manage.js",
72
+ "lib/generators/devisable/templates/partials/_role_permission.rb",
73
+ "lib/generators/devisable/templates/partials/_roles_index_delete.erb",
74
+ "lib/generators/devisable/templates/partials/_user_model_methods.erb",
75
+ "lib/generators/devisable/templates/partials/_user_role.rb",
76
+ "lib/generators/devisable/templates/spec/helpers/roles_helper_spec.erb",
77
+ "lib/generators/devisable/templates/spec/models/ability_spec.erb",
78
+ "lib/generators/devisable/templates/spec/models/permission_spec.erb",
79
+ "lib/generators/devisable/templates/spec/models/role_spec.erb",
80
+ "lib/generators/devisable/templates/spec/models/user_spec.erb",
81
+ "pkg/devisable-0.1.0.gem",
82
+ "pkg/devise_generator-0.1.0.gem",
83
+ "test/helper.rb",
84
+ "test/test_devise_generator.rb"
85
+ ]
86
+ s.homepage = %q{http://github.com/scottsampson/devisable}
87
+ s.licenses = ["MIT"]
88
+ s.require_paths = ["lib"]
89
+ s.rubygems_version = %q{1.6.2}
90
+ s.summary = %q{Generates a complete devise install including cancan, and oauth}
91
+ s.test_files = [
92
+ "test/helper.rb",
93
+ "test/test_devise_generator.rb"
94
+ ]
95
+
96
+ if s.respond_to? :specification_version then
97
+ s.specification_version = 3
98
+
99
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
100
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
101
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
102
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
103
+ s.add_development_dependency(%q<rcov>, [">= 0"])
104
+ else
105
+ s.add_dependency(%q<shoulda>, [">= 0"])
106
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
107
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
108
+ s.add_dependency(%q<rcov>, [">= 0"])
109
+ end
110
+ else
111
+ s.add_dependency(%q<shoulda>, [">= 0"])
112
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
113
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
114
+ s.add_dependency(%q<rcov>, [">= 0"])
115
+ end
116
+ end
117
+
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Scott Sampson
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.
@@ -0,0 +1,111 @@
1
+ = Devisable
2
+
3
+ Start your rails project off right with Devisable.
4
+
5
+ It is a quick and easy generator that sets up devise,cancan and/or oauth on your site. It:
6
+
7
+ * Supports facebook and twitter oauth.
8
+ * Uses cancan permissions
9
+ * Has a user and roles tool so you can change permissions inside a gui
10
+ * Supports all devise options
11
+ * Contains rspec and cucumber test options
12
+ * Can be added to existing project that don't already have devise.
13
+
14
+ == Installation
15
+
16
+ Devisable supports rails 3 with ruby >= 1.9.2.
17
+
18
+ gem install Devisable
19
+
20
+ Then Add Devisable to your gemfile
21
+
22
+ rails generate devisable --help
23
+
24
+ == Usage
25
+
26
+ It is always good practice to start a new branch in your repo before making major updates like when using devisable.
27
+
28
+ Use --help to see a list of complete options
29
+
30
+ Runtime Options:
31
+
32
+ -c, [--config] # Configuration Options for devise. ie 1,2,3,7,11 (see Devise options below)
33
+ -t, [--twitteroauth] # Twitter Oauth key and secret seperated by , (comma). ie 123lk23jjsdfklsd,2l4kljknsdjlsdf
34
+ -o, [--facebookoauth] # Facebook Oauth key, secret and client_id seperated by , (comma). ie 123lk23jjsdfklsd,2l4kljknsdjlsdf,102092932
35
+ -g, [--gems] # Version of the gems you want to use seperated by Devise,Warden,Cancan. ie 1.1.5,0.1.1,1.5.1
36
+ -d, [--denied] # add this option if you want to add a customized permission denied message
37
+ -e, [--extra] # Extra fields added to the user model. ie first_name:string,last_name:string
38
+ -n, [--new] # If the project is brand new. Will remove the index.html and add the root route
39
+ -s, [--sudo] # Use sudo for the gem install commands (for non rvm/osx users)
40
+ -u, [--url] # Rool url for your app in development
41
+ -C, [--cucumber] # Include cucumber tests, currently does not support oauth
42
+
43
+ Devise Options (used with the -c command)
44
+
45
+ 1. Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of an user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
46
+ 2. Token Authenticatable: signs in an user based on an authentication token (also known as “single access token”). The token can be given both through query string or HTTP Basic Authentication.
47
+ 3. Oauthable: adds OAuth2 support
48
+ 4. Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
49
+ 5. Recoverable: resets the user password and sends reset instructions.
50
+ 6. Registerable: handles signing up users through a registration process, also allowing them to edit and destroy their account.
51
+ 7. Rememberable: manages generating and clearing a token for remembering the user from a saved cookie.
52
+ 8. Trackable: tracks sign in count, timestamps and IP address.
53
+ 9. Timeoutable: expires sessions that have no activity in a specified period of time.
54
+ 10. Validatable: provides validations of email and password. It’s optional and can be customized, so you’re able to define your own validations.
55
+ 11. Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
56
+
57
+ To just setup Basic authentication with devisable
58
+
59
+ rails generate devisable
60
+
61
+ This will setup with the devise options 1,4,5,7,8,10
62
+
63
+ Twitter Oauth - Note you will need to setup your app in twitter before running this
64
+
65
+ rails generate devisable -c 2,3 -t <key>,<secret> -u <url_to_your_project>
66
+
67
+ rails generate devisable -c 2,3 -t asdf489fhkbnajbsdf,2uh3uh383493hkjdf -u http://dev.yoururl.com
68
+
69
+ Facebook Oauth
70
+
71
+ rails generate devisable -c 2,3 -o <key>,<secret>,<app_id> -u <url_to_your_project>
72
+
73
+ rails generate devisable -c 2,3 -o asdf489fhkbnajbsdf,2uh3uh383493hkjdf,10100101001 -u http://dev.yoururl.com
74
+
75
+ All three (normal authentication,twitter_oauth, facebook_oauth)
76
+
77
+ rails generate devisable -c 1,2,3,5,6,7,8 -t asdf489fhkbnajbsdf,2uh3uh383493hkjdf -o asdf489fhkbnajbsdf,2uh3uh383493hkjdf,10100101001 -u http://dev.yoururl.com
78
+
79
+ Starting a project - Use the -n option
80
+
81
+ rails generate devisable -c 1,2,3,5,6,7,8 -t asdf489fhkbnajbsdf,2uh3uh383493hkjdf -o asdf489fhkbnajbsdf,2uh3uh383493hkjdf,10100101001 -n -u http://dev.yoururl.com
82
+
83
+ Add Cucumber tests - use the -C option
84
+
85
+ rails generate devisable -c 1,2,3,5,6,7,8 -t asdf489fhkbnajbsdf,2uh3uh383493hkjdf -o asdf489fhkbnajbsdf,2uh3uh383493hkjdf,10100101001 -n -C -u http://dev.yoururl.com
86
+
87
+ Add extra fields to the user model
88
+
89
+ rails generate devisable -e first_name:string,last_name:string
90
+
91
+ == Contributing to devisable
92
+
93
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
94
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
95
+ * Fork the project
96
+ * Start a feature/bugfix branch
97
+ * Commit and push until you are happy with your contribution
98
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
99
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
100
+
101
+ == TODOS
102
+
103
+ * Be able to tie your facebook, twitter, and normal authentication options to each other.
104
+ * Support for haml and sass instead of erb
105
+ * Add Facebook javascript autologin option
106
+
107
+ == Copyright
108
+
109
+ Copyright (c) 2011 Scott. See LICENSE.txt for
110
+ further details.
111
+
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "devisable"
19
+ gem.homepage = "http://github.com/scottsampson/devisable"
20
+ gem.license = "MIT"
21
+ gem.summary = "Generates a complete devise install including cancan, and oauth"
22
+ gem.description = "Generates initial code for a devise install. Gives the options for oauth, using cancan, and creating a user tool to manage the users."
23
+ gem.email = "scott@cloudspace.com"
24
+ gem.authors = ["Scott Sampson","Jeremiah Hemphill"]
25
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
26
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
27
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
28
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ require 'rcov/rcovtask'
40
+ Rcov::RcovTask.new do |test|
41
+ test.libs << 'test'
42
+ test.pattern = 'test/**/test_*.rb'
43
+ test.verbose = true
44
+ end
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "devise_generator #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,57 @@
1
+ Description:
2
+ This generator will build the code for devise and any necessary requirements such as cancan, warden, oauth.
3
+
4
+ Options for devise include:
5
+ 1. Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of an user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
6
+ 2. Token Authenticatable: signs in an user based on an authentication token (also known as “single access token”). The token can be given both through query string or HTTP Basic Authentication.
7
+ 3. Oauthable: adds OAuth2 support
8
+ 4. Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
9
+ 5. Recoverable: resets the user password and sends reset instructions.
10
+ 6. Registerable: handles signing up users through a registration process, also allowing them to edit and destroy their account.
11
+ 7. Rememberable: manages generating and clearing a token for remembering the user from a saved cookie.
12
+ 8. Trackable: tracks sign in count, timestamps and IP address.
13
+ 9. Timeoutable: expires sessions that have no activity in a specified period of time.
14
+ 10. Validatable: provides validations of email and password. It’s optional and can be customized, so you’re able to define your own validations.
15
+ 11. Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
16
+
17
+ More runtime options:
18
+ Runtime options:
19
+ -c, [--config] # Configuration Options for devise. ie 1,2,3,7,11
20
+ -t, [--twitteroauth] # Twitter Oauth key and secret seperated by , (comma). ie 123lk23jjsdfklsd,2l4kljknsdjlsdf
21
+ -o, [--facebookoauth] # Facebook Oauth key, secret and client_id seperated by , (comma). ie 123lk23jjsdfklsd,2l4kljknsdjlsdf,102092932
22
+ -g, [--gems] # Version of the gems you want to use seperated by Devise,Warden,Cancan. ie 1.1.5,0.1.1,1.5.1
23
+ -d, [--denied] # add this option if you want to add a customized permission denied message
24
+ -e, [--extra] # Extra fields added to the user model. ie first_name:string,last_name:string
25
+ -n, [--new] # If the project is brand new. Will remove the index.html and add the root route
26
+ -s, [--sudo] # Use sudo for the gem install commands (for non rvm/osx users)
27
+ -u, [--url] # Rool url for your app in development
28
+ -C, [--cucumber] # Include cucumber tests, currently does not support oauth
29
+
30
+ Things you still need to update after you run this:
31
+ - Add the before filter to each controller.
32
+ - You can find an example in the applications controller. Remove from the applications controller.
33
+ - Clean up the users model.
34
+ - If you have not done so, remove the index.html and add a root route to your routes.rb file
35
+ - Move the login/logout links
36
+ - I added them to layouts/application.html.erb
37
+ - Fix the navigation
38
+ - I added the partial to layouts/application.html.erb
39
+ - If you don't have flash notices you need to add them in your layout
40
+
41
+ Examples:
42
+ twitter oauth:
43
+
44
+ rails generate devisable -c 2,3 -t asdf489fhkbnajbsdf,2uh3uh383493hkjdf -g 1.1.5,0.1.1,1.5.1 -r -d -e first_name:string,last_name:string -u http://dev.yoururl.com
45
+
46
+ facebook oauth:
47
+
48
+ rails generate devisable -c 2,3 -o asdf489fhkbnajbsdf,2uh3uh383493hkjdf,10201020202 -g 1.1.5,0.1.1,1.5.1 -r -d -e first_name:string,last_name:string -u http://dev.yoururl.com
49
+
50
+ No oauth:
51
+
52
+ rails generate devisable -c 1,4,5,7,8,10 -g 1.1.5,0.1.1,1.5.1 -r -d -e first_name:string,last_name:string
53
+
54
+ Default run is:
55
+
56
+ rails generate devisable -c 1,4,5,7,8,10
57
+
@@ -0,0 +1,484 @@
1
+ require 'rubygems'
2
+ require 'optparse'
3
+ require 'bundler'
4
+ require 'bundler/cli'
5
+
6
+ class DevisableGenerator < Rails::Generators::Base
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ @@available_configuration_options = {
10
+ '1' => 'database_authenticatable',
11
+ '2' => 'token_authenticatable',
12
+ '3' => 'oauthable',
13
+ '4' => 'confirmable',
14
+ '5' => 'recoverable',
15
+ '6' => 'registerable',
16
+ '7' => 'rememberable',
17
+ '8' => 'trackable',
18
+ '9' => 'timeoutable',
19
+ '10' => 'validatable',
20
+ '11' => 'lockable'
21
+ }
22
+ @@actual_configuration_options = {
23
+ 'config' => ['1','5','6','7','8','10'],
24
+ 'twitter_oauth' => [],
25
+ 'facebook_oauth' => [],
26
+ 'gems' => ['1.1.5','0.1.1','1.5.1','1.5.1'], #devise, warden_oauth, cancan, json_pure
27
+ 'registration' => false,
28
+ 'denied' => false,
29
+ 'extra' => [],
30
+ 'new' => false,
31
+ 'sudo' => false,
32
+ 'url' => 'http://localhost:3000'
33
+ }
34
+
35
+
36
+ #setups up configuration options from command line
37
+ #@param runtime_args [string,nil] arguments passed in via command line
38
+ def initialize(*runtime_args)
39
+ super(*runtime_args)
40
+ #@tut_args = runtime_args
41
+ #@@actual_configuration_options = @tut_args[1].split(',')
42
+
43
+ # -c, [--config] [string] # Configuration Options for devise. ie 1,2,3,7,11
44
+ # -o, [--oauth] [string] # Oauth secret and key seperated by , (comma). ie 123lk23jjsdfklsd,2l4kljknsdjlsdf
45
+ # -g, [--gems] [string] # Version of the gems you want to use seperated by Devise,Warden_oauth,Cancan. ie 1.1.5,0.1.1,1.5.1
46
+ # -r, [--registration] #add this option if you want to add a customized registration controller
47
+ # -d, [--denied] # add this option if you want to add a customized permission denied message
48
+ # -e, [--extra] [string] # Extra fields added to the user model. ie first_name:string,last_name:string
49
+ # -s, [--sudo] # add this option if gem commands need to use sudo
50
+
51
+
52
+ OptionParser.new do |opts|
53
+ opts.banner = "Usage: autoperf.rb [-c config]"
54
+
55
+ opts.on("-c", "--config [string]", String, "Devise configuration options") do |v|
56
+ @@actual_configuration_options['config'] = v.split(',')
57
+ end
58
+ opts.on("-t", "--twitteroauth [string]", String, "twitter oauth key and secret") do |v|
59
+ @@actual_configuration_options['twitter_oauth'] = v.split(',')
60
+ if @@actual_configuration_options['twitter_oauth'].length != 2
61
+ throw_error("You must have both key and secret seperated by comma for -to option.")
62
+ end
63
+ end
64
+ opts.on("-o", "--facebookoauth [string]", String, "facebook oauth key, secret, and client_id") do |v|
65
+ @@actual_configuration_options['facebook_oauth'] = v.split(',')
66
+ if @@actual_configuration_options['facebook_oauth'].length != 3
67
+ throw_error("You must have key, secret, and client_id seperated by comma for -fo option.")
68
+ end
69
+ end
70
+ opts.on("-g", "--gems [string]", String, "Gem Version options") do |v|
71
+ @@actual_configuration_options['gems'] = v.split(',')
72
+ if @@actual_configuration_options['gems'].length != 3
73
+ throw_error("You must have 3 gem versions seperated by comma for -g option. ie devise,warden,cancan")
74
+ end
75
+ end
76
+ opts.on("-d", "--denied [string]", String, "Add customized permission denied message") do |v|
77
+ @@actual_configuration_options['denied'] = true
78
+ end
79
+ opts.on("-e", "--extra [string]", String, "Extra fields added to the user model") do |v|
80
+ @@actual_configuration_options['extra'] = v.split(',')
81
+ end
82
+ opts.on("-n", "--new [string]", String, "Is New Project") do |v|
83
+ @@actual_configuration_options['new'] = true
84
+ end
85
+ opts.on("-s", "--sudo [string]", String, "Using sudo for gem commands") do |v|
86
+ @@actual_configuration_options['sudo'] = true
87
+ end
88
+ opts.on("-u", "--url [string]", String, "Root url for your app in development") do |v|
89
+ @@actual_configuration_options['url'] = v
90
+ end
91
+ opts.on("-C", "--cucumber [string]", String, "Include cucumber tests") do |v|
92
+ @@actual_configuration_options['cucumber'] = true
93
+ end
94
+ end.parse!
95
+ execute
96
+ end
97
+
98
+ #stops execution and prints error if an important enough error occurs
99
+ #@param error [string] The string that gets printed out when the error is thrown
100
+ def throw_error(error = '')
101
+ puts error
102
+ exit();
103
+ end
104
+
105
+ #replaces the last string 'end' in a file with the value of rep_str
106
+ #
107
+ #@param filename [string] file that will be manipulated
108
+ #@param rep_str [string] what the last end in the file will be replaced with
109
+ #@return nil
110
+ def replace_last_end_in_file_with(filename,rep_str)
111
+ gsub_file filename , /^(.*)end$/m, "\\1" + rep_str + "\nend"
112
+ end
113
+
114
+ #Adds all the necessary gems
115
+
116
+ def add_gems
117
+ sudo = ''
118
+ if @@actual_configuration_options['sudo']
119
+ sudo = 'sudo '
120
+ end
121
+ gem("devise", @@actual_configuration_options['gems'][0])
122
+ gem("warden_oauth", :version => @@actual_configuration_options['gems'][1], :git => "git://github.com/scottsampson/warden_oauth.git")
123
+ gem("cancan", @@actual_configuration_options['gems'][2])
124
+ gem("json_pure", @@actual_configuration_options['gems'][3])
125
+ gem("twitter_oauth", @@actual_configuration_options['gems'][4])
126
+
127
+ # cucumber only gems
128
+ if @@actual_configuration_options['cucumber']
129
+ gem("capybara")
130
+ gem("database_cleaner")
131
+ gem("cucumber-rails")
132
+ gem("cucumber")
133
+ gem("rspec-rails")
134
+ end
135
+ Bundler.with_clean_env do
136
+ output = system("bundle install")
137
+ if !output
138
+ err_str = "Gem conflict. Please make sure your gem versions in your Gemfile match the following:\n\n"
139
+ err_str += "devise - #{@@actual_configuration_options['gems'][0]}\n"
140
+ err_str += "warden_oauth - #{@@actual_configuration_options['gems'][1]}\n"
141
+ err_str += "cancan - #{@@actual_configuration_options['gems'][2]}\n"
142
+ err_str += "json_pure - #{@@actual_configuration_options['gems'][3]}\n\n\n"
143
+ throw_error(err_str)
144
+ end
145
+ end
146
+ end
147
+
148
+ #generates the devise user with option arguments from the 'extra' configuration options
149
+ def generate_devise_user
150
+ extra_args = ''
151
+ for i in 0...@@actual_configuration_options['extra'].length
152
+ extra_args << ' ' + @@actual_configuration_options['extra'][i]
153
+ end
154
+ unless extra_args.include?('username')
155
+ extra_args << ' username:string'
156
+ end
157
+ generate("devise:install")
158
+ generate("devise","user" + extra_args)
159
+ generate("devise:views")
160
+ end
161
+
162
+ #takes the options from the command line and
163
+ #replaces the existing devise configuration in the user model
164
+ #with the new one.
165
+ def generate_user_configuration
166
+ rep_str = ''
167
+ @@actual_configuration_options['config'].each do |option|
168
+ rep_str << ', :' + @@available_configuration_options[option]
169
+ end
170
+ rep_str = ' devise ' + rep_str[1..-1] + "\n"
171
+ gsub_file "app/models/user.rb" , /^[ ]*(devise)([^\n]*)(\n)(.*)(\s)/, rep_str
172
+
173
+ rep_str = load_erb_string('partials/_user_model_methods.erb')
174
+ replace_last_end_in_file_with("app/models/user.rb",rep_str)
175
+ end
176
+
177
+ #grabs a certain migration file that already exists so it can be modified
178
+ #@param name excerpt of the name of the file you want
179
+ #@return the filename you were looking for
180
+ def get_migration(name)
181
+ basedir = './db/migrate'
182
+ Dir.chdir(basedir)
183
+ file = basedir + '/' + Dir.glob("*" + name + "*").first
184
+ Dir.chdir('../../')
185
+ return file
186
+ end
187
+
188
+ #loads a file from the templates folder and implements erb on it
189
+ #@param filename [string] Name of the file to be retrieved
190
+ #@return the data within the file after implementing erb
191
+ def load_erb_string(filename)
192
+ @twitter_secret = @@actual_configuration_options['twitter_oauth'][1]
193
+ @twitter_key = @@actual_configuration_options['twitter_oauth'][0]
194
+ @facebook_secret = @@actual_configuration_options['facebook_oauth'][1]
195
+ @facebook_key = @@actual_configuration_options['facebook_oauth'][0]
196
+ @facebook_client_id = @@actual_configuration_options['facebook_oauth'][2]
197
+ file_path = File.expand_path("../templates", __FILE__) + '/' + filename
198
+ erb_file = ERB.new(File.read(file_path),0,"%")
199
+ return erb_file.result(binding)
200
+ end
201
+
202
+ #loads a file from the templates folder WITHOUT implementing erb
203
+ #@param filename [string] Name of the file to be retrieved
204
+ #@return the data within the file
205
+ def load_file_string(filename)
206
+ file_path = File.expand_path("../templates", __FILE__) + '/' + filename
207
+ erb_file = File.read(file_path)
208
+ return erb_file
209
+ end
210
+
211
+
212
+ #checks for oauth
213
+ #if so adds oauth code
214
+ def check_for_oauth
215
+ @has_twitter_oauth = @@actual_configuration_options['twitter_oauth'].length > 0 ? true : false
216
+ @has_facebook_oauth = @@actual_configuration_options['facebook_oauth'].length > 0 ? true : false
217
+ @has_standard_authentication = @@actual_configuration_options['config'].include?('1') ? true : false
218
+
219
+ if @has_twitter_oauth || @had_facebook_oauth
220
+
221
+ @twitter_secret = @@actual_configuration_options['twitter_oauth'][1]
222
+ @twitter_key = @@actual_configuration_options['twitter_oauth'][0]
223
+ @facebook_secret = @@actual_configuration_options['facebook_oauth'][1]
224
+ @facebook_key = @@actual_configuration_options['facebook_oauth'][0]
225
+ @facebook_client_id = @@actual_configuration_options['facebook_oauth'][2]
226
+ @url = @@actual_configuration_options['url']
227
+ #/config/initializers/devise.rb
228
+ remove_file "config/initializers/devise.rb"
229
+ template "config/initializers/devise_initializer.erb", "config/initializers/devise.rb"
230
+
231
+ # remove user password from devise sign in page
232
+ unless @@actual_configuration_options['config'].include?('1')
233
+ gsub_file "app/views/devise/sessions/new.html.erb", "<p><%= f.label :password %><br />\n", ""
234
+ gsub_file "app/views/devise/sessions/new.html.erb", "<%= f.password_field :password %></p>\n", ""
235
+ end
236
+
237
+ #add twitter_oauth
238
+ keys = load_erb_string('partials/_environments_development.erb')
239
+ append_to_file "config/environments/development.rb", keys
240
+ append_to_file "config/environments/test.rb", keys
241
+
242
+ #Add correct fields to the table
243
+ user_migration_file = get_migration("devise_create_user")
244
+ gsub_file user_migration_file, "# t.token_authenticatable", "t.token_authenticatable"
245
+ fields = load_erb_string('partials/_oauth_user_table_fields.erb')
246
+ insert_into_file user_migration_file, fields, :after => "t.token_authenticatable\n"
247
+
248
+ #add correct fields to user model
249
+ str = "attr_accessible :default_provider, :username\n"
250
+ insert_into_file "app/models/user.rb", str, :after => "# Setup accessible (or protected) attributes for your model\n"
251
+
252
+ generate("model", "oauth_profile user_id:integer provider:string token:string secret:string username:string email:string name:string img_url:string")
253
+
254
+ insert_into_file "app/models/oauth_profile.rb", "belongs_to :user\n", :after => "class OauthProfile < ActiveRecord::Base\n"
255
+
256
+ insert_into_file "app/models/user.rb", "has_many :oauth_profiles\n", :after => "class User < ActiveRecord::Base\n"
257
+
258
+ end
259
+
260
+ # Link to "Login With Twitter/Facebook" somewhere in your view
261
+ login_links = load_erb_string('partials/_login_links.erb')
262
+ insert_into_file "app/views/layouts/application.html.erb", login_links, :after => "<body>\n"
263
+ end
264
+
265
+ #adds confirmable code if the confirmable option for devise is included
266
+ def confirmable
267
+ if @@actual_configuration_options['config'].include?('4')
268
+ user_migration_file = get_migration("devise_create_user")
269
+ gsub_file user_migration_file, "# t.confirmable", "t.confirmable"
270
+
271
+ insert_into_file "app/controllers/application_controller.rb", "before_filter :mailer_set_url_options\n", :after => "class ApplicationController < ActionController::Base\n"
272
+
273
+ methods = load_erb_string('partials/_application_controller_methods.erb')
274
+ gsub_file "app/controllers/application_controller.rb", "end", methods + "\nend"
275
+ end
276
+ end
277
+
278
+ #adds lockable code if the lockable option for devise is included
279
+ def lockable
280
+ if @@actual_configuration_options['config'].include?('11')
281
+ user_migration_file = get_migration("devise_create_user")
282
+ gsub_file user_migration_file, "# t.lockable ", "t.lockable "
283
+ end
284
+ end
285
+
286
+ #adds the authenticate calls to the application controller
287
+ def add_authentication_check_to_controllers
288
+ insert_into_file "app/controllers/application_controller.rb", "before_filter :authenticate_user!, :except => []\n", :after => "class ApplicationController < ActionController::Base\n"
289
+
290
+ methods = load_erb_string('partials/_application_controller_methods2.erb')
291
+ insert_into_file "app/controllers/application_controller.rb",methods + "\n", :after => "before_filter :authenticate_user!, :except => []\n"
292
+ end
293
+
294
+ #installs cancan, updates the ability model, adds permission checks to views
295
+ def install_cancan
296
+ generate("cancan:ability")
297
+ #create the Role model
298
+ generate("scaffold","Role name:string")
299
+ generate("model","Permission role_id:integer model:string ability:string")
300
+ #create the Many To Many relationship between users and roles
301
+ generate("migration","UsersHaveAndBelongToManyRoles")
302
+ basedir = './db/migrate'
303
+ Dir.chdir(basedir)
304
+ file = basedir + '/' + Dir.glob("*users_have_and_belong_to_many*").first
305
+ Dir.chdir('../../')
306
+ self_up_migration = load_erb_string('partials/_migration_up.rb')
307
+ self_down_migration = load_erb_string('partials/_migration_down.rb')
308
+ insert_into_file file, self_up_migration, :after => "def self.up\n"
309
+ insert_into_file file, self_down_migration, :after => "def self.down\n"
310
+ insert_into_file "app/models/user.rb", "has_and_belongs_to_many :roles\n", :after => "class User < ActiveRecord::Base\n"
311
+ insert_into_file "app/models/role.rb", "has_and_belongs_to_many :users\n", :after => "class Role < ActiveRecord::Base\n"
312
+ insert_into_file "app/models/role.rb", "has_many :permissions\nvalidates_presence_of :name\n", :after => "has_and_belongs_to_many :users\n"
313
+ insert_into_file "app/controllers/roles_controller.rb", "before_filter :accessible_permissions, :only => [:new, :edit, :show, :update, :create]\nload_and_authorize_resource\n", :after => "class RolesController < ApplicationController\n"
314
+ insert_into_file "app/controllers/roles_controller.rb", "@role.save_permissions(params[:role_ids])\n", :after => "if @role.update_attributes(params[:role])\n"
315
+
316
+ insert_into_file "app/controllers/roles_controller.rb", "@role.save_permissions(params[:role_ids]) \n", :after => "if @role.save\n"
317
+ insert_into_file "app/models/permission.rb", "belongs_to :role\n", :after => "class Permission < ActiveRecord::Base\n"
318
+ rep_str = load_erb_string('partials/_permission_equals.rb')
319
+ insert_into_file "app/models/permission.rb", rep_str, :after => "belongs_to :role\n"
320
+
321
+ rep_str = load_erb_string('partials/_ability_class.rb')
322
+ gsub_file "app/models/ability.rb" , /^(.*)end$/m, rep_str
323
+ rep_str = load_erb_string('partials/_user_role.rb')
324
+ insert_into_file "app/models/user.rb", rep_str, :after => "has_and_belongs_to_many :roles\n"
325
+ end
326
+
327
+ #add a customized registration controller
328
+ def customize_registration_controller
329
+ template "app/controllers/registrations_controller.erb", "app/controllers/registrations_controller.rb"
330
+ gsub_file "config/routes.rb" , "devise_for :users\n", "devise_for :users, :controllers => { :registrations => \"registrations\" }\n"
331
+ end
332
+
333
+ #add a customize permission denied message for cancan
334
+ def customize_permission_denied_error
335
+ if @@actual_configuration_options['denied']
336
+ rep_str = load_erb_string('partials/_access_denied_flash.rb')
337
+ insert_into_file "app/controllers/application_controller.rb", rep_str, :after => "protect_from_forgery\n"
338
+ end
339
+ end
340
+
341
+ #creates the user tool instead of using scaffolding
342
+ def create_user_tool
343
+ @show_password = @@actual_configuration_options['config'].include?('1')
344
+ #TODO: Have to make sure if they have changed the devise_for :users that we account for it here.
345
+ insert_into_file "config/routes.rb", "resources :users", :after => "devise_for :users, :controllers => { :registrations => \"registrations\" }\n"
346
+ template "app/views/users/index.erb", "app/views/users/index.html.erb"
347
+ template "app/views/users/new.erb", "app/views/users/new.html.erb"
348
+ template "app/views/users/show.erb", "app/views/users/show.html.erb"
349
+ template "app/views/users/edit.erb", "app/views/users/edit.html.erb"
350
+ template "app/views/users/_form.erb", "app/views/users/_form.html.erb"
351
+ template "app/controllers/users_controller.erb", "app/controllers/users_controller.rb"
352
+ end
353
+
354
+ #uses scaffold to create the roles tool but then overrides many of the methods
355
+ def create_roles_tool
356
+ #TODO: Have to make sure if they have changed the devise_for :users that we account for it here.
357
+ rep_str = load_file_string('partials/_role_permission.rb')
358
+ insert_into_file "app/helpers/roles_helper.rb", rep_str, :after => "module RolesHelper\n"
359
+ #most of this is done in the scaffold above
360
+ gsub_file "app/views/roles/index.html.erb" , "<td><%= link_to 'Edit', edit_role_path(role) %></td>", "<td><%= link_to_if(can?(:edit, Role), 'Edit', edit_role_path(role)) %></td>"
361
+ rep_str = load_erb_string('partials/_roles_index_delete.erb')
362
+ gsub_file "app/views/roles/index.html.erb" , "<td><%= link_to 'Destroy', role, :confirm => 'Are you sure?', :method => :delete %></td>", rep_str
363
+
364
+ gsub_file "app/views/roles/show.html.erb" , "<%= link_to 'Edit', edit_role_path(@role) %>", "<%= link_to_if(can?(:edit, Role), 'Edit', edit_role_path(@role)) %>"
365
+ gsub_file "app/views/roles/show.html.erb" , "<p id=\"notice\"><%= notice %></p>", ""
366
+ gsub_file "app/views/roles/_form.html.erb" , /^[\s]*(<div class="actions">)[\s]+(<%= f.submit %>)[\s]+(<\/div>)/m, "<p><%= f.label :permission %></p>\n <ul class=\"no-pad no-bullets\">\n <%= permissions_checkboxes(@role, :permission_ids, @accessible_permissions, @role.id) %>\n </ul>\n <div class=\"actions\">\n <%= f.submit %>\n </div>"
367
+
368
+
369
+ rep_str = load_erb_string('partials/_accessible_permissions_model.rb')
370
+ gsub_file "app/models/role.rb", /^(\s)*end\Z/m, rep_str
371
+ rep_str = load_erb_string('partials/_accessible_permissions_controller.rb')
372
+ gsub_file "app/controllers/roles_controller.rb" , /^(\s)*end\Z/m, rep_str
373
+ gsub_file "app/controllers/roles_controller.rb" , "format.html { redirect_to(roles_url) }", "format.html { redirect_to(roles_url, :notice => 'Role was successfully deleted.') }"
374
+ end
375
+
376
+ #adds the shared navigation to the layout view
377
+ def create_tool_navigation
378
+ empty_directory "app/views/shared"
379
+ template "app/views/shared/_admin_nav.erb", "app/views/shared/_admin_nav.html.erb"
380
+ rep_str = load_erb_string('partials/_application_current_tab.rb')
381
+ insert_into_file "app/helpers/application_helper.rb", rep_str, :after => "module ApplicationHelper\n"
382
+ end
383
+
384
+ #if the new option is selected removes the index file. Adds a welcome controller. Adds the root route
385
+ def new_project
386
+ if @@actual_configuration_options['new']
387
+ remove_file "public/index.html"
388
+ insert_into_file "config/routes.rb", "root :to => 'welcome#index'", :after => "resources :users\n"
389
+ template "app/controllers/welcome_controller.erb", "app/controllers/welcome_controller.rb"
390
+ empty_directory "app/views/welcome"
391
+ template "app/views/welcome/welcome_index.erb", "app/views/welcome/index.html.erb"
392
+ insert_into_file "config/routes.rb", "root :to => 'welcome#index'", :after => "resources :users\n"
393
+ rep_str = load_erb_string('partials/_application_flash.html.erb')
394
+ insert_into_file "app/views/layouts/application.html.erb", rep_str, :after => "<%= render 'shared/admin_nav' %>\n"
395
+ end
396
+ end
397
+
398
+ #adds the javascript for the role permissions checkboxes
399
+ def add_javascript
400
+ rep_str = load_erb_string('partials/_permission_manage.js')
401
+ append_to_file "public/javascripts/application.js", rep_str
402
+ end
403
+
404
+ #adds all the features and steps for cucumber tests
405
+ def add_cucumber_tests
406
+ if @@actual_configuration_options['cucumber']
407
+ generate('cucumber:install')
408
+ # features
409
+ template('cucumber/devise.feature', 'features/devise.feature')
410
+ template('cucumber/user.feature', 'features/user.feature')
411
+ template('cucumber/role.feature', 'features/role.feature')
412
+ # step definitions
413
+ template('cucumber/step_definitions/authentication_steps.rb', 'features/step_definitions/authentication_steps.rb')
414
+ template('cucumber/step_definitions/generic_steps.rb', 'features/step_definitions/generic_steps.rb')
415
+ template('cucumber/step_definitions/role_steps.rb', 'features/step_definitions/role_steps.rb')
416
+ template('cucumber/step_definitions/user_steps.rb', 'features/step_definitions/user_steps.rb')
417
+ # support
418
+ #empty_directory "features/support"
419
+ rep_str = load_erb_string('cucumber/support/_paths_partial.rb')
420
+ insert_into_file('features/support/paths.rb', rep_str, :after => "case page_name\n")
421
+ # this edit to the cucumber env file may be caused by rails 3.0.1 and can be removed after testing
422
+ gsub_file('features/support/env.rb', "require 'cucumber/rails/capybara_javascript_emulation'", "#require 'cucumber/rails/capybara_javascript_emulation'")
423
+ # rake task
424
+ rep_str = load_erb_string('cucumber/_rake_partial.rb')
425
+ insert_into_file('lib/tasks/cucumber.rake', rep_str, :after => "namespace :cucumber do\n")
426
+ gsub_file('lib/tasks/cucumber.rake', "task :cucumber => 'cucumber:ok'", "task :cucumber => ['cucumber:setup_js_with_vnc4server', 'cucumber:ok', 'cucumber:kill_js']")
427
+ end
428
+ end
429
+
430
+ #if you want to send the confirmable email you need to set the default mailer
431
+ def add_default_mailer_config
432
+ rep_str = "config.action_mailer.default_url_options = { :host => \"#{@@actual_configuration_options['url']}\" }\n"
433
+ insert_into_file "config/environments/development.rb", rep_str, :after => "config.action_mailer.raise_delivery_errors = false\n"
434
+ insert_into_file "config/environments/test.rb", rep_str, :after => "config.action_mailer.delivery_method = :test\n"
435
+ end
436
+
437
+ #add a little custom css for the flash notices
438
+ def modify_css
439
+ gsub_file('public/stylesheets/scaffold.css', "#notice {", "#notice, div.notice {")
440
+ end
441
+
442
+ #adds the rspec tests
443
+ def add_rspec_tests
444
+ rake('db:create')
445
+ generate('rspec:install')
446
+ ['ability_spec','permission_spec','role_spec','user_spec'].each do |filename|
447
+ remove_file "spec/models/#{filename}.rb"
448
+ template("spec/models/#{filename}.erb", "spec/models/#{filename}.rb")
449
+ end
450
+ removing_files = ['spec/controllers/roles_controller_spec.rb','spec/helpers/roles_helper_spec.rb']
451
+ removing_files += ['spec/views/roles/edit.html.erb_spec.rb','spec/views/roles/index.html.erb_spec.rb']
452
+ removing_files += ['spec/views/roles/new.html.erb_spec.rb','spec/views/roles/show.html.erb_spec.rb','spec/requests/roles_spec.rb']
453
+ removing_files += ['spec/models/oauth_profile_spec.rb']
454
+ removing_files.each do |filename|
455
+ remove_file filename
456
+ end
457
+ template('spec/helpers/roles_helper_spec.erb', 'spec/helpers/roles_helper_spec.rb')
458
+ end
459
+
460
+ #feels a little procedural doesn't it.
461
+ #executes all the methods above in the correct order.
462
+ def execute
463
+ add_gems
464
+ generate_devise_user
465
+ generate_user_configuration
466
+ check_for_oauth
467
+ confirmable
468
+ lockable
469
+ add_authentication_check_to_controllers
470
+ install_cancan
471
+ customize_registration_controller
472
+ customize_permission_denied_error
473
+ create_user_tool
474
+ create_roles_tool
475
+ create_tool_navigation
476
+ new_project
477
+ add_javascript
478
+ add_cucumber_tests
479
+ add_default_mailer_config
480
+ modify_css
481
+ add_rspec_tests
482
+ end
483
+
484
+ end