Class: Effective::EmailTemplate

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActionView::Helpers::TextHelper
Defined in:
app/models/effective/email_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



7
8
9
# File 'app/models/effective/email_template.rb', line 7

def current_user
  @current_user
end

Instance Method Details

#body_plain?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/effective/email_template.rb', line 58

def body_plain?
  body.present? && !(body.include?('</p>') || body.include?('</div>'))
end

#content_typeObject



54
55
56
# File 'app/models/effective/email_template.rb', line 54

def content_type
  'text/html'
end

#render(assigns = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/effective/email_template.rb', line 62

def render(assigns = {})
  assigns = deep_stringify_assigns(assigns)

  {
    from: from,
    cc: cc.presence,
    bcc: bcc.presence,
    subject: template_subject.render(assigns),
    body: template_body.render(assigns)
  }.compact
end

#template_variablesObject



74
75
76
77
78
79
80
# File 'app/models/effective/email_template.rb', line 74

def template_variables
  [template_body.presence, template_subject.presence].compact.map do |template|
    Liquid::ParseTreeVisitor.for(template.root).add_callback_for(Liquid::VariableLookup) do |node|
      [node.name, *node.lookups].join('.')
    end.visit
  end.flatten.uniq.compact
end

#to_sObject



50
51
52
# File 'app/models/effective/email_template.rb', line 50

def to_s
  template_name.presence || 'New Email Template'
end