class Lux::Mailer

Rails mode via method missing is suported Mailer.email_login('foo@bar.baz').deliver Mailer.email_login('foo@bar.baz').body

Attributes

mail[R]

Public Class Methods

deliver() click to toggle source
# File lib/lux/mailer/mailer.rb, line 41
def deliver
  send(method_name, *args).deliver
end
method_missing(method_sym, *args) click to toggle source
# File lib/lux/mailer/mailer.rb, line 37
def method_missing method_sym, *args
  prepare(method_sym, *args)
end
new() click to toggle source
# File lib/lux/mailer/mailer.rb, line 48
def initialize
  @mail = FreeStruct.new subject: nil, body: nil, to: nil, cc: nil, from: nil
end
prepare(template, *args) click to toggle source

Mailer.prepare(:email_login, 'foo@bar.baz')

# File lib/lux/mailer/mailer.rb, line 24
def prepare template, *args
  obj = new
  obj.instance_variable_set :@_template, template
  Object.class_callback :before, obj
  obj.send template, *args
  Object.class_callback :after, obj
  obj
end
render(method_name, *args) click to toggle source
# File lib/lux/mailer/mailer.rb, line 33
def render method_name, *args
  send(method_name, *args).body
end

Public Instance Methods

body() click to toggle source
# File lib/lux/mailer/mailer.rb, line 69
def body
  data = @mail.body

  unless data
    helper = Lux::View::Helper.new self, self.class.helper
    data = Lux::View.render_with_layout "layouts/#{self.class.layout}", "mailer/#{@_template}", helper
  end

  data.gsub(%r{\shref=(['"])/}) { %[ href=#{$1}#{Lux.config.host}/] }
end
deliver() click to toggle source
# File lib/lux/mailer/mailer.rb, line 52
def deliver
  raise "From in mailer not defined"    unless @mail.from
  raise "To in mailer not defined"      unless @mail.to
  raise "Subject in mailer not defined" unless @mail.subject

  m = Mail.new
  m[:from]         = @mail.from
  m[:to]           = @mail.to
  m[:subject]      = @mail.subject
  m[:body]         = body
  m[:content_type] = 'text/html; charset=UTF-8'

  Lux.delay { m.deliver! }

  instance_exec m, &Lux.config.on_mail
end
subject() click to toggle source
# File lib/lux/mailer/mailer.rb, line 80
def subject
  @mail.subject
end
to() click to toggle source
# File lib/lux/mailer/mailer.rb, line 84
def to
  @mail.to
end