Skip to content

Commit

Permalink
#35 setup smtp, setup open_letter
Browse files Browse the repository at this point in the history
  • Loading branch information
Onur Özgür ÖZKAN committed May 20, 2013
1 parent 958bf5f commit f34206c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
59 changes: 59 additions & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,67 @@ def convert_application_css_to_sass
copy_file 'app/assets/stylesheets/application.css.sass', 'app/assets/stylesheets/application.css.sass'
end

# Interval: Configure smtp
def configure_smtp
copy_file 'config/initializers/mail.rb', 'config/initializers/mail.rb'

prepend_file 'config/environments/production.rb',
"require Rails.root.join('config/initializers/mail')\n"

config = <<-RUBY
# Mail Settings
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = MAIL_SETTING
RUBY

inject_into_file 'config/environments/production.rb', config,
:after => 'config.action_mailer.raise_delivery_errors = false'
end

# Interval: Configure action mailer
def configure_action_mailer
action_mailer_host 'development', "#{app_name}.dev"
action_mailer_host 'test', 'www.example.com'
action_mailer_host 'production', "#{app_name}.com"
end

# Interval: Setup letter opener
def setup_letter_opener
config = 'config.action_mailer.delivery_method = :letter_opener'
configure_environment 'development', config
end

# Internal: Leftovers
def leftovers
end

private

# Internal: Set action mailer hostname
#
# rail_env - rails env like development, text, production
# host - domain.dev, domain.com or example.com
#
# Returns nothing
def action_mailer_host(rails_env, host)
config = "config.action_mailer.default_url_options = { host: '#{host}' }"
configure_environment(rails_env, config)
end

# Internal: Set configure environment
#
# rail_env - rails env like development, text, production
# config - config string which will add to rails_env file
#
# Return nothing
def configure_environment(rails_env, config)
inject_into_file(
"config/environments/#{rails_env}.rb",
"\n\n #{config}",
before: "\nend"
)
end
end
end
8 changes: 8 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def customization
invoke :install_gems
invoke :gitignore_files_and_folders
invoke :setup_bootstrap_sass_coffee
invoke :configure_mail_setting
end

# Internal: Customize gemfile
Expand Down Expand Up @@ -86,6 +87,13 @@ def setup_bootstrap_sass_coffee
build :convert_application_css_to_sass
end

# Internal: Setup mail setting
def configure_mail_setting
build :configure_mail_setting
build :configure_action_mailer
build :setup_letter_opener
end


# Internal: Let's not: We'll bundle manually at the right spot.
def run_bundle
Expand Down
13 changes: 13 additions & 0 deletions templates/config/initializers/mail.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if Rails.env.production?
MAIL_SETTING = {
address: ENV['MAIL_ADDRESS'], # example 'smtp.mandrillapp.com'
port: '587',
enable_starttls_auto: true,
domain: ENV['MAIL_DOMAIN'], # example 'domain.com'
user_name: ENV['MAIL_USERNAME'], # example '[email protected]'
password: ENV['MAIL_PASSWORD'],
authentication: 'plain'
}
end


4 changes: 3 additions & 1 deletion templates/cybele_Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ gem 'responders'

group :doc do
gem 'sdoc', require: false
end
end

gem 'letter_opener', :group => :development

0 comments on commit f34206c

Please sign in to comment.