Class: Crm::TemplateSet

Inherits:
Core::BasicResource show all
Includes:
Core::Mixins::ChangeLoggable, Core::Mixins::Inspectable
Defined in:
lib/crm/template_set.rb

Overview

TemplateSet represents the JustRelate WebCRM template set singleton. The templates of the template set singleton can be used to render customized text, e.g. a mailing greeting or a password request email body (password_request_email_body).

JustRelate WebCRM uses the / Liquid template engine for evaluating the templates.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::Mixins::Inspectable

#inspect

Methods included from Core::Mixins::ChangeLoggable

#changes

Methods inherited from Core::BasicResource

base_type, #eql?, #id, #path, #reload, resource_name, #type

Methods included from Core::Mixins::AttributeProvider

#[], #attributes, #initialize, #method_missing, #methods, #raw, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Crm::Core::Mixins::AttributeProvider

Class Method Details

.pathObject



13
14
15
# File 'lib/crm/template_set.rb', line 13

def self.path
  resource_name
end

.singletonTemplateSet

Returns the template set singleton.

Returns:



20
21
22
# File 'lib/crm/template_set.rb', line 20

def self.singleton
  new({}).reload
end

Instance Method Details

#render_preview(templates: {}, context: {}) ⇒ Hash{String => String}

Renders a preview of the template set using the specified context items. This is for testing your (future) templates.

  • All templates contained in the set are rendered.

  • You may temporally add any number of templates to the set (just for the purpose of rendering).

  • Pass as context items all the instances (e.g. contact, acticity) for which the templates should be rendered.

Templates have access to the context items. You can use the following keys to represent context items:

  • account

  • contact

  • activity

  • mailing

  • event

The keys expect an ID as input. For example, {"account" => "23"} allows the template to access account.name of the account with the ID 23.

Examples:

contact.first_name
# => 'Michael'

template_set.templates['digest_email_subject']
# => 'Summary for {{contact.first_name}}'

template_set.render_preview(
  templates: { greeting: 'Dear {{contact.first_name}}, {{foo}}' },
  context: {contact: contact.id, foo: 'welcome!'}
)
# => {
#  ...
#  'digest_email_subject' => 'Summary for Michael',
#  'greeting' => 'Dear Michael, welcome!',
#  ...
# }

Parameters:

  • templates (Hash{String => String}) (defaults to: {})

    the set of additional or temporary replacement templates to render.

  • context (Hash{String => String}) (defaults to: {})

    the context items of the preview.

Returns:

  • (Hash{String => String})

    the processed templates.



74
75
76
77
78
79
# File 'lib/crm/template_set.rb', line 74

def render_preview(templates: {}, context: {})
  Core::RestApi.instance.post("#{path}/render_preview", {
    'templates' => templates,
    'context' => context,
  })
end

#update(attributes) ⇒ self

Updates the attributes of this template set. See Modifiable#update for details.

Returns:

  • (self)

    the updated template set singleton.



28
29
30
31
# File 'lib/crm/template_set.rb', line 28

def update(attributes)
  load_attributes(
      Core::RestApi.instance.put(path, attributes, if_match_header))
end