Module: ActsAsEmailNotification
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/acts_as_email_notification.rb
Overview
ActsAsEmailNotification Used for email notification resources that are initialized from an effective_email_template but save their own liquid template content. Effective::EventNotification, Effective::PollNotification, Effective::Notification
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary
collapse
Instance Method Details
#email_notification_body_html? ⇒ Boolean
90
91
92
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 90
def email_notification_body_html?
body.present? && (body.include?('</p>') || body.include?('</div>'))
end
|
#email_notification_body_plain? ⇒ Boolean
94
95
96
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 94
def email_notification_body_plain?
body.present? && !(body.include?('</p>') || body.include?('</div>'))
end
|
#email_notification_body_template ⇒ Object
98
99
100
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 98
def email_notification_body_template
Liquid::Template.parse(body) rescue nil
end
|
#email_notification_body_variables ⇒ Object
106
107
108
109
110
111
112
113
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 106
def email_notification_body_variables
template = email_notification_body_template()
return unless template.present?
Liquid::ParseTreeVisitor.for(template.root).add_callback_for(Liquid::VariableLookup) do |node|
[node.name, *node.lookups].join('.')
end.visit.flatten.uniq.compact
end
|
#email_notification_html? ⇒ Boolean
82
83
84
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 82
def email_notification_html?
content_type == 'text/html'
end
|
#email_notification_params ⇒ Object
78
79
80
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 78
def email_notification_params
{ from: from, cc: cc.presence, bcc: bcc.presence, subject: subject, body: body, content_type: content_type }
end
|
#email_notification_plain? ⇒ Boolean
86
87
88
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 86
def email_notification_plain?
content_type == 'text/plain'
end
|
#email_notification_subject_template ⇒ Object
102
103
104
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 102
def email_notification_subject_template
Liquid::Template.parse(subject) rescue nil
end
|
#email_notification_subject_variables ⇒ Object
115
116
117
118
119
120
121
122
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 115
def email_notification_subject_variables
template = email_notification_subject_template()
return unless template.present?
Liquid::ParseTreeVisitor.for(template.root).add_callback_for(Liquid::VariableLookup) do |node|
[node.name, *node.lookups].join('.')
end.visit.flatten.uniq.compact
end
|
#email_template ⇒ Object
70
71
72
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 70
def email_template
raise('to be implemented')
end
|
#email_template_variables ⇒ Object
74
75
76
|
# File 'app/models/concerns/acts_as_email_notification.rb', line 74
def email_template_variables
raise('to be implemented')
end
|