mac_generators 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/lib/generators/authentication/email/USAGE +39 -0
  3. data/lib/generators/authentication/email/email_generator.rb +128 -0
  4. data/lib/generators/authentication/{templates → email/templates}/create_identities.rb +1 -1
  5. data/lib/generators/authentication/email/templates/database_authentication.rb +16 -0
  6. data/lib/generators/authentication/{templates → email/templates}/erb/identity_new.html.erb +0 -0
  7. data/lib/generators/authentication/email/templates/erb/session_new.html.erb +15 -0
  8. data/lib/generators/authentication/{templates → email/templates}/haml/identity_new.html.haml +0 -0
  9. data/lib/generators/authentication/email/templates/haml/session_new.html.haml +15 -0
  10. data/lib/generators/authentication/{templates → email/templates}/identities_controller.rb +1 -1
  11. data/lib/generators/authentication/email/templates/identity.rb +6 -0
  12. data/lib/generators/authentication/email/templates/sessions_controller.rb +16 -0
  13. data/lib/generators/authentication/email/templates/warden.rb +19 -0
  14. data/lib/generators/authentication/omniauth/USAGE +32 -0
  15. data/lib/generators/authentication/omniauth/omniauth_generator.rb +121 -0
  16. data/lib/generators/authentication/omniauth/templates/authentication_domain.rb +1 -0
  17. data/lib/generators/authentication/omniauth/templates/create_identities.rb +12 -0
  18. data/lib/generators/authentication/omniauth/templates/identity.rb +9 -0
  19. data/lib/generators/authentication/omniauth/templates/oauth_authentication.rb +36 -0
  20. data/lib/generators/authentication/omniauth/templates/omniauth.rb +3 -0
  21. data/lib/generators/authentication/omniauth/templates/sessions_controller.rb +12 -0
  22. data/lib/generators/authentication/omniauth/templates/warden.rb +19 -0
  23. data/lib/mac_generators/version.rb +1 -1
  24. data/test/dummy/app/controllers/application_controller.rb +24 -0
  25. data/test/dummy/config/database.yml +3 -3
  26. data/test/dummy/config/environments/test.rb +0 -3
  27. data/test/dummy/config/locales/en.yml +14 -0
  28. data/test/dummy/config/routes.rb +5 -0
  29. data/test/dummy/db/test.sqlite3 +0 -0
  30. data/test/dummy/log/test.log +3560 -0
  31. data/test/dummy/tmp/Gemfile +3 -0
  32. data/test/dummy/tmp/app/controllers/application_controller.rb +27 -0
  33. data/test/dummy/tmp/app/controllers/sessions_controller.rb +12 -0
  34. data/test/dummy/tmp/app/models/identity.rb +9 -0
  35. data/test/dummy/tmp/config/initializers/authentication_domain.rb +1 -0
  36. data/test/dummy/tmp/config/initializers/omniauth.rb +3 -0
  37. data/test/dummy/tmp/config/initializers/warden.rb +19 -0
  38. data/test/dummy/tmp/config/locales/en.yml +10 -0
  39. data/test/dummy/tmp/config/routes.rb +4 -0
  40. data/test/dummy/tmp/db/migrate/create_identities.rb +12 -0
  41. data/test/dummy/tmp/lib/strategies/oauth_authentication.rb +36 -0
  42. data/test/fixtures/Gemfile +0 -0
  43. data/test/fixtures/application_controller.rb +3 -0
  44. data/test/fixtures/en.yml +1 -0
  45. data/test/fixtures/routes.rb +2 -0
  46. data/test/generators/authentication_email_generator_test.rb +141 -0
  47. data/test/generators/authentication_omniauth_generator_test.rb +107 -0
  48. data/test/support/generators_test_helper.rb +51 -0
  49. data/test/test_helper.rb +20 -0
  50. metadata +115 -37
  51. data/README +0 -3
  52. data/lib/generators/authentication/USAGE +0 -8
  53. data/lib/generators/authentication/authentication_generator.rb +0 -89
  54. data/lib/generators/authentication/templates/erb/session_new.html.erb +0 -14
  55. data/lib/generators/authentication/templates/haml/session_new.html.haml +0 -14
  56. data/lib/generators/authentication/templates/identity.rb +0 -26
  57. data/lib/generators/authentication/templates/sessions_controller.rb +0 -21
  58. data/test/mac_generators_test.rb +0 -7
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mac_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mario A Chavez
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-20 00:00:00.000000000 Z
11
+ date: 2013-04-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,44 +20,94 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
26
  version: 4.0.0.beta
30
27
  - !ruby/object:Gem::Dependency
31
- name: sqlite3
28
+ name: minitest-rails
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
- description: Includes 2 generators, the first one is to create a Rails authentication.
47
- The second on is to add bootstrap to a rails application
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-focus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Includes 3 generators, the first two are to create a Rails authentication.
84
+ The last one is to add bootstrap to a rails application
48
85
  email: mario.chavez@gmail.com
49
86
  executables: []
50
87
  extensions: []
51
88
  extra_rdoc_files: []
52
89
  files:
53
- - lib/generators/authentication/authentication_generator.rb
54
- - lib/generators/authentication/templates/create_identities.rb
55
- - lib/generators/authentication/templates/erb/identity_new.html.erb
56
- - lib/generators/authentication/templates/erb/session_new.html.erb
57
- - lib/generators/authentication/templates/haml/identity_new.html.haml
58
- - lib/generators/authentication/templates/haml/session_new.html.haml
59
- - lib/generators/authentication/templates/identities_controller.rb
60
- - lib/generators/authentication/templates/identity.rb
61
- - lib/generators/authentication/templates/sessions_controller.rb
62
- - lib/generators/authentication/USAGE
90
+ - lib/generators/authentication/email/email_generator.rb
91
+ - lib/generators/authentication/email/templates/create_identities.rb
92
+ - lib/generators/authentication/email/templates/database_authentication.rb
93
+ - lib/generators/authentication/email/templates/erb/identity_new.html.erb
94
+ - lib/generators/authentication/email/templates/erb/session_new.html.erb
95
+ - lib/generators/authentication/email/templates/haml/identity_new.html.haml
96
+ - lib/generators/authentication/email/templates/haml/session_new.html.haml
97
+ - lib/generators/authentication/email/templates/identities_controller.rb
98
+ - lib/generators/authentication/email/templates/identity.rb
99
+ - lib/generators/authentication/email/templates/sessions_controller.rb
100
+ - lib/generators/authentication/email/templates/warden.rb
101
+ - lib/generators/authentication/email/USAGE
102
+ - lib/generators/authentication/omniauth/omniauth_generator.rb
103
+ - lib/generators/authentication/omniauth/templates/authentication_domain.rb
104
+ - lib/generators/authentication/omniauth/templates/create_identities.rb
105
+ - lib/generators/authentication/omniauth/templates/identity.rb
106
+ - lib/generators/authentication/omniauth/templates/oauth_authentication.rb
107
+ - lib/generators/authentication/omniauth/templates/omniauth.rb
108
+ - lib/generators/authentication/omniauth/templates/sessions_controller.rb
109
+ - lib/generators/authentication/omniauth/templates/warden.rb
110
+ - lib/generators/authentication/omniauth/USAGE
63
111
  - lib/generators/bootstrap/bootstrap_generator.rb
64
112
  - lib/generators/bootstrap/templates/_application.css.scss
65
113
  - lib/generators/bootstrap/templates/_variables.css.scss
@@ -73,7 +121,6 @@ files:
73
121
  - lib/tasks/mac_generators_tasks.rake
74
122
  - MIT-LICENSE
75
123
  - Rakefile
76
- - README
77
124
  - test/dummy/app/assets/javascripts/application.js
78
125
  - test/dummy/app/assets/stylesheets/application.css
79
126
  - test/dummy/app/controllers/application_controller.rb
@@ -97,7 +144,9 @@ files:
97
144
  - test/dummy/config/routes.rb
98
145
  - test/dummy/config.ru
99
146
  - test/dummy/db/development.sqlite3
147
+ - test/dummy/db/test.sqlite3
100
148
  - test/dummy/log/development.log
149
+ - test/dummy/log/test.log
101
150
  - test/dummy/public/404.html
102
151
  - test/dummy/public/422.html
103
152
  - test/dummy/public/500.html
@@ -105,37 +154,47 @@ files:
105
154
  - test/dummy/Rakefile
106
155
  - test/dummy/README.rdoc
107
156
  - test/dummy/script/rails
108
- - test/mac_generators_test.rb
157
+ - test/dummy/tmp/app/controllers/application_controller.rb
158
+ - test/dummy/tmp/app/controllers/sessions_controller.rb
159
+ - test/dummy/tmp/app/models/identity.rb
160
+ - test/dummy/tmp/config/initializers/authentication_domain.rb
161
+ - test/dummy/tmp/config/initializers/omniauth.rb
162
+ - test/dummy/tmp/config/initializers/warden.rb
163
+ - test/dummy/tmp/config/locales/en.yml
164
+ - test/dummy/tmp/config/routes.rb
165
+ - test/dummy/tmp/db/migrate/create_identities.rb
166
+ - test/dummy/tmp/Gemfile
167
+ - test/dummy/tmp/lib/strategies/oauth_authentication.rb
168
+ - test/fixtures/application_controller.rb
169
+ - test/fixtures/en.yml
170
+ - test/fixtures/Gemfile
171
+ - test/fixtures/routes.rb
172
+ - test/generators/authentication_email_generator_test.rb
173
+ - test/generators/authentication_omniauth_generator_test.rb
174
+ - test/support/generators_test_helper.rb
109
175
  - test/test_helper.rb
110
176
  homepage: http://mario-chavez.decisionesinteligentes.com
111
177
  licenses: []
178
+ metadata: {}
112
179
  post_install_message:
113
180
  rdoc_options: []
114
181
  require_paths:
115
182
  - lib
116
183
  required_ruby_version: !ruby/object:Gem::Requirement
117
- none: false
118
184
  requirements:
119
- - - ! '>='
185
+ - - '>='
120
186
  - !ruby/object:Gem::Version
121
187
  version: '0'
122
- segments:
123
- - 0
124
- hash: -303739505095055290
125
188
  required_rubygems_version: !ruby/object:Gem::Requirement
126
- none: false
127
189
  requirements:
128
- - - ! '>='
190
+ - - '>='
129
191
  - !ruby/object:Gem::Version
130
192
  version: '0'
131
- segments:
132
- - 0
133
- hash: -303739505095055290
134
193
  requirements: []
135
194
  rubyforge_project:
136
- rubygems_version: 1.8.24
195
+ rubygems_version: 2.0.3
137
196
  signing_key:
138
- specification_version: 3
197
+ specification_version: 4
139
198
  summary: Custom generators.
140
199
  test_files:
141
200
  - test/dummy/app/assets/javascripts/application.js
@@ -161,7 +220,9 @@ test_files:
161
220
  - test/dummy/config/routes.rb
162
221
  - test/dummy/config.ru
163
222
  - test/dummy/db/development.sqlite3
223
+ - test/dummy/db/test.sqlite3
164
224
  - test/dummy/log/development.log
225
+ - test/dummy/log/test.log
165
226
  - test/dummy/public/404.html
166
227
  - test/dummy/public/422.html
167
228
  - test/dummy/public/500.html
@@ -169,5 +230,22 @@ test_files:
169
230
  - test/dummy/Rakefile
170
231
  - test/dummy/README.rdoc
171
232
  - test/dummy/script/rails
172
- - test/mac_generators_test.rb
233
+ - test/dummy/tmp/app/controllers/application_controller.rb
234
+ - test/dummy/tmp/app/controllers/sessions_controller.rb
235
+ - test/dummy/tmp/app/models/identity.rb
236
+ - test/dummy/tmp/config/initializers/authentication_domain.rb
237
+ - test/dummy/tmp/config/initializers/omniauth.rb
238
+ - test/dummy/tmp/config/initializers/warden.rb
239
+ - test/dummy/tmp/config/locales/en.yml
240
+ - test/dummy/tmp/config/routes.rb
241
+ - test/dummy/tmp/db/migrate/create_identities.rb
242
+ - test/dummy/tmp/Gemfile
243
+ - test/dummy/tmp/lib/strategies/oauth_authentication.rb
244
+ - test/fixtures/application_controller.rb
245
+ - test/fixtures/en.yml
246
+ - test/fixtures/Gemfile
247
+ - test/fixtures/routes.rb
248
+ - test/generators/authentication_email_generator_test.rb
249
+ - test/generators/authentication_omniauth_generator_test.rb
250
+ - test/support/generators_test_helper.rb
173
251
  - test/test_helper.rb
data/README DELETED
@@ -1,3 +0,0 @@
1
- = MacGenerators
2
-
3
- This project rocks and uses MIT-LICENSE.
@@ -1,8 +0,0 @@
1
- Description:
2
- Will generate files for Rails authentication
3
-
4
- Example:
5
- rails generate authentication
6
-
7
- This will create:
8
- app/controllers/identity_controller.rb
@@ -1,89 +0,0 @@
1
- class AuthenticationGenerator < Rails::Generators::Base
2
-
3
- source_root File.expand_path('../templates', __FILE__)
4
- argument :resource_name, :type => :string, :default => 'identity'
5
- class_option :haml, type: :boolean, default: false, description: 'Generate haml templates'
6
-
7
- def copy_controller_files
8
- template 'identities_controller.rb', "app/controllers/#{resource_pluralize}_controller.rb"
9
- template 'sessions_controller.rb', 'app/controllers/sessions_controller.rb'
10
- end
11
-
12
- def copy_view_files
13
- puts ">>>#{options}"
14
- if options[:haml]
15
- template 'haml/identity_new.html.haml', "app/views/#{resource_pluralize}/new.html.haml"
16
- template 'haml/session_new.html.haml', "app/views/sessions/new.html.haml"
17
- else
18
- template 'erb/identity_new.html.erb', "app/views/#{resource_pluralize}/new.html.erb"
19
- template 'erb/session_new.html.erb', "app/views/sessions/new.html.erb"
20
- end
21
- end
22
-
23
- def add_routes
24
- route "get 'sign_up' => '#{resource_pluralize}#new', as: :sign_up"
25
- route "get 'log_in' => 'sessions#new', as: :log_in"
26
- route "get 'log_out' => 'sessions#destroy', as: :log_out"
27
-
28
- route "resource :#{resource_name}, only: [:create, :new]"
29
- route "resource :sessions, only: [:create, :new]"
30
- end
31
-
32
- def generate_user
33
- if Dir["db/migrate/*create_#{resource_pluralize}.rb"].empty?
34
- template 'create_identities.rb', "db/migrate/#{migration_name}"
35
- end
36
- template 'identity.rb', "app/models/#{resource_name}.rb"
37
- end
38
-
39
- def add_helper_methods
40
- insert_into_file 'app/controllers/application_controller.rb', after: /:exception/ do
41
- <<-EOS
42
-
43
-
44
- helper_method :current_#{resource_name}
45
-
46
- private
47
- def current_#{resource_name}
48
- @current_#{resource_name} ||= #{resource_name.classify}.find(session[:#{resource_name}_id]) if session[:#{resource_name}_id]
49
- end
50
- EOS
51
- end
52
-
53
- end
54
-
55
- def add_gems
56
- gem 'bcrypt-ruby', require: 'bcrypt'
57
- end
58
-
59
- def add_translations
60
- insert_into_file "config/locales/#{I18n.default_locale.to_s}.yml", after: 'en:' do
61
- <<-EOS
62
-
63
- sessions:
64
- new:
65
- log_in: 'Log in'
66
- create:
67
- invalid_credentials: 'Your credentials are invalid'
68
- logged_in: 'Welcome back!'
69
- destroy:
70
- logged_out: 'See you later!'
71
- #{resource_pluralize}:
72
- new:
73
- create: 'Create #{resource_name}'
74
- create:
75
- sign_up: 'Welcome to your new account!'
76
- EOS
77
- end
78
- end
79
-
80
- private
81
- def resource_pluralize
82
- @resource_pluralize ||= resource_name.pluralize
83
- end
84
-
85
- def migration_name
86
- date = (DateTime.now.strftime "%Y %m %d %H %M %S").gsub(' ', '')
87
- "#{date}_create_#{resource_pluralize}.rb"
88
- end
89
- end
@@ -1,14 +0,0 @@
1
- <%%- if flash.alert %>
2
- <div class='alert'><%%= flash.alert %></div>
3
- <%% end %>
4
- <%%= form_tag sessions_path do %>
5
- <p>
6
- <%%= label_tag :email %><br />
7
- <%%= text_field_tag :email, params[:email] %>
8
- </p>
9
- <p>
10
- <%%= label_tag :password %><br />
11
- <%%= password_field_tag :password, params[:password] %>
12
- </p>
13
- <p class='button'><%%= submit_tag t('.log_in') %></p>
14
- <%% end %>
@@ -1,14 +0,0 @@
1
- - if flash.alert
2
- .alert
3
- = flash.alert
4
- = form_tag sessions_path do
5
- %p
6
- = label_tag :email
7
- %br/
8
- = text_field_tag :email, params[:email]
9
- %p
10
- = label_tag :password
11
- %br/
12
- = password_field_tag :password, params[:password]
13
- %p.button
14
- = submit_tag t('.log_in')
@@ -1,26 +0,0 @@
1
- class <%= resource_name.classify %> < ActiveRecord::Base
2
- attr_accessor :password
3
- before_save :encrypt_password
4
-
5
- validates_confirmation_of :password
6
- validates_presence_of :password, :on => :create
7
- validates_presence_of :email
8
- validates_uniqueness_of :email
9
-
10
- def encrypt_password
11
- if password.present?
12
- self.password_salt = BCrypt::Engine.generate_salt
13
- self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
14
- end
15
- end
16
-
17
- def self.authenticate(email, password)
18
- <%= resource_name %> = where(email: email).first
19
-
20
- if <%= resource_name %> && <%= resource_name %>.password_hash == BCrypt::Engine.hash_secret(password, <%= resource_name %>.password_salt)
21
- <%= resource_name %>
22
- else
23
- nil
24
- end
25
- end
26
- end
@@ -1,21 +0,0 @@
1
- class SessionsController < ApplicationController
2
- def new
3
- end
4
-
5
- def create
6
- <%= resource_name %> = <%= resource_name.classify %>.authenticate params[:email], params[:password]
7
-
8
- if <%= resource_name %>
9
- session[:<%=resource_name %>_id] = <%= resource_name %>.id
10
- return redirect_to root_url, notice: t('.logged_in')
11
- end
12
- flash.now.alert = t('.invalid_credentials')
13
- render :new
14
- end
15
-
16
- def destroy
17
- session[:<%=resource_name %>_id] = nil
18
- redirect_to root_url, notice: t('.logged_out')
19
- end
20
- end
21
-
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MacGeneratorsTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, MacGenerators
6
- end
7
- end