Class: Effective::EmailTemplate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::EmailTemplate
- Defined in:
- app/models/effective/email_template.rb
Constant Summary collapse
- CONTENT_TYPE_PLAIN =
'text/plain'- CONTENT_TYPE_HTML =
'text/html'- CONTENT_TYPES =
[CONTENT_TYPE_PLAIN, CONTENT_TYPE_HTML]
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
Instance Method Summary collapse
- #html? ⇒ Boolean
- #plain? ⇒ Boolean
- #render(assigns = {}) ⇒ Object
- #template_variables ⇒ Object
- #to_s ⇒ Object
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
#html? ⇒ Boolean
52 53 54 |
# File 'app/models/effective/email_template.rb', line 52 def html? content_type == CONTENT_TYPE_HTML end |
#plain? ⇒ Boolean
56 57 58 |
# File 'app/models/effective/email_template.rb', line 56 def plain? content_type == CONTENT_TYPE_PLAIN end |
#render(assigns = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/effective/email_template.rb', line 60 def render(assigns = {}) assigns = deep_stringify_assigns(assigns) { 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
73 74 75 76 77 78 79 |
# File 'app/models/effective/email_template.rb', line 73 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
48 49 50 |
# File 'app/models/effective/email_template.rb', line 48 def to_s template_name.presence || 'New Email Template' end |