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 +4 -4
- data/app/datatables/effective_email_templates_datatable.rb +4 -1
- data/app/mailers/concerns/effective_email_templates_mailer.rb +20 -1
- data/app/models/effective/email_template.rb +18 -14
- data/app/views/admin/email_templates/_form.html.haml +12 -11
- data/lib/effective_email_templates/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9651ddd52c209639a97f57e6598f203ef6de87c39264db848a02fc57118272c
|
4
|
+
data.tar.gz: fec2c937050738a39b1d6df2aeaf0b104a8d581188b3e7e9024806c141707ded
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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.
|
14
|
-
|
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
|
-
=
|
20
|
+
= card do
|
21
|
+
%p The available variables for this email template are:
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
%ul
|
24
|
+
- Array(f.object.template_variables).each do |variable|
|
25
|
+
%li {{ #{variable} }}
|
21
26
|
|
22
|
-
|
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'
|
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.
|
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:
|
11
|
+
date: 2024-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|