Class: Effective::EmailTemplate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::EmailTemplate
- Defined in:
- app/models/effective/email_template.rb
Constant Summary collapse
- CONTENT_TYPES =
['text/plain', 'text/html']
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
Instance Method Summary collapse
- #render(assigns = {}) ⇒ Object
- #template_variables ⇒ Object
-
#to_s ⇒ Object
validate(if: -> { content_type == ‘text/plain’ && body.present? }) do if body.include?(‘</a>’) || body.include?(‘</p>’) self.errors.add(:content_type, ‘expected no html tags in body’) self.errors.add(:body, ‘expected no html tags in body’) end end.
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
5 6 7 |
# File 'app/models/effective/email_template.rb', line 5 def current_user @current_user end |
Instance Method Details
#render(assigns = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/effective/email_template.rb', line 55 def render(assigns = {}) assigns = deep_stringify_assigns(assigns) result = { from: from, cc: cc.presence, bcc: bcc.presence, content_type: content_type, subject: template_subject.render(assigns), body: template_body.render(assigns) }.compact end |
#template_variables ⇒ Object
68 69 70 71 72 73 74 |
# File 'app/models/effective/email_template.rb', line 68 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_s ⇒ Object
validate(if: -> { content_type == ‘text/plain’ && body.present? }) do
if body.include?('</a>') || body.include?('</p>')
self.errors.add(:content_type, 'expected no html tags in body')
self.errors.add(:body, 'expected no html tags in body')
end
end
51 52 53 |
# File 'app/models/effective/email_template.rb', line 51 def to_s template_name.presence || 'New Email Template' end |