Class: Tricle::Mailer

Inherits:
ActionMailer::Base
  • Object
show all
Includes:
ActiveSupport::DescendantsTracker
Defined in:
lib/tricle/mailer.rb

Constant Summary collapse

CSS =
File.read(File.join(File.dirname(__FILE__), 'templates', 'email.css')).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.group(title) ⇒ Object



51
52
53
54
# File 'lib/tricle/mailer.rb', line 51

def group(title)
  self.report.add_group(title)
  yield if block_given?
end

.inherited(klass) ⇒ Object



46
47
48
49
# File 'lib/tricle/mailer.rb', line 46

def inherited(klass)
  klass.report = Tricle::Presenters::Report.new
  super(klass)
end

.list(klass, &block) ⇒ Object



60
61
62
# File 'lib/tricle/mailer.rb', line 60

def list(klass, &block)
  self.report.add_list(klass, &block)
end

.metric(klass) ⇒ Object



56
57
58
# File 'lib/tricle/mailer.rb', line 56

def metric(klass)
  self.report.add_metric(klass)
end

.send_allObject



64
65
66
67
68
69
70
71
72
# File 'lib/tricle/mailer.rb', line 64

def send_all
  mailers = Tricle::Mailer.descendants
  puts "Sending #{mailers.size} emails..."
  mailers.each do |klass|
    puts "Sending #{klass.name}..."
    klass.email.deliver
  end
  puts "Done."
end

Instance Method Details

#email(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tricle/mailer.rb', line 30

def email(options = {})
  options = {
    subject: self.subject
  }.merge(options)

  @report = self.report

  message = mail(options) do |format|
    format.html { render 'templates/email' }
    format.text { render 'templates/email' }
  end

  premailer(message)
end

#premailer(message) ⇒ Object



24
25
26
27
28
# File 'lib/tricle/mailer.rb', line 24

def premailer(message)
  # message.text_part.body = Premailer.new(message.text_part.body.to_s, with_html_string: true).to_plain_text
  message.html_part.body = Premailer.new(message.html_part.body.to_s, css_string: CSS.dup, with_html_string: true).to_inline_css
  message
end

#subjectObject



20
21
22
# File 'lib/tricle/mailer.rb', line 20

def subject
  "Your #{self.class.name.titleize}"
end