Class: Newsly::Mailer

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
app/mailers/newsly/mailer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.render_body(template_name, template_type, template_data = {}) ⇒ Object



27
28
29
30
# File 'app/mailers/newsly/mailer.rb', line 27

def self.render_body(template_name, template_type, template_data = {})
  tpl = Newsly::Template.where(:name => template_name.to_s, :template_type => template_type, :draft => false).first
  tpl.render(template_data)
end

Instance Method Details

#build_mail(template_id, to, template_data = {}, extra_headers = {}, layout = "newsly/mailer") ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/mailers/newsly/mailer.rb', line 15

def build_mail(template_id, to, template_data = {}, extra_headers = {}, layout = "newsly/mailer")
  headers = {}
  tmpl = Newsly::Template.find(template_id)
  headers[:to] = to
  headers[:subject] = tmpl.subject
  body = tmpl.render(template_data)
  headers = headers.merge(extra_headers)
  mail(headers) do |format|
    format.html { render :inline => body, :layout => layout }
  end
end

#build_newsletter(newsletter_id, to, template_data = {}, extra_headers = {}) ⇒ Object



7
8
9
10
11
12
13
# File 'app/mailers/newsly/mailer.rb', line 7

def build_newsletter(newsletter_id, to, template_data = {}, extra_headers = {})
	@newsletter = Newsly::Newsletter.find(newsletter_id)
   @template = Newsly::Template.where(:name => "newsletter", :draft => false).first
   @template_data = template_data.merge({"newsletter" => {"body" => @newsletter.render(template_data)}})
   @extra_headers = {:subject => "#{@newsletter.title}"}.merge(extra_headers)
   self.build_mail(@template.id, to, @template_data, @extra_headers)
end