Module: CustomEmails::Templatable::ClassMethods

Defined in:
lib/custom_emails/templatable.rb

Instance Method Summary collapse

Instance Method Details

#interpolate(content, context) ⇒ Object

Use liquid to get the result of template interpretation.

Parameters:

  • the (String)

    template

  • the (Hash)

    variable tree that have to be inserted into the template



24
25
26
27
28
29
30
31
# File 'lib/custom_emails/templatable.rb', line 24

def interpolate(content, context)
  template = ::Liquid::Template.parse(content)
  if template.errors.empty?
    template.render(context)
  else
    content
  end
end

#valid_template?(content) ⇒ Boolean

Checks if a content is valid for interpolation.

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/custom_emails/templatable.rb', line 12

def valid_template?(content)
  return true if content.blank?

  template = ::Liquid::Template.parse(content)
  template.errors.empty?
end