Class: Kowl::MailerGenerator

Inherits:
Generators::Base show all
Defined in:
lib/kowl/generators/mailer_generator.rb

Instance Method Summary collapse

Methods inherited from Generators::Base

default_source_root, source_paths

Methods included from Docker

#alpine_docker_dependencies, #app_js_volumes, #app_volumes, #db_volumes, #debian_database_dependencies, #debian_docker_dependencies, #docker_app_command, #docker_compose_database_string, #docker_databases, #docker_depends_on, #docker_port_watcher, #docker_redis_service, #docker_sidekiq_service, #docker_variables, #docker_volumes, #docker_webpacker_service, #dockerfile_database_args, #dockerfile_migration_snip, #js_volumes, #mysql_volumes, #postgresql_volumes, #redis_volumes

Methods included from Actions

#add_extension_routes, #add_package, #append_to_file, #database_route, #dev_config, #dup_file, #file_exists?, #mailer_gems, #mailer_route, #mk_dir, #move_file, #pry_gems, #rails_cmd, #remove_dir, #remove_file, #remove_gem, #replace_string_in_file, #robocop_test_engine, #sidekiq_route, #template_linter_gems

Instance Method Details

#add_mailer_assetsObject

Add the applications assets that need to be compiled for the mailer



31
32
33
34
# File 'lib/kowl/generators/mailer_generator.rb', line 31

def add_mailer_assets
  copy_file('app/assets/stylesheets/bootstrap/application-mailer.scss')
  add_to_assets('application-mailer.scss')
end

#copy_devise_mailer_configObject

Add a devise mailer layout the application if devise is to be used



26
27
28
# File 'lib/kowl/generators/mailer_generator.rb', line 26

def copy_devise_mailer_config
  copy_file('app/mailers/devise_mailer.rb', 'app/mailers/devise_mailer.rb') unless options[:noauth]
end

#copy_mailer_layoutsObject

Add DeviseMailer layout view, to cleanup devise emails



16
17
18
# File 'lib/kowl/generators/mailer_generator.rb', line 16

def copy_mailer_layouts
  copy_file('app/views/layouts/devise_mailer.html.erb', 'app/views/layouts/devise_mailer.html.erb') unless options[:noauth]
end

#override_application_mailerObject

Override the applications default application_mailer file with some basic config



21
22
23
# File 'lib/kowl/generators/mailer_generator.rb', line 21

def override_application_mailer
  copy_file 'app/mailers/application_mailer.rb', 'app/mailers/application_mailer.rb', force: true
end

#setup_letter_openerObject

Setup letter_opener config and initializer to catch emails in development



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kowl/generators/mailer_generator.rb', line 37

def setup_letter_opener
  smtp_config = <<~LETTER_OPENER
    # Specify if you you have a preference which method you want SMTP responses to be handled in dev
    # config.action_mailer.delivery_method = :letter_opener
    config.action_mailer.delivery_method = :letter_opener_web
    config.action_mailer.perform_deliveries = true
    config.action_mailer.raise_delivery_errors = false
  LETTER_OPENER
  dev_config(smtp_config)
  copy_file('config/initializers/letter_opener.rb', 'config/initializers/letter_opener.rb')
end

#setup_production_mailerObject

Setup a mailer initializer for production, based on the application config



50
51
52
53
54
55
56
# File 'lib/kowl/generators/mailer_generator.rb', line 50

def setup_production_mailer
  if options[:mailer] == 'postmark'
    copy_file('config/initializers/postmark.rb', 'config/initializers/postmark.rb', force: true)
  else
    copy_file('config/initializers/sparkpost.rb', 'config/initializers/sparkpost.rb', force: true)
  end
end