effective_email_templates 1.9.3 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/datatables/effective_email_templates_datatable.rb +0 -2
- data/app/helpers/effective_email_templates_helper.rb +0 -21
- data/app/mailers/concerns/effective_email_templates_mailer.rb +2 -15
- data/app/models/effective/email_template.rb +15 -47
- data/app/views/admin/email_templates/_form.html.haml +1 -8
- data/config/effective_email_templates.rb +0 -3
- data/db/migrate/101_create_effective_email_templates.rb +0 -1
- data/lib/effective_email_templates/importer.rb +1 -4
- data/lib/effective_email_templates/version.rb +1 -1
- data/lib/effective_email_templates.rb +2 -2
- metadata +2 -4
- data/app/models/effective/email_review.rb +0 -38
- data/app/views/effective/email_reviews/_fields.html.haml +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f9c6e50213d4168bcb01a3d4f4524e89b58aeced9f489e94f706bfa3370f962
|
|
4
|
+
data.tar.gz: 9fc4ba9085fa62c3a77334bb1ba3d86f531f2f659feee2d6da73658557ad2874
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8313334ab8ac9cb89e8ab962519f91a4bd7e8c6ad140a515c0a7d0dc25385d2b33115e9dd14cb63dfcd45d1633986c7cd242fb263c742d375baff04ef3ea6c7
|
|
7
|
+
data.tar.gz: 161defb7c4e2d0d1008acf6eb435f3414ebef94580b41d89c294a0dedaa1d93a20bb7fbb9e3ba32f541e18e56b839848bf3d8fdd928fdb00efd58fde7004bdc0
|
|
@@ -1,23 +1,2 @@
|
|
|
1
1
|
module EffectiveEmailTemplatesHelper
|
|
2
|
-
|
|
3
|
-
# We are given a form to essentially send an email
|
|
4
|
-
def effective_email_review_fields(form, template_name, mail = nil)
|
|
5
|
-
raise('expected a mail object') if mail && !mail.kind_of?(ActionMailer::MessageDelivery)
|
|
6
|
-
raise('expected form.object to respond to email_review') unless form.object.respond_to?(:email_review)
|
|
7
|
-
|
|
8
|
-
email_review = form.object.email_review
|
|
9
|
-
|
|
10
|
-
unless email_review&.template_name == template_name.to_s
|
|
11
|
-
email_template = Effective::EmailTemplate.where(template_name: template_name).first!
|
|
12
|
-
email_review = Effective::EmailReview.build(email_template: email_template)
|
|
13
|
-
|
|
14
|
-
if mail.present?
|
|
15
|
-
email_review.body = mail.message.body
|
|
16
|
-
email_review.subject = mail.message.subject
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
render(partial: 'effective/email_reviews/fields', locals: { email_review: email_review, form: form })
|
|
21
|
-
end
|
|
22
|
-
|
|
23
2
|
end
|
|
@@ -42,22 +42,9 @@ module EffectiveEmailTemplatesMailer
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
#
|
|
45
|
+
# Render as multipart html email
|
|
46
46
|
body = merged.fetch(:body) || ''
|
|
47
|
-
|
|
48
|
-
# For text/plain emails
|
|
49
|
-
if email_template.plain?
|
|
50
|
-
stripped = body.strip
|
|
51
|
-
|
|
52
|
-
if stripped.starts_with?('<p>') || stripped.ends_with?('</p>')
|
|
53
|
-
raise("unexpected html content found when when rendering text/plain email_template #{action_name}")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
return super(merged)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# For text/html emails
|
|
60
|
-
layout = mailer_layout().presence || raise("expected a mailer layout when rendering text/html email_template #{action_name}")
|
|
47
|
+
layout = mailer_layout().presence || raise("expected a mailer layout when rendering email_template #{action_name}")
|
|
61
48
|
|
|
62
49
|
super(merged.except(:body, :content_type)) do |format|
|
|
63
50
|
format.text { strip_tags(body) }
|
|
@@ -8,10 +8,6 @@ module Effective
|
|
|
8
8
|
|
|
9
9
|
log_changes if respond_to?(:log_changes)
|
|
10
10
|
|
|
11
|
-
CONTENT_TYPE_PLAIN = 'text/plain'
|
|
12
|
-
CONTENT_TYPE_HTML = 'text/html'
|
|
13
|
-
CONTENT_TYPES = [CONTENT_TYPE_PLAIN, CONTENT_TYPE_HTML]
|
|
14
|
-
|
|
15
11
|
effective_resource do
|
|
16
12
|
template_name :string
|
|
17
13
|
|
|
@@ -22,14 +18,21 @@ module Effective
|
|
|
22
18
|
subject :string
|
|
23
19
|
body :text
|
|
24
20
|
|
|
25
|
-
content_type :string
|
|
26
|
-
|
|
27
21
|
timestamps
|
|
28
22
|
end
|
|
29
23
|
|
|
30
24
|
before_validation do
|
|
31
25
|
self.from ||= EffectiveEmailTemplates.mailer_froms.first
|
|
32
|
-
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Convert to HTML
|
|
29
|
+
before_validation(if: -> { body_plain? }) do
|
|
30
|
+
html = simple_format(body)
|
|
31
|
+
|
|
32
|
+
# Replace [UpsideAMS](http://www.upsideams.com) type markdown links
|
|
33
|
+
html = html.gsub(/\[(.*?)\]\((.*?)\)/, '<a href="\2">\1</a>')
|
|
34
|
+
|
|
35
|
+
assign_attributes(body: html)
|
|
33
36
|
end
|
|
34
37
|
|
|
35
38
|
validates :body, liquid: true
|
|
@@ -38,31 +41,18 @@ module Effective
|
|
|
38
41
|
validates :subject, presence: true
|
|
39
42
|
validates :from, presence: true, email: true
|
|
40
43
|
validates :body, presence: true
|
|
41
|
-
validates :content_type, presence: true, inclusion: { in: CONTENT_TYPES }
|
|
42
44
|
validates :template_name, presence: true
|
|
43
45
|
|
|
44
|
-
validate(if: -> {
|
|
46
|
+
validate(if: -> { body.present? }) do
|
|
45
47
|
errors.add(:body, 'expected html tags in body') if body_plain?
|
|
46
48
|
end
|
|
47
49
|
|
|
48
|
-
validate(if: -> { plain? && body.present? }) do
|
|
49
|
-
errors.add(:body, 'unexpected html tags found in body') if body_html?
|
|
50
|
-
end
|
|
51
|
-
|
|
52
50
|
def to_s
|
|
53
51
|
template_name.presence || 'New Email Template'
|
|
54
52
|
end
|
|
55
53
|
|
|
56
|
-
def
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def plain?
|
|
61
|
-
content_type == CONTENT_TYPE_PLAIN
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def body_html?
|
|
65
|
-
body.present? && (body.include?('</p>') || body.include?('</div>'))
|
|
54
|
+
def content_type
|
|
55
|
+
'text/html'
|
|
66
56
|
end
|
|
67
57
|
|
|
68
58
|
def body_plain?
|
|
@@ -76,7 +66,6 @@ module Effective
|
|
|
76
66
|
from: from,
|
|
77
67
|
cc: cc.presence,
|
|
78
68
|
bcc: bcc.presence,
|
|
79
|
-
content_type: content_type,
|
|
80
69
|
subject: template_subject.render(assigns),
|
|
81
70
|
body: template_body.render(assigns)
|
|
82
71
|
}.compact
|
|
@@ -90,35 +79,14 @@ module Effective
|
|
|
90
79
|
end.flatten.uniq.compact
|
|
91
80
|
end
|
|
92
81
|
|
|
93
|
-
def save_as_html!
|
|
94
|
-
assign_attributes(content_type: 'text/html')
|
|
95
|
-
|
|
96
|
-
if body_plain?
|
|
97
|
-
html = simple_format(body)
|
|
98
|
-
|
|
99
|
-
# Replace [UpsideAMS](http://www.upsideams.com) type markdown links
|
|
100
|
-
html = html.gsub(/\[(.*?)\]\((.*?)\)/, '<a href="\2">\1</a>')
|
|
101
|
-
|
|
102
|
-
assign_attributes(body: html)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
save!
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def save_as_plain!
|
|
109
|
-
assign_attributes(content_type: 'text/plain')
|
|
110
|
-
assign_attributes(body: strip_tags(body)) if body_html?
|
|
111
|
-
save!
|
|
112
|
-
end
|
|
113
|
-
|
|
114
82
|
private
|
|
115
83
|
|
|
116
84
|
def template_body
|
|
117
|
-
Liquid::Template.parse(body)
|
|
85
|
+
(Liquid::Template.parse(body) rescue nil)
|
|
118
86
|
end
|
|
119
87
|
|
|
120
88
|
def template_subject
|
|
121
|
-
Liquid::Template.parse(subject)
|
|
89
|
+
(Liquid::Template.parse(subject) rescue nil)
|
|
122
90
|
end
|
|
123
91
|
|
|
124
92
|
def deep_stringify_assigns(assigns)
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
= card do
|
|
3
3
|
= f.static_field :template_name, label: 'Name'
|
|
4
4
|
|
|
5
|
-
- if EffectiveEmailTemplates.select_content_type
|
|
6
|
-
= f.select :content_type, Effective::EmailTemplate::CONTENT_TYPES
|
|
7
|
-
|
|
8
5
|
= 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.'
|
|
9
6
|
= f.text_field :cc
|
|
10
7
|
= f.text_field :bcc
|
|
@@ -12,11 +9,7 @@
|
|
|
12
9
|
- prefix_hint = EffectiveResources.mailer_subject_prefix_hint.to_s.strip.presence
|
|
13
10
|
= 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')
|
|
14
11
|
|
|
15
|
-
= f.
|
|
16
|
-
= f.text_area :body, hint: 'The text/plain content of your email template', rows: 10
|
|
17
|
-
|
|
18
|
-
= f.show_if(:content_type, Effective::EmailTemplate::CONTENT_TYPE_HTML) do
|
|
19
|
-
= f.article_editor :body, hint: 'The text/html content of your email template', mode: :email
|
|
12
|
+
= f.article_editor :body, hint: 'The content of your email template', mode: :email
|
|
20
13
|
|
|
21
14
|
= card do
|
|
22
15
|
%p The available variables for this email template are:
|
|
@@ -57,10 +57,7 @@ module EffectiveEmailTemplates
|
|
|
57
57
|
email_template.assign_attributes(from: from)
|
|
58
58
|
email_template.assign_attributes(body: body)
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
save_method = (EffectiveEmailTemplates.select_content_type ? :save_as_html! : :save!)
|
|
62
|
-
|
|
63
|
-
if (email_template.send(save_method) rescue false)
|
|
60
|
+
if email_template.save
|
|
64
61
|
puts("SUCCESS #{filename(filepath)}") unless quiet
|
|
65
62
|
else
|
|
66
63
|
puts "ERROR #{filename(filepath)}: #{email_template.errors.full_messages.to_sentence}"
|
|
@@ -6,13 +6,13 @@ require 'effective_email_templates/version'
|
|
|
6
6
|
module EffectiveEmailTemplates
|
|
7
7
|
|
|
8
8
|
def self.config_keys
|
|
9
|
-
[:email_templates_table_name, :
|
|
9
|
+
[:email_templates_table_name, :layout]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
include EffectiveGem
|
|
13
13
|
|
|
14
14
|
def self.permitted_params
|
|
15
|
-
@permitted_params ||= [:from, :bcc, :cc, :subject, :body
|
|
15
|
+
@permitted_params ||= [:from, :bcc, :cc, :subject, :body]
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
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.
|
|
4
|
+
version: 1.10.1
|
|
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: 2026-
|
|
11
|
+
date: 2026-06-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -193,10 +193,8 @@ files:
|
|
|
193
193
|
- app/mailers/concerns/effective_email_templates_mailer.rb
|
|
194
194
|
- app/mailers/effective/email_templates_mailer.rb
|
|
195
195
|
- app/models/concerns/has_one_email_review.rb
|
|
196
|
-
- app/models/effective/email_review.rb
|
|
197
196
|
- app/models/effective/email_template.rb
|
|
198
197
|
- app/views/admin/email_templates/_form.html.haml
|
|
199
|
-
- app/views/effective/email_reviews/_fields.html.haml
|
|
200
198
|
- app/views/layouts/effective_email_templates_mailer_layout.html.haml
|
|
201
199
|
- config/effective_email_templates.rb
|
|
202
200
|
- config/email_templates_mailer.rb
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module Effective
|
|
2
|
-
class EmailReview
|
|
3
|
-
include ActiveModel::Model
|
|
4
|
-
|
|
5
|
-
attr_accessor :email_template
|
|
6
|
-
attr_accessor :template_name
|
|
7
|
-
|
|
8
|
-
attr_accessor :body
|
|
9
|
-
attr_accessor :subject
|
|
10
|
-
attr_accessor :from
|
|
11
|
-
attr_accessor :cc
|
|
12
|
-
attr_accessor :bcc
|
|
13
|
-
|
|
14
|
-
def self.build(attributes = {})
|
|
15
|
-
email_review = new(attributes)
|
|
16
|
-
template = email_review.email_template
|
|
17
|
-
|
|
18
|
-
if template.present?
|
|
19
|
-
email_review.body ||= template.body
|
|
20
|
-
email_review.subject ||= template.subject
|
|
21
|
-
email_review.from ||= template.from
|
|
22
|
-
email_review.cc ||= template.cc
|
|
23
|
-
email_review.bcc ||= template.bcc
|
|
24
|
-
email_review.template_name ||= template.template_name
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
email_review
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
validates :body, presence: true, liquid: true
|
|
31
|
-
validates :subject, liquid: true
|
|
32
|
-
|
|
33
|
-
def email_template
|
|
34
|
-
@email_template ||= Effective::EmailTemplate.where(template_name: template_name).first
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
= form.fields_for(:email_review, email_review) do |f|
|
|
2
|
-
= f.hidden_field :template_name
|
|
3
|
-
= f.text_area :body, required: true, rows: 10
|
|
4
|
-
|
|
5
|
-
= collapse('Show / hide email variables') do
|
|
6
|
-
%p The available variables are:
|
|
7
|
-
|
|
8
|
-
%ul
|
|
9
|
-
- Array(f.object.email_template&.template_variables).each do |variable|
|
|
10
|
-
%li {{ #{variable} }}
|
|
11
|
-
|
|
12
|
-
%small.text-muted Only a developer can add additional variables
|
|
13
|
-
|