From 362292716fadd58f186211429c8970734d6c923b Mon Sep 17 00:00:00 2001 From: Yuki Date: Tue, 21 Jul 2015 23:43:14 +0530 Subject: [PATCH] Mail templating, hopefully --- app/mailers/retromail.rb | 19 +++++++++++++++++++ .../confirmation_instructions.html.haml | 2 +- .../mailer/confirmation_instructions.txt.erb | 6 ++++++ app/views/layouts/mail.html.haml | 5 +++++ app/views/layouts/mail.txt.erb | 3 +++ config/initializers/devise.rb | 2 +- 6 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 app/mailers/retromail.rb create mode 100644 app/views/devise/mailer/confirmation_instructions.txt.erb create mode 100644 app/views/layouts/mail.html.haml create mode 100644 app/views/layouts/mail.txt.erb diff --git a/app/mailers/retromail.rb b/app/mailers/retromail.rb new file mode 100644 index 00000000..8dc1c04f --- /dev/null +++ b/app/mailers/retromail.rb @@ -0,0 +1,19 @@ +class Retromail < Devise::Mailer + helper :application + include Devise::Controllers::UrlHelpers + default template_path: 'devise/mailer', parts_order: [ 'text/plain', 'text/html' ] + layout 'mail' + + def devise_mail(record, action, opts={}) + initialize_from_record(record) + mail(headers_for(action, opts)) do |format| + format.txt + format.html + end + end + + def confirmation_instructions(record, token, opts={}) + @token = token + devise_mail(record, :confirmation_instructions, opts) + end +end diff --git a/app/views/devise/mailer/confirmation_instructions.html.haml b/app/views/devise/mailer/confirmation_instructions.html.haml index abd20771..00035a8f 100644 --- a/app/views/devise/mailer/confirmation_instructions.html.haml +++ b/app/views/devise/mailer/confirmation_instructions.html.haml @@ -5,4 +5,4 @@ = succeed '!' do = @resource.screen_name %p You can confirm your account email through the link below: -%p= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token, protocol: (APP_CONFIG['https'] ? :https : :http)) \ No newline at end of file +%p= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token, protocol: (APP_CONFIG['https'] ? :https : :http)) diff --git a/app/views/devise/mailer/confirmation_instructions.txt.erb b/app/views/devise/mailer/confirmation_instructions.txt.erb new file mode 100644 index 00000000..3f7e2181 --- /dev/null +++ b/app/views/devise/mailer/confirmation_instructions.txt.erb @@ -0,0 +1,6 @@ +Welcome to <%= APP_CONFIG['site_name'] %>, <%= @resource.screen_name %>! + +You can confirm your account email by copying link below, +and entering it into your browser. + +<%= confirmation_url(@resource, confirmation_token: @token, protocol: (APP_CONFIG['https'] ? :https : :http)) %> diff --git a/app/views/layouts/mail.html.haml b/app/views/layouts/mail.html.haml new file mode 100644 index 00000000..5d987e18 --- /dev/null +++ b/app/views/layouts/mail.html.haml @@ -0,0 +1,5 @@ +%style{type: "text/css"} p{margin:0;padding:0;}*,div,small,span,body{font-family:Arial;} +%div{style: 'background: #5e35b1; padding: 5px; padding-left: 10px; font-size: 25px; color: white; font-family: Arial; width: 800px; margin: 0;'}= APP_CONFIG['site_name'] +%div{style: 'border: #5e35b1 5px solid; padding: 5px; border-top: none; background: white; color: black; font-family: Arial; width: 795px; margin: 0;'} + = yield +%small{style: 'color: grey; display: block; width: 800px; text-align: center;'} © 2015 Retrospring diff --git a/app/views/layouts/mail.txt.erb b/app/views/layouts/mail.txt.erb new file mode 100644 index 00000000..d955dba9 --- /dev/null +++ b/app/views/layouts/mail.txt.erb @@ -0,0 +1,3 @@ +<%= yield %> + +© 2015 Retrospring diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index fc6c699c..e7731fc3 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -13,7 +13,7 @@ Devise.setup do |config| config.mailer_sender = "#{APP_CONFIG['site_name']} <#{APP_CONFIG['email_from']}>" # Configure the class responsible to send e-mails. - # config.mailer = 'Devise::Mailer' + config.mailer = 'Retromail' # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and