effective_email_templates 1.5.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1522926c50dd2f6874bc8cb41b906b4c8c2d31b8f0952ae1dc7482b647dc184c
4
- data.tar.gz: 3cab7ba180c3eadfeb74e6c6806ed24b46b74408073eb94f04598b23776bdfce
3
+ metadata.gz: 8d32e71af524fb3658debbf8210a4239b4bbd98f7a806f0a743735e62bc135dc
4
+ data.tar.gz: f6064f01a1a679b3c4bf1abca99222ab4ba191d4bb0ee16a1ac23ddad644c368
5
5
  SHA512:
6
- metadata.gz: 93d50932390ea0c38b202196451c58623f433a78d8d131b0568da75a1e44b0029653285934a1d311db7c7a658a2c78c969bbbabf78144e2335d4454ccd0fbfdb
7
- data.tar.gz: 9b5fe215d1dd3bb1f2e05d1a5417536eb4a38f3a29c0369e0346562347c308b88a21fe9d96a4c1e6f017d926b01429aed989e9e8f0310d7f4754b4ed7c152675
6
+ metadata.gz: 360328a697866d2d802d7c882bcfbd9c0be6e148c0b6d98114417088af72b9ea74cc935d275b6396a8be64becd88749536f491b1cfcb0f953e8ab1c739ba276e
7
+ data.tar.gz: 5cad8e018ad138e6050278c36e39a69a631a06773bc8d87aeee9986a96b56de9ab3f491198634eea514126f30241a0536b2b8ccceb9721f5e6a7da928e7f0b63
@@ -9,21 +9,40 @@ module EffectiveEmailTemplatesMailer
9
9
 
10
10
  assigns = (@assigns || {})
11
11
 
12
- # Parse assigns. Special keys for body and subject.
12
+ # Parse body content if given
13
13
  body = assigns.delete(:body) || headers[:body] || headers['body']
14
14
  email_template.body = body if body.present?
15
15
 
16
- # Ignore the subject when passed in via mail method subject: key.
17
- subject = assigns.delete(:subject)
16
+ # Parse subject content if explicitly given
17
+ # Otherwise the :subject key is a default and should be ignored in favor of the email template subject instead
18
+ subject = assigns.delete(:subject) || headers[:subject] || headers['subject']
18
19
  email_template.subject = subject if subject.present?
19
20
 
21
+ # If the body or subject are nil, they will be populated from the email_template
22
+
20
23
  # Add any _url helpers
21
24
  assigns = route_url_assigns(email_template, assigns).merge(assigns)
22
25
 
23
- # Render from the template, possibly with updated body
26
+ # Render from the template, possibly with updated body and subject
24
27
  rendered = email_template.render(assigns)
25
28
 
26
- super(rendered.merge(headers.except(:body, :subject, 'body', 'subject')))
29
+ # Merge any other passed values
30
+ merged = rendered.merge(headers.except(:body, :subject, 'body', 'subject'))
31
+
32
+ # Finalize the subject_for Proc
33
+ if respond_to?(:subject_for) # EffectiveResourcesMailer
34
+ if (prefix = EffectiveResources.mailer_subject_prefix_hint).present?
35
+ subject = subject_for(action_name, merged[:subject], email_template, merged)
36
+
37
+ if subject.start_with?("#{prefix}#{prefix}") || subject.start_with?("#{prefix} #{prefix}")
38
+ subject = subject.sub(prefix, '')
39
+ end
40
+
41
+ merged[:subject] = subject
42
+ end
43
+ end
44
+
45
+ super(merged)
27
46
  end
28
47
 
29
48
  private
@@ -23,6 +23,7 @@ module Effective
23
23
 
24
24
  before_validation do
25
25
  self.content_type ||= CONTENT_TYPES.first
26
+ self.from ||= EffectiveEmailTemplates.mailer_froms.first
26
27
  end
27
28
 
28
29
  validates :body, liquid: true
@@ -4,11 +4,15 @@
4
4
  - if EffectiveEmailTemplates.select_content_type
5
5
  = f.select :content_type, Effective::EmailTemplate::CONTENT_TYPES
6
6
 
7
- = f.select :from, EffectiveEmailTemplates.mailer_froms, hint: 'Please contact us to add additional sender addresses.'
7
+ = f.select :from, mailer_froms_collection(), hint: 'Please contact us to add additional sender addresses. Please refresh the page if this from address looks weird.'
8
8
  = f.text_field :cc
9
9
  = f.text_field :bcc
10
10
 
11
- = f.text_field :subject, hint: 'The subject of your email'
11
+ - prefix_hint = EffectiveResources.mailer_subject_prefix_hint.to_s.strip.presence
12
+
13
+ = f.text_field :subject,
14
+ hint: (prefix_hint ? "The subject of your email. It will be automatically prefixed with #{prefix_hint}." : 'The subject of your email')
15
+
12
16
  = f.text_area :body, hint: 'The content of your email template', rows: 10
13
17
 
14
18
  .card
@@ -1,3 +1,3 @@
1
1
  module EffectiveEmailTemplates
2
- VERSION = '1.5.1'.freeze
2
+ VERSION = '1.7.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_email_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-25 00:00:00.000000000 Z
11
+ date: 2023-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails