Class: Effective::EmailTemplate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::EmailTemplate
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- app/models/effective/email_template.rb
Constant Summary collapse
- LIQUID_TAG =
/\{\{.*?\}\}|\{%.*?%\}/m- NBSP =
/\u00A0| /
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
Instance Method Summary collapse
- #body_plain? ⇒ Boolean
- #content_type ⇒ Object
- #render(assigns = {}) ⇒ Object
-
#strip_liquid_nbsp(value) ⇒ Object
Replace non-breaking spaces with regular spaces, but only INSIDE Liquid tags (where they break parsing).
- #template_variables ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#current_user ⇒ Object
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
68 69 70 |
# File 'app/models/effective/email_template.rb', line 68 def body_plain? body.present? && !(body.include?('</p>') || body.include?('</div>')) end |
#content_type ⇒ Object
64 65 66 |
# File 'app/models/effective/email_template.rb', line 64 def content_type 'text/html' end |
#render(assigns = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/effective/email_template.rb', line 82 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 |
#strip_liquid_nbsp(value) ⇒ Object
Replace non-breaking spaces with regular spaces, but only INSIDE Liquid tags (where they break parsing). Intentional elsewhere in the template's HTML is left untouched.
77 78 79 80 |
# File 'app/models/effective/email_template.rb', line 77 def strip_liquid_nbsp(value) return value if value.blank? value.gsub(LIQUID_TAG) { |tag| tag.gsub(NBSP, ' ') } end |
#template_variables ⇒ Object
94 95 96 97 98 99 100 |
# File 'app/models/effective/email_template.rb', line 94 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
60 61 62 |
# File 'app/models/effective/email_template.rb', line 60 def to_s template_name.presence || 'New Email Template' end |