Class: Waw::Tools::MailAgent::Template

Inherits:
Mail show all
Defined in:
lib/waw/tools/mail/template.rb

Overview

Allows creating WLang templates for mails easily

Instance Attribute Summary collapse

Attributes inherited from Mail

#bcc, #body, #cc, #charset, #content_type, #date, #from, #mime_version, #subject, #to

Instance Method Summary collapse

Methods inherited from Mail

decode, #dup, #initialize, #to_s

Constructor Details

This class inherits a constructor from Waw::Tools::MailAgent::Mail

Instance Attribute Details

#dialectObject

Returns the wlang dialect to use



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/waw/tools/mail/template.rb', line 11

def dialect
  return @dialect if @dialect
  case content_type
    when 'text/html'
      'wlang/xhtml'
    when 'text/plain'
      'wlang/active-string'
    else
      Waw.logger.warn("Unable to get wlang dialect from content-type #{content_type}")
      Waw.logger.warn("Using wlang/active-string by default")
  end
end

Instance Method Details

#instantiate(context = {}) ⇒ Object Also known as: to_mail

Instantiates this template using a given wlang context. The date of the resulting mail is set to Time.now



26
27
28
29
30
31
32
# File 'lib/waw/tools/mail/template.rb', line 26

def instantiate(context = {})
  mail, args = self.dup, context.unsymbolize_keys
  mail.subject = mail.subject.wlang(args, dialect)
  mail.body = mail.body.wlang(args, dialect)
  mail.date = Time.now
  mail
end