Class: Xhive::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/xhive/mailer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, mailer, key = nil) ⇒ Mailer

Returns a new instance of Mailer.



5
6
7
8
9
10
11
12
13
# File 'lib/xhive/mailer.rb', line 5

def initialize(site, mailer, key = nil)
  @site = site
  @resource = mailer.class.name.underscore
  @mailer = mailer
  @action = mailer.action_name
  @key = key
  @vars = mailer_instance_variables(mailer)
  @page = Xhive::Mapper.page_for(@site, @resource, @action, @key, @vars)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/xhive/mailer.rb', line 3

def action
  @action
end

#contentObject (readonly)

Public: returns the email content body.

Returns: the rendered template or the mapped page content body.



40
41
42
# File 'lib/xhive/mailer.rb', line 40

def content
  @content
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/xhive/mailer.rb', line 3

def key
  @key
end

#mailerObject (readonly)

Returns the value of attribute mailer.



3
4
5
# File 'lib/xhive/mailer.rb', line 3

def mailer
  @mailer
end

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/xhive/mailer.rb', line 3

def page
  @page
end

#resourceObject (readonly)

Returns the value of attribute resource.



3
4
5
# File 'lib/xhive/mailer.rb', line 3

def resource
  @resource
end

#siteObject (readonly)

Returns the value of attribute site.



3
4
5
# File 'lib/xhive/mailer.rb', line 3

def site
  @site
end

#varsObject (readonly)

Returns the value of attribute vars.



3
4
5
# File 'lib/xhive/mailer.rb', line 3

def vars
  @vars
end

Instance Method Details

#send(opts = {}, &block) ⇒ Object

Public: sends the email to the specified recipients.

opts - The Hash containing the email sending options.

:from
:to
:reply_to
:subject (uses page title if mapper is found)

block - The block for customizing the email sending.



26
27
28
29
30
31
32
33
34
# File 'lib/xhive/mailer.rb', line 26

def send(opts = {}, &block)
  unless block_given?
    mailer.send(:mail, opts.merge(:subject => subject || opts[:subject])) do |format|
      format.html { mailer.render :text => content }
    end
  else
    yield content
  end
end

#subjectObject

Public: returns the email subject.

Returns: the rendered template or the mapped page content body.



49
50
51
# File 'lib/xhive/mailer.rb', line 49

def subject
  @subject = page.present? ? page.present_title(vars) : nil
end