effective_email_templates 1.8.0 → 1.9.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f5c8f6d7991aa4a349fecda1ea4fc687df0facb55214d176a0030720ede39db
|
4
|
+
data.tar.gz: 7882e4790ff27ff4c60d5985bc501df2fac90bba84e96dcb7b44f7d63dfe3657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f36ac864bc2efe007f7f06555aefe5a5a9abdae549dc2b4ed44db66033858efb1c26cac1ab7679ce6bb4321c2a3468fc8b80399347682c76b412e05ba74acdbf
|
7
|
+
data.tar.gz: 4ef1228155f5f2940e36af9a9b1c7373147954eb241fe5573c15f880b00231e8f86b6dec1eba53b24bea6b29c688c861b983ffc94a716f55a13c349b39a7f329
|
@@ -42,12 +42,22 @@ module EffectiveEmailTemplatesMailer
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
# Process body as plain text or html
|
46
|
+
body = merged.fetch(:body) || ''
|
47
|
+
|
45
48
|
# For text/plain emails
|
46
|
-
|
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
|
47
58
|
|
48
59
|
# For text/html emails
|
49
|
-
|
50
|
-
layout = mailer_layout().presence || raise("expected a mailer layout when rendering text/html templates")
|
60
|
+
layout = mailer_layout().presence || raise("expected a mailer layout when rendering text/html email_template #{action_name}")
|
51
61
|
|
52
62
|
super(merged.except(:body, :content_type)) do |format|
|
53
63
|
format.text { strip_tags(body) }
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Effective
|
2
2
|
class EmailTemplate < ActiveRecord::Base
|
3
|
+
include ActionView::Helpers::TextHelper
|
4
|
+
|
3
5
|
self.table_name = (EffectiveEmailTemplates.email_templates_table_name || :email_templates).to_s
|
4
6
|
|
5
7
|
attr_accessor :current_user
|
@@ -12,20 +14,22 @@ module Effective
|
|
12
14
|
|
13
15
|
effective_resource do
|
14
16
|
template_name :string
|
15
|
-
content_type :string
|
16
17
|
|
17
|
-
subject :string
|
18
18
|
from :string
|
19
19
|
cc :string
|
20
20
|
bcc :string
|
21
|
+
|
22
|
+
subject :string
|
21
23
|
body :text
|
22
24
|
|
25
|
+
content_type :string
|
26
|
+
|
23
27
|
timestamps
|
24
28
|
end
|
25
29
|
|
26
30
|
before_validation do
|
27
|
-
self.content_type ||= CONTENT_TYPES.first
|
28
31
|
self.from ||= EffectiveEmailTemplates.mailer_froms.first
|
32
|
+
self.content_type ||= CONTENT_TYPES.first
|
29
33
|
end
|
30
34
|
|
31
35
|
validates :body, liquid: true
|
@@ -38,11 +42,11 @@ module Effective
|
|
38
42
|
validates :template_name, presence: true
|
39
43
|
|
40
44
|
validate(if: -> { html? && body.present? }) do
|
41
|
-
errors.add(:body, 'expected html tags in body')
|
45
|
+
errors.add(:body, 'expected html tags in body') if body_plain?
|
42
46
|
end
|
43
47
|
|
44
48
|
validate(if: -> { plain? && body.present? }) do
|
45
|
-
errors.add(:body, '
|
49
|
+
errors.add(:body, 'unexpected html tags found in body') if body_html?
|
46
50
|
end
|
47
51
|
|
48
52
|
def to_s
|
@@ -57,6 +61,14 @@ module Effective
|
|
57
61
|
content_type == CONTENT_TYPE_PLAIN
|
58
62
|
end
|
59
63
|
|
64
|
+
def body_html?
|
65
|
+
body.present? && (body.include?('</p>') || body.include?('</div>'))
|
66
|
+
end
|
67
|
+
|
68
|
+
def body_plain?
|
69
|
+
body.present? && !(body.include?('</p>') || body.include?('</div>'))
|
70
|
+
end
|
71
|
+
|
60
72
|
def render(assigns = {})
|
61
73
|
assigns = deep_stringify_assigns(assigns)
|
62
74
|
|
@@ -78,6 +90,18 @@ module Effective
|
|
78
90
|
end.flatten.uniq.compact
|
79
91
|
end
|
80
92
|
|
93
|
+
def save_as_html!
|
94
|
+
assign_attributes(content_type: 'text/html')
|
95
|
+
assign_attributes(body: simple_format(body)) if body_plain?
|
96
|
+
save!
|
97
|
+
end
|
98
|
+
|
99
|
+
def save_as_plain!
|
100
|
+
assign_attributes(content_type: 'text/plain')
|
101
|
+
assign_attributes(body: strip_tags(body)) if body_html?
|
102
|
+
save!
|
103
|
+
end
|
104
|
+
|
81
105
|
private
|
82
106
|
|
83
107
|
def template_body
|
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.9.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: 2024-06-
|
11
|
+
date: 2024-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: haml
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: pry-byebug
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|