Skip to content

Commit f34206c

Browse files
author
Onur Özgür ÖZKAN
committed
#35 setup smtp, setup open_letter
1 parent 958bf5f commit f34206c

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

lib/cybele/app_builder.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,67 @@ def convert_application_css_to_sass
105105
copy_file 'app/assets/stylesheets/application.css.sass', 'app/assets/stylesheets/application.css.sass'
106106
end
107107

108+
# Interval: Configure smtp
109+
def configure_smtp
110+
copy_file 'config/initializers/mail.rb', 'config/initializers/mail.rb'
111+
112+
prepend_file 'config/environments/production.rb',
113+
"require Rails.root.join('config/initializers/mail')\n"
114+
115+
config = <<-RUBY
116+
117+
118+
# Mail Settings
119+
config.action_mailer.delivery_method = :smtp
120+
config.action_mailer.smtp_settings = MAIL_SETTING
121+
RUBY
122+
123+
inject_into_file 'config/environments/production.rb', config,
124+
:after => 'config.action_mailer.raise_delivery_errors = false'
125+
end
126+
127+
# Interval: Configure action mailer
128+
def configure_action_mailer
129+
action_mailer_host 'development', "#{app_name}.dev"
130+
action_mailer_host 'test', 'www.example.com'
131+
action_mailer_host 'production', "#{app_name}.com"
132+
end
133+
134+
# Interval: Setup letter opener
135+
def setup_letter_opener
136+
config = 'config.action_mailer.delivery_method = :letter_opener'
137+
configure_environment 'development', config
138+
end
139+
108140
# Internal: Leftovers
109141
def leftovers
110142
end
143+
144+
private
145+
146+
# Internal: Set action mailer hostname
147+
#
148+
# rail_env - rails env like development, text, production
149+
# host - domain.dev, domain.com or example.com
150+
#
151+
# Returns nothing
152+
def action_mailer_host(rails_env, host)
153+
config = "config.action_mailer.default_url_options = { host: '#{host}' }"
154+
configure_environment(rails_env, config)
155+
end
156+
157+
# Internal: Set configure environment
158+
#
159+
# rail_env - rails env like development, text, production
160+
# config - config string which will add to rails_env file
161+
#
162+
# Return nothing
163+
def configure_environment(rails_env, config)
164+
inject_into_file(
165+
"config/environments/#{rails_env}.rb",
166+
"\n\n #{config}",
167+
before: "\nend"
168+
)
169+
end
111170
end
112171
end

lib/cybele/generators/app_generator.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def customization
3131
invoke :install_gems
3232
invoke :gitignore_files_and_folders
3333
invoke :setup_bootstrap_sass_coffee
34+
invoke :configure_mail_setting
3435
end
3536

3637
# Internal: Customize gemfile
@@ -86,6 +87,13 @@ def setup_bootstrap_sass_coffee
8687
build :convert_application_css_to_sass
8788
end
8889

90+
# Internal: Setup mail setting
91+
def configure_mail_setting
92+
build :configure_mail_setting
93+
build :configure_action_mailer
94+
build :setup_letter_opener
95+
end
96+
8997

9098
# Internal: Let's not: We'll bundle manually at the right spot.
9199
def run_bundle

templates/config/initializers/mail.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
if Rails.env.production?
2+
MAIL_SETTING = {
3+
address: ENV['MAIL_ADDRESS'], # example 'smtp.mandrillapp.com'
4+
port: '587',
5+
enable_starttls_auto: true,
6+
domain: ENV['MAIL_DOMAIN'], # example 'domain.com'
7+
user_name: ENV['MAIL_USERNAME'], # example '[email protected]'
8+
password: ENV['MAIL_PASSWORD'],
9+
authentication: 'plain'
10+
}
11+
end
12+
13+

templates/cybele_Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ gem 'responders'
1414

1515
group :doc do
1616
gem 'sdoc', require: false
17-
end
17+
end
18+
19+
gem 'letter_opener', :group => :development

0 commit comments

Comments
 (0)