johnhenry 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 464844324b026f3ef2f5e69dea4a7b48418887f8
4
- data.tar.gz: 0b0f82a74cdf0bf55c7fa09a32426f324b4d45b4
3
+ metadata.gz: 92f77c92449e3fde78b20a4fd4f76ceef79120fc
4
+ data.tar.gz: 789c9bdb98150f1762652efec16f1ec1b2254c86
5
5
  SHA512:
6
- metadata.gz: 608d0963e5a3dc171b2d028aaa3831532358ed6f9a6635e791767dfd298cf77802d5195b32059f6623b8811097c5a92726a31a5f55886346776fb45b540bcf49
7
- data.tar.gz: 8b203d776895e9f51552084fbf5946877f02e5df4b1f074d4c4b8d46c5405659fb874dcc22afd5ec2442fc12559d18e6f12c7ede19fc2f8ca62d19b7b33da29b
6
+ metadata.gz: 44bd98b2a747e5ba526f8a54f5d232a7d428aad40f3fa6b864a36ceaabe12a20e070c08ab882ed9e39865b190d52c107eee0402146b215daa4d70e659a3c4506
7
+ data.tar.gz: 0359057958f604bab7dc8151b63755430ac1d61417b63c2ab3cf840564ba61cdda6442b1955f1ba5c6799b826013fb3227c2e614cd898600595b0a2ee8b8aaac
@@ -0,0 +1,14 @@
1
+ class UserMailer < ActionMailer::Base
2
+ default from: 'No Reply <no-reply@example.com>'
3
+ default bcc: ENV['BCC_EMAILS'] if ENV['BCC_EMAILS'].present?
4
+
5
+ def signup(user)
6
+ @user = user
7
+ @name = @user.email.split('@').first.try(:titleize)
8
+ subject = "Thanks for trying the JohnHenry Rails toolkit"
9
+ subject += ", #{ @name }" unless @name.blank?
10
+ Rails.logger.info "Sending signup notification to #{ user.email }"
11
+ mail to: user.email,
12
+ subject: subject
13
+ end
14
+ end
@@ -3,4 +3,11 @@ class User < ActiveRecord::Base
3
3
  # :confirmable, :lockable, :timeoutable and :omniauthable
4
4
  devise :database_authenticatable, :registerable,
5
5
  :recoverable, :rememberable, :trackable, :validatable
6
+ after_save :send_signup_email
7
+
8
+ private
9
+
10
+ def send_signup_email
11
+ UserMailer.signup(self).deliver
12
+ end
6
13
  end
@@ -0,0 +1,44 @@
1
+ - unless @name.blank?
2
+ Hi #{ @name },
3
+
4
+ %p
5
+ Thanks for trying the
6
+ %a{ href: 'http://www.johnhenryrails.com' } JohnHenry Rails
7
+ toolkit!
8
+
9
+ %p
10
+ This is the default user signup email that users will receive after
11
+ registering for an account. It's a great place for an onboarding email where
12
+ you introduce the new user to:
13
+
14
+ %ul
15
+ %li how they can access their profile
16
+ %li= link_to 'A password reset link', new_password_path(@user)
17
+ %li other helpful information.
18
+
19
+ %p
20
+ We've got a few reminders for you too, site admin:
21
+
22
+ %ul
23
+ %li
24
+ provision the SendGrid starter package to Heroku with:
25
+ %br
26
+ %code `heroku addons:add sendgrid:starter`
27
+ %br
28
+ %br
29
+ %li
30
+ set an environment variable of one or more recipients to be BCC'ed on every
31
+ email:
32
+ %br
33
+ %code `heroku config:set BCC_EMAILS='user@example.com[,user2@examples.com]'`
34
+ %br
35
+ %br
36
+ %li
37
+ on your development server, you can access the
38
+ %a{ href: 'http://localhost:3000/email_preview' } Email Preview
39
+ gem, which helps you build your emails quickly before you even send a test
40
+ message.
41
+
42
+ %p Finally, end with a thank you for trying your product.
43
+
44
+ %p <3
@@ -1,3 +1,4 @@
1
+
1
2
  # BEGIN autogenerated by JohnHenryRails
2
3
  gem 'haml-rails'
3
4
  gem 'devise'
@@ -1,3 +1,3 @@
1
1
  module JohnHenry
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  end
@@ -11,6 +11,8 @@ namespace :johnhenry do
11
11
  install_javascript
12
12
  install_stylesheets
13
13
  install_stripe
14
+ install_sendgrid
15
+ install_email_preview
14
16
 
15
17
  success_message
16
18
  end
@@ -44,69 +46,99 @@ namespace :johnhenry do
44
46
  end
45
47
  end
46
48
 
49
+ def create_file(blob_array, contents)
50
+ target = File.join(Rails.root, *blob_array)
51
+ Rails.logger.info "Creating #{ target }..."
52
+ File.open(target, 'w') { |f| f.write(contents) }
53
+ end
54
+
55
+ def insert_into_file_after(blob_array, line_no, lines)
56
+ target = File.join(Rails.root, *blob_array)
57
+ file_contents = File.readlines(target)
58
+ prepend = file_contents[0..(line_no-1)]
59
+ append = file_contents[line_no..-1]
60
+ contents = (prepend + lines + append)
61
+ Rails.logger.info "Inserting into #{ target } at line #{ line_no }..."
62
+ File.open(target, 'w') { |f| f.write contents.join }
63
+ end
64
+
47
65
  def update_gemfile
48
66
  source = File.join(johnhenry_root, *%w(lib Gemfile))
49
67
  target = File.join(Rails.root, *%w(Gemfile))
50
68
 
51
- gemfile_lines_to_insert = File.readlines(source)
69
+ Rails.logger.info "Removing sqlite3 and turbolinks from Gemfile..."
52
70
  gemfile_lines = File.readlines(target).reject do |line|
53
71
  line =~ /(sqlite3|turbolinks)/
54
72
  end
55
- gemfile = gemfile_lines[0..5] + gemfile_lines_to_insert + gemfile_lines[5..-1]
56
- Rails.logger.info "Inserting gems into Gemfile and removing turbolinks..."
57
- File.open(target, 'w') { |f| f.write gemfile.join("") }
73
+ File.open(target, 'w') { |f| f.write(gemfile_lines.join) }
74
+
75
+ insert_into_file_after(%w(Gemfile), 5, File.readlines(source))
58
76
  end
59
77
 
60
78
  def install_javascript
61
- source = File.join(Rails.root, *%w(app assets javascripts application.js))
62
- application_js = File.readlines(source)
63
- File.open(source, 'w') do |f|
64
- # replace turbolinks with johnhenry/application
65
- app = application_js[0..13] +
66
- ["//= require johnhenry/application\n"] +
67
- application_js[15..-1]
68
- Rails.logger.info "Adding dependencies to application.js..."
69
- f.write(app.join(""))
70
- end
79
+ code = ["//= require johnhenry/application\n"]
80
+ insert_into_file_after(%w(app assets javascripts application.js), 12, code)
71
81
  end
72
82
 
73
83
  def install_stylesheets
74
- source = File.join(Rails.root, *%w(app assets stylesheets application.css))
75
- application_css = File.readlines(source)
76
- File.open(source, 'w') do |f|
77
- app = application_css[0..11] +
78
- [" *= require johnhenry/application\n"] +
79
- application_css[12..-1]
80
- Rails.logger.info "Adding dependencies to application.css..."
81
- f.write(app.join(""))
82
- end
84
+ code = [" *= require johnhenry/application\n"]
85
+ insert_into_file_after(%w(app assets stylesheets application.css), 10, code)
83
86
  end
84
87
 
85
88
  def install_stripe
86
- target = File.join(Rails.root, *%w(config initializers stripe.rb))
87
- File.open(target, 'w') do |f|
88
- Rails.logger.info "Creating config/initializers/stripe.rb..."
89
- f.write("Stripe.api_key = ENV['STRIPE_SECRET_KEY']\n")
90
- f.write("STRIPE_PUBLISHABLE_KEY = ENV['STRIPE_PUBLISHABLE_KEY']\n")
91
- end
89
+ code = <<-EOS
90
+ Stripe.api_key = ENV['STRIPE_SECRET_KEY']
91
+ STRIPE_PUBLISHABLE_KEY = ENV['STRIPE_PUBLISHABLE_KEY']
92
+ EOS
93
+ create_file(%w(config initializers stripe.rb), code)
92
94
  end
93
95
 
94
- def update_routes
95
- source = File.join(Rails.root, *%w(config routes.rb))
96
- routes_rb = File.readlines(source)
97
- File.open(source, 'w') do |f|
98
- f.write(routes_rb[0])
99
- f.write(<<-EOS)
100
- root 'johnhenry/home#welcome'
101
- devise_for :users, controllers: {
102
- registrations: 'johnhenry/registrations',
103
- sessions: 'johnhenry/sessions'
96
+ def install_sendgrid
97
+ code = <<-EOS
98
+ ActionMailer::Base.smtp_settings = {
99
+ :address => 'smtp.sendgrid.net',
100
+ :port => '587',
101
+ :authentication => :plain,
102
+ :user_name => ENV['SENDGRID_USERNAME'],
103
+ :password => ENV['SENDGRID_PASSWORD'],
104
+ :domain => 'heroku.com',
105
+ :enable_starttls_auto => true
104
106
  }
105
- resources :payments, controller: 'johnhenry/payments'
106
- EOS
107
- Rails.logger.info "Injecting routes into config/routes.rb..."
108
- f.write(routes_rb[1..-1].join(''))
109
- end
107
+ EOS
108
+ target = File.join(Rails.root, *%w(config environment.rb))
109
+ Rails.logger.info "Creating config/environment.rb..."
110
+ File.open(target, 'a+') { |f| f.write(code) }
111
+
112
+ code = [" config.action_mailer.default_url_options = { host: 'localhost:3000' }"]
113
+ insert_into_file_after(%w(config environments development.rb), 26, code)
114
+
115
+ code = [" config.action_mailer.default_url_options = { host: 'www.johnhenryrails.com' }"]
116
+ insert_into_file_after(%w(config environments production.rb), 39, code)
117
+ end
118
+
119
+ def install_email_preview
120
+ code = <<-EOS
121
+ if Rails.env.development?
122
+ EmailPreview.register 'Signup' do
123
+ user = User.new email: 'johnny.cage@gmail.com'
124
+ UserMailer.signup(user)
125
+ end
126
+ end
127
+ EOS
128
+ create_file(%w(config initializers email_preview.rb), code)
129
+ end
130
+
131
+
132
+ def update_routes
133
+ code = <<-EOS
134
+ root 'johnhenry/home#welcome'
135
+ devise_for :users, controllers: {
136
+ registrations: 'johnhenry/registrations',
137
+ sessions: 'johnhenry/sessions'
138
+ }
139
+ resources :payments, controller: 'johnhenry/payments'
140
+ EOS
141
+ insert_into_file_after(%w(config routes.rb), 1, [code])
110
142
  end
111
143
 
112
144
  def success_message
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: johnhenry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Derewecki
@@ -184,6 +184,7 @@ files:
184
184
  - app/controllers/johnhenry/registrations_controller.rb
185
185
  - app/controllers/johnhenry/sessions_controller.rb
186
186
  - app/helpers/johnhenry/application_helper.rb
187
+ - app/mailers/user_mailer.rb
187
188
  - app/models/payment.rb
188
189
  - app/models/user.rb
189
190
  - app/views/johnhenry/devise/confirmations/new.html.haml
@@ -211,6 +212,7 @@ files:
211
212
  - app/views/johnhenry/shared/_signin_form.html.haml
212
213
  - app/views/johnhenry/shared/_signup_form.html.haml
213
214
  - app/views/layouts/johnhenry/application.html.haml
215
+ - app/views/user_mailer/signup.html.haml
214
216
  - config/initializers/devise.rb
215
217
  - config/routes.rb
216
218
  - db/development.sqlite3