Skip to content

Commit

Permalink
Add a graphic template for emails and preview emails in local
Browse files Browse the repository at this point in the history
  • Loading branch information
FloMapo authored and fab-girard committed Aug 18, 2017
1 parent 28ea821 commit acc8d06
Show file tree
Hide file tree
Showing 16 changed files with 502 additions and 49 deletions.
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ group :development do
gem 'better_errors'
gem 'binding_of_caller'

# Preview emails
gem 'letter_opener_web'

if respond_to?(:install_if)
# Install only for ruby >=2.2
install_if lambda { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2') } do
Expand Down Expand Up @@ -167,6 +170,9 @@ gem 'nokogiri'
gem 'addressable'
gem 'icalendar'

# Format emails, nokogiri is required for premailer
gem 'premailer-rails'

gem 'chronic_duration'

group :production do
Expand Down
22 changes: 21 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ GEM
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.2)
css_parser (1.5.0)
addressable
daemons (1.2.4)
debug_inspector (0.0.3)
delayed_job (4.1.2)
Expand Down Expand Up @@ -302,6 +304,7 @@ GEM
hashie (3.5.5)
highline (1.7.8)
html_validation (1.1.3)
htmlentities (4.3.4)
http-cookie (1.0.3)
domain_name (~> 0.5)
http_accept_language (2.1.0)
Expand Down Expand Up @@ -341,6 +344,8 @@ GEM
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
json (1.8.6)
launchy (2.4.3)
addressable (~> 2.3)
leaflet-rails (1.0.3)
rails (>= 4.2.0)
less (2.6.0)
Expand All @@ -350,6 +355,12 @@ GEM
less (~> 2.6.0)
sprockets (> 2, < 4)
tilt
letter_opener (1.4.1)
launchy (~> 2.2)
letter_opener_web (1.3.1)
actionmailer (>= 3.2)
letter_opener (~> 1.0)
railties (>= 3.2)
libnotify (0.9.3)
ffi (>= 1.0.11)
libv8 (3.16.14.19)
Expand Down Expand Up @@ -406,6 +417,13 @@ GEM
polyglot (0.3.5)
polylines (0.3.0)
powerpack (0.1.1)
premailer (1.10.4)
addressable
css_parser (>= 1.4.10)
htmlentities (>= 4.0.0)
premailer-rails (1.9.7)
actionmailer (>= 3, < 6)
premailer (~> 1.7, >= 1.7.9)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand Down Expand Up @@ -685,6 +703,7 @@ DEPENDENCIES
leaflet-rails (> 1.0.2)
leaflet-responsive-popup-rails!
leaflet_numbered_markers-rails!
letter_opener_web
libnotify
lograge
macaddr
Expand All @@ -700,6 +719,7 @@ DEPENDENCIES
pg
pnotify-rails!
polylines
premailer-rails
pry-rails
rack-cors
rails (~> 4.2)
Expand Down Expand Up @@ -738,4 +758,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
1.15.1
1.15.3
Empty file removed app/assets/images/.keep
Empty file.
Binary file added app/assets/images/icon-facebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icon-linkedin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icon-twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/logo-mapotempo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file removed app/mailers/.keep
Empty file.
10 changes: 9 additions & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
class UserMailer < ApplicationMailer
def welcome_message(user, locale)
I18n.with_locale(locale) do
mail to: user.email, subject: t("user_mailer.welcome.title", s: user.customer.reseller.name) do |format|
@name = user.customer.reseller.name

@title = t('user_mailer.welcome.title')
@confirmation_link = user.customer.reseller.url_protocol + "://" + user.customer.reseller.host + password_user_path(user, token: user.confirmation_token)
@home_link = user.customer.reseller.url_protocol + "://" + user.customer.reseller.host
@contact_link = (user.customer.reseller.contact_url && user.customer.reseller.contact_url.gsub('{LG}', I18n.locale.to_s))
@subscription_duration = user.customer.end_subscription && (user.customer.end_subscription - Date.today).to_i > 1 ? (user.customer.end_subscription - Date.today).to_i : 15

mail to: user.email, subject: t('user_mailer.welcome.subject', name: @name) do |format|
format.html { render 'user_mailer/welcome', locals: { user: user } }
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ class User < ApplicationRecord

after_create :send_welcome_email, if: ->(user) { user.send_email.to_i == 1 }

def send_welcome_email
Mapotempo::Application.config.delayed_job_use ? UserMailer.delay.welcome_message(self, I18n.locale) : UserMailer.welcome_message(self, I18n.locale).deliver_now
self.update! confirmation_sent_at: Time.now
end

include RefSanitizer

include Confirmable
Expand Down Expand Up @@ -93,6 +88,11 @@ def api_key_random
self.api_key = SecureRandom.hex
end

def send_welcome_email
Mapotempo::Application.config.delayed_job_use ? UserMailer.delay.welcome_message(self, I18n.locale) : UserMailer.welcome_message(self, I18n.locale).deliver_now
self.update! confirmation_sent_at: Time.now
end

private

def set_default_time_zone
Expand Down
Loading

0 comments on commit acc8d06

Please sign in to comment.