effective_email_templates 1.7.0 → 1.8.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: 8d32e71af524fb3658debbf8210a4239b4bbd98f7a806f0a743735e62bc135dc
4
- data.tar.gz: f6064f01a1a679b3c4bf1abca99222ab4ba191d4bb0ee16a1ac23ddad644c368
3
+ metadata.gz: e9651ddd52c209639a97f57e6598f203ef6de87c39264db848a02fc57118272c
4
+ data.tar.gz: fec2c937050738a39b1d6df2aeaf0b104a8d581188b3e7e9024806c141707ded
5
5
  SHA512:
6
- metadata.gz: 360328a697866d2d802d7c882bcfbd9c0be6e148c0b6d98114417088af72b9ea74cc935d275b6396a8be64becd88749536f491b1cfcb0f953e8ab1c739ba276e
7
- data.tar.gz: 5cad8e018ad138e6050278c36e39a69a631a06773bc8d87aeee9986a96b56de9ab3f491198634eea514126f30241a0536b2b8ccceb9721f5e6a7da928e7f0b63
6
+ metadata.gz: 55b6589e19e6437bf9b42a064df20c536b0e092dcc0efc1e646bba5c49867b214e9ba1f3e9c5c0f8d0cc55974fe28fe7348e63a4b21d6cb71c69417cced54844
7
+ data.tar.gz: e7caa88e4d81f51abf3c244c20dca5873caf3b1f4766dfdb0e821958ba039195376f08192c5c96e607e52dcdbd1df14e638d7d959eb0d1e86974c36c7616b444
@@ -9,7 +9,10 @@ class EffectiveEmailTemplatesDatatable < Effective::Datatable
9
9
 
10
10
  col :template_name, label: 'Name'
11
11
 
12
- col :from, search: EffectiveEmailTemplates.mailer_froms
12
+ col :from, search: EffectiveEmailTemplates.mailer_froms do |email_template|
13
+ ERB::Util.html_escape_once(email_template.from)
14
+ end
15
+
13
16
  col :cc
14
17
  col :bcc
15
18
  col :subject
@@ -42,11 +42,30 @@ module EffectiveEmailTemplatesMailer
42
42
  end
43
43
  end
44
44
 
45
- super(merged)
45
+ # For text/plain emails
46
+ return super(merged) if email_template.plain?
47
+
48
+ # For text/html emails
49
+ body = merged.fetch(:body)
50
+ layout = mailer_layout().presence || raise("expected a mailer layout when rendering text/html templates")
51
+
52
+ super(merged.except(:body, :content_type)) do |format|
53
+ format.text { strip_tags(body) }
54
+ format.html { render(layout: layout, inline: body) }
55
+ end
56
+ end
57
+
58
+ def mailer_layout
59
+ try(:mailer_settings).try(:mailer_layout) || EffectiveEmailTemplates.mailer_layout
46
60
  end
47
61
 
48
62
  private
49
63
 
64
+ def strip_tags(html)
65
+ return html if html.blank?
66
+ view_context.strip_tags(html.gsub(/<\/(div|p|br|h[1-6])>/, "\n"))
67
+ end
68
+
50
69
  def route_url_assigns(email_template, existing)
51
70
  route_variables = email_template.template_variables
52
71
  .select { |name| name.ends_with?('_url') }
@@ -6,7 +6,9 @@ module Effective
6
6
 
7
7
  log_changes if respond_to?(:log_changes)
8
8
 
9
- CONTENT_TYPES = ['text/plain', 'text/html']
9
+ CONTENT_TYPE_PLAIN = 'text/plain'
10
+ CONTENT_TYPE_HTML = 'text/html'
11
+ CONTENT_TYPES = [CONTENT_TYPE_PLAIN, CONTENT_TYPE_HTML]
10
12
 
11
13
  effective_resource do
12
14
  template_name :string
@@ -35,28 +37,30 @@ module Effective
35
37
  validates :content_type, presence: true, inclusion: { in: CONTENT_TYPES }
36
38
  validates :template_name, presence: true
37
39
 
38
- # validate(if: -> { content_type == 'text/html' && body.present? }) do
39
- # unless body.include?('<') && body.include?('>')
40
- # self.errors.add(:content_type, 'expected html tags in body')
41
- # self.errors.add(:body, 'expected html tags in body')
42
- # end
43
- # end
40
+ validate(if: -> { html? && body.present? }) do
41
+ errors.add(:body, 'expected html tags in body') unless body.include?('</p>') || body.include?('</div>')
42
+ end
44
43
 
45
- # validate(if: -> { content_type == 'text/plain' && body.present? }) do
46
- # if body.include?('</a>') || body.include?('</p>')
47
- # self.errors.add(:content_type, 'expected no html tags in body')
48
- # self.errors.add(:body, 'expected no html tags in body')
49
- # end
50
- # end
44
+ validate(if: -> { plain? && body.present? }) do
45
+ errors.add(:body, 'expected no html tags in body') if body.include?('</p>') || body.include?('</div>')
46
+ end
51
47
 
52
48
  def to_s
53
49
  template_name.presence || 'New Email Template'
54
50
  end
55
51
 
52
+ def html?
53
+ content_type == CONTENT_TYPE_HTML
54
+ end
55
+
56
+ def plain?
57
+ content_type == CONTENT_TYPE_PLAIN
58
+ end
59
+
56
60
  def render(assigns = {})
57
61
  assigns = deep_stringify_assigns(assigns)
58
62
 
59
- result = {
63
+ {
60
64
  from: from,
61
65
  cc: cc.presence,
62
66
  bcc: bcc.presence,
@@ -9,21 +9,22 @@
9
9
  = f.text_field :bcc
10
10
 
11
11
  - prefix_hint = EffectiveResources.mailer_subject_prefix_hint.to_s.strip.presence
12
+ = f.text_field :subject, hint: (prefix_hint ? "The subject of your email. It will be automatically prefixed with: #{prefix_hint}" : 'The subject of your email')
12
13
 
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')
14
+ = f.show_if(:content_type, Effective::EmailTemplate::CONTENT_TYPE_PLAIN) do
15
+ = f.text_area :body, hint: 'The text/plain content of your email template', rows: 10
16
+
17
+ = f.show_if(:content_type, Effective::EmailTemplate::CONTENT_TYPE_HTML) do
18
+ = f.article_editor :body, hint: 'The text/html content of your email template', mode: :email
15
19
 
16
- = f.text_area :body, hint: 'The content of your email template', rows: 10
20
+ = card do
21
+ %p The available variables for this email template are:
17
22
 
18
- .card
19
- .card-body
20
- %p The available variables for this email template are:
23
+ %ul
24
+ - Array(f.object.template_variables).each do |variable|
25
+ %li {{ #{variable} }}
21
26
 
22
- %ul
23
- - Array(f.object.template_variables).each do |variable|
24
- %li {{ #{variable} }}
25
-
26
- %small.text-muted Please contact us to add additional variables
27
+ %small.text-muted Please contact us to add additional variables
27
28
 
28
29
  = f.submit do
29
30
  = f.save 'Save'
@@ -1,3 +1,3 @@
1
1
  module EffectiveEmailTemplates
2
- VERSION = '1.7.0'.freeze
2
+ VERSION = '1.8.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.7.0
4
+ version: 1.8.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-26 00:00:00.000000000 Z
11
+ date: 2024-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails