Class: Xhive::Mailer
- Inherits:
-
Object
- Object
- Xhive::Mailer
- Defined in:
- lib/xhive/mailer.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#content ⇒ Object
readonly
Public: returns the email content body.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#mailer ⇒ Object
readonly
Returns the value of attribute mailer.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
-
#initialize(site, mailer, key = nil) ⇒ Mailer
constructor
A new instance of Mailer.
-
#send(opts = {}, &block) ⇒ Object
Public: sends the email to the specified recipients.
-
#subject ⇒ Object
Public: returns the email subject.
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/xhive/mailer.rb', line 3 def action @action end |
#content ⇒ Object (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 |
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/xhive/mailer.rb', line 3 def key @key end |
#mailer ⇒ Object (readonly)
Returns the value of attribute mailer.
3 4 5 |
# File 'lib/xhive/mailer.rb', line 3 def mailer @mailer end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
3 4 5 |
# File 'lib/xhive/mailer.rb', line 3 def page @page end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
3 4 5 |
# File 'lib/xhive/mailer.rb', line 3 def resource @resource end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
3 4 5 |
# File 'lib/xhive/mailer.rb', line 3 def site @site end |
#vars ⇒ Object (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 |
#subject ⇒ Object
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 |