effective_resources 2.13.0 → 2.15.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: 9f4283f3c4e59e72313277c4e8a132c9bcb35fb9250fbd140733c53c2e74d18b
4
- data.tar.gz: ec11d262fa2bb76d6cea5e31b9445da37fc1c89d4721c89465d07b2bef9ef6bc
3
+ metadata.gz: fd61b5df998f90f23f8564279a7dc20840cf169c5114b026ff7cadef9978f00f
4
+ data.tar.gz: 1106d08aabdc5053db5fb6e78db263be7157b477b78dc6162f7edc8feef10ede
5
5
  SHA512:
6
- metadata.gz: fce12caba2beddbabbd580ddfc9a75e1bc0e0b3827a1bba509141764856953df8015e44f489e872d5cb2cde6b093d527e9823be0d273b984c771a443d8211ee6
7
- data.tar.gz: ec4a712e9c30fd1ba87c019b8bf98861cdcddb236e8b0872f45f83fa6ea3b01102fdc2030a0d3a92cc2cace7829b0123f6dd042042dd6da08c7b9e6d81597bcf
6
+ metadata.gz: 8815dfa572def42ccad3f5731af8fffe847992a997568a2fd867a4b1586ec51716bfd368d42df15f5578fa2a3759ada115e09243ee225314aa7b3d1f30e14412
7
+ data.tar.gz: 1abf591d59b8a0ec96bfe05f8a2d0e6776389b7016a47ae72bc0bf010a70f33c8f7719a4b4e0424c55b0869c6eb3afc9ce9f82984ce7769800b637c4c0c992cd
@@ -13,25 +13,15 @@ module EffectiveActsAsEmailFormHelper
13
13
  action.kind_of?(Effective::EmailTemplate) ? action : Effective::EmailTemplate.where(template_name: action).first!
14
14
  end
15
15
 
16
- if email_template.present?
17
- resource.email_form_from ||= email_template.from
18
- resource.email_form_subject ||= email_template.subject
19
- resource.email_form_body ||= email_template.body
20
- else
21
- defaults = form.object.email_form_defaults(action)
22
-
23
- resource.email_form_from ||= defaults[:from]
24
- resource.email_form_subject ||= defaults[:subject]
25
- resource.email_form_body ||= defaults[:body]
26
- end
27
-
28
- resource.email_form_from ||= EffectiveResources.mailer_froms.first
16
+ # These defaults are only used when there is no email_template
17
+ email_defaults = form.object.email_form_defaults(action) unless email_template.present?
29
18
 
30
19
  locals = {
31
20
  form: form,
32
21
  email_to: to,
33
22
  email_skip: skip,
34
23
  email_action: (action || true),
24
+ email_defaults: email_defaults,
35
25
  email_template: email_template,
36
26
  email_variables: variables
37
27
  }
@@ -39,4 +29,13 @@ module EffectiveActsAsEmailFormHelper
39
29
  render(partial: (partial || 'effective/acts_as_email_form/fields'), locals: locals)
40
30
  end
41
31
 
32
+ def mailer_froms_collection(froms: nil)
33
+ froms ||= EffectiveResources.mailer_froms
34
+
35
+ froms.map do |from|
36
+ html = content_tag(:span, escape_once(from))
37
+ [from, from, 'data-html': html]
38
+ end
39
+ end
40
+
42
41
  end
@@ -8,17 +8,9 @@ module EffectiveMailer
8
8
  layout -> { mailer_settings.mailer_layout }
9
9
  end
10
10
 
11
- protected
12
-
13
- def mailer_admin
14
- mailer_settings.mailer_admin
15
- end
16
-
17
- def subject_for(action, default, resource, opts = {})
11
+ def subject_for(action, subject, resource, opts = {})
18
12
  mailer_subject = mailer_settings.mailer_subject
19
13
 
20
- subject = opts[:subject] || opts['subject'] || default
21
-
22
14
  if mailer_subject.respond_to?(:call)
23
15
  subject = self.instance_exec(action, subject, resource, opts, &mailer_subject)
24
16
  end
@@ -26,8 +18,12 @@ module EffectiveMailer
26
18
  subject
27
19
  end
28
20
 
21
+ def mailer_admin
22
+ mailer_settings.mailer_admin
23
+ end
24
+
29
25
  def headers_for(resource, opts = {})
30
- (resource.respond_to?(:log_changes_datatable) ? opts.merge(log: resource) : opts)
26
+ resource.respond_to?(:log_changes_datatable) ? opts.merge(log: resource) : opts
31
27
  end
32
28
 
33
29
  private
@@ -43,9 +43,9 @@ module ActsAsEmailForm
43
43
  end
44
44
  end
45
45
 
46
- if defined?(EffectiveEmailTemplates)
47
- validates :email_form_subject, liquid: true, if: -> { email_form_effective_email_templates? }
48
- validates :email_form_body, liquid: true, if: -> { email_form_effective_email_templates? }
46
+ with_options(if: -> { defined?(EffectiveEmailTemplates) }) do
47
+ validates :email_form_subject, liquid: true
48
+ validates :email_form_body, liquid: true
49
49
  end
50
50
 
51
51
  def email_form_params
@@ -56,10 +56,6 @@ module ActsAsEmailForm
56
56
  EffectiveResources.truthy?(email_form_skip)
57
57
  end
58
58
 
59
- def email_form_effective_email_templates?
60
- !!defined?(EffectiveEmailTemplates)
61
- end
62
-
63
59
  # Only considered when not using an effective email template
64
60
  def email_form_defaults(action)
65
61
  { from: nil, subject: nil, body: nil }
@@ -7,9 +7,23 @@
7
7
  - if email_to.present?
8
8
  = form.static_field :email_form_to, label: 'To', value: (email_to.try(:email) || email_to)
9
9
 
10
- = form.select :email_form_from, EffectiveResources.mailer_froms, label: 'From'
11
- = form.text_field :email_form_subject, label: 'Subject'
12
- = form.text_area :email_form_body, label: 'Body', rows: 10
10
+ - if form.object.errors.present?
11
+ = form.select :email_form_from, mailer_froms_collection(), label: 'From'
12
+ = form.text_field :email_form_subject, label: 'Subject'
13
+ = form.text_area :email_form_body, label: 'Body', rows: 10
14
+
15
+ - elsif email_template.present?
16
+ -# email_template is an Effective::EmailTemplate
17
+ - from_value = email_template.from || EffectiveResources.mailer_froms.first
18
+ = form.select :email_form_from, mailer_froms_collection(), label: 'From', value: from_value
19
+ = form.text_field :email_form_subject, label: 'Subject', value: email_template.subject
20
+ = form.text_area :email_form_body, label: 'Body', value: email_template.body, rows: 10
21
+
22
+ - else
23
+ - from_value = email_defaults[:from] || EffectiveResources.mailer_froms.first
24
+ = form.select :email_form_from, mailer_froms_collection(), label: 'From', value: from_value
25
+ = form.text_field :email_form_subject, label: 'Subject', value: (email_defaults[:subject] || '')
26
+ = form.text_area :email_form_body, label: 'Body', rows: 10, value: (email_defaults[:body] || '')
13
27
 
14
28
  - if email_variables.present?
15
29
  %p The available variables are:
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.13.0'.freeze
2
+ VERSION = '2.15.0'.freeze
3
3
  end
@@ -72,6 +72,11 @@ module EffectiveResources
72
72
  config[:mailer_froms].presence || [mailer_sender]
73
73
  end
74
74
 
75
+ # This is used by the effective_email_templates form
76
+ def self.mailer_subject_prefix_hint
77
+ instance_exec(:mailer_subject_blank_prefix, nil, nil, nil, &mailer_subject) if mailer_subject.respond_to?(:call)
78
+ end
79
+
75
80
  # Utilities
76
81
 
77
82
  # This looks up the best class give the name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.0
4
+ version: 2.15.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