Class: Webhookdb::Message::Template
- Inherits:
-
Object
- Object
- Webhookdb::Message::Template
- Defined in:
- lib/webhookdb/message/template.rb
Overview
Template is the base class for all message templates. Every message (email, and/or SMS, etc) has a Template that defines how to look up its text template and the dynamic data for rendering into the template. Subclasses should override methods to control the rendering behavior; see the method docs to see what is expected to be overridden.
Direct Known Subclasses
Webhookdb::Messages::ErrorGenericBackfill, Webhookdb::Messages::ErrorIcalendarFetch, Webhookdb::Messages::ErrorSignalwireSendSms, Webhookdb::Messages::Invite, Webhookdb::Messages::NewCustomer, Webhookdb::Messages::OrgDatabaseMigrationFinished, Webhookdb::Messages::OrgDatabaseMigrationStarted, Webhookdb::Messages::Testers::Base, Webhookdb::Messages::Verification
Class Method Summary collapse
-
.fixtured(_recipient) ⇒ Object
Override to return a new version of the template, with its data fixtured.
Instance Method Summary collapse
- #dispatch(to, transport: Webhookdb::Message::DEFAULT_TRANSPORT) ⇒ Object
- #dispatch_email(to) ⇒ Object
-
#extra_fields ⇒ Object
Return a hash of special fields for that this delivery should use.
- #full_template_name ⇒ Object
-
#layout ⇒ Object
The layout for the template.
- #layout_path(transport) ⇒ Object
-
#liquid_drops ⇒ Object
The hash that is used for the rendering of the template.
-
#liquify(o) ⇒ Object
Liquify wraps any object in a Liquification.
-
#template_folder ⇒ Object
The folder containing this template.
-
#template_name ⇒ Object
The name of the template.
- #template_path(transport) ⇒ Object
Class Method Details
.fixtured(_recipient) ⇒ Object
Override to return a new version of the template, with its data fixtured. It is used for message previewing. The argument is the message recipient, because they may need to be used to build resources off of.
Only needs to be overridden if the template constructor takes arguments. Assume that fixtures are loaded when this method is called; do not require them as part of your code.
20 21 22 |
# File 'lib/webhookdb/message/template.rb', line 20 def self.fixtured(_recipient) return self.new end |
Instance Method Details
#dispatch(to, transport: Webhookdb::Message::DEFAULT_TRANSPORT) ⇒ Object
24 25 26 |
# File 'lib/webhookdb/message/template.rb', line 24 def dispatch(to, transport: Webhookdb::Message::DEFAULT_TRANSPORT) return Webhookdb::Message.dispatch(self, to, transport) end |
#dispatch_email(to) ⇒ Object
28 29 30 |
# File 'lib/webhookdb/message/template.rb', line 28 def dispatch_email(to) return self.dispatch(to, transport: :email) end |
#extra_fields ⇒ Object
Return a hash of special fields for that this delivery should use. Necessary for deliveries that need to carry along some metadata. For example:
{'reply_to' => '[email protected]'}
for customers who send support requests. These fields are subject to flux and change and may only be applicable to some transports.
86 87 88 |
# File 'lib/webhookdb/message/template.rb', line 86 def extra_fields return {} end |
#full_template_name ⇒ Object
44 45 46 47 |
# File 'lib/webhookdb/message/template.rb', line 44 def full_template_name fld = self.template_folder.present? ? "#{self.template_folder}/" : "" return "#{fld}#{self.template_name}" end |
#layout ⇒ Object
The layout for the template. See the ‘layouts’ folder in the message data directory.
54 55 56 |
# File 'lib/webhookdb/message/template.rb', line 54 def layout return "standard" end |
#layout_path(transport) ⇒ Object
58 59 60 61 |
# File 'lib/webhookdb/message/template.rb', line 58 def layout_path(transport) return nil if self.layout.nil? return Webhookdb::Message::DATA_DIR + "layouts/#{self.layout}.#{transport}.liquid" end |
#liquid_drops ⇒ Object
The hash that is used for the rendering of the template. These must be simple types (strings, ints, bools, etc), or Liquid::Drop subclasses. By default, templates are rendered with some default variables, such as ‘recipient’, ‘environment’, and ‘app_url’.
67 68 69 70 71 72 73 74 |
# File 'lib/webhookdb/message/template.rb', line 67 def liquid_drops return { api_url: Webhookdb.api_url, support_email: Webhookdb.support_email, oss_repo: Webhookdb.oss_repo_url, docs_url: "https://docs.webhookdb.com", } end |
#liquify(o) ⇒ Object
Liquify wraps any object in a Liquification.
77 78 79 |
# File 'lib/webhookdb/message/template.rb', line 77 def liquify(o) return Webhookdb::Liquid::Liquification.new(o) end |
#template_folder ⇒ Object
The folder containing this template. Templates in the root template directory should use nil.
33 34 35 |
# File 'lib/webhookdb/message/template.rb', line 33 def template_folder return nil end |
#template_name ⇒ Object
The name of the template. By default, it is tied to the name of the class, so Messages::NewCustomer looks for ‘new_customer’ templates. However, a subclass can override this to not tie the template to the class name.
40 41 42 |
# File 'lib/webhookdb/message/template.rb', line 40 def template_name return self.class.name.demodulize.underscore end |