Associated templates
jodosha opened this issue · comments
Be able to include Lotus::Mailer
in Ruby objects.
When included, it exposes one class method .templates
.
It's a Hash
that holds the templates that the mailer will be able to render.
Location And Name
By convention, it should look for templates in the same directory. The name of those templates must be the "underscored" version of the class name.
Given a mailer named InvoiceMailer
, that lives in lib/bookshelf/mailers
, it must lookup for templates in that directory with a invoice_mailer.*.*
pattern.
Format
Once a matching template is found, it must be associated to .templates
.
The key of the hash is the format expressed as a Symbol, while the value is a template object.
This object must hold two references: the first is the absolute path of where the file is located, while the second value is the body of the file.
The format is the first extension for that file. For instance, if we have a template named invoice_mailer.html.erb
, the format will be :html
.
For a depth understanding of what we aim for, please have a look at http://lotusrb.org/guides/views/templates
The only difference with Lotus::View, is that we have multiple templates per class. This is useful to send multipart emails.
Laziness
The lookup of those templates must be lazy. It MUST be triggered by Lotus::Mailer.load!
.
Please have a look at Lotus::View.load!
.
Customization
A developer may want to customize the template for a given format.
They can use .template
followed by the format (which MUST be stored as a Symbol) and the path to the template. This path must be joined with the root defined by the configuration (#1).
class InvoiceMailer
include Lotus::Mailer
template :html, 'path/to/template'
end