effective_email_templates 1.8.0 → 1.9.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47bfa3ecaa97c291febde3388a8f11190d61a19bf760204f6295ed92e5bb4471
|
4
|
+
data.tar.gz: 4d7c4d2780620e6aa3f530fec568d8296c34f48b517b2921243095e3e6c3dc16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbcb356a67b2b287bfb7a2031e1bc97de2d849df08c16ff347c7bfae412dcce7c452a8a8a940ff566492988274c5e1c058e171cd7c4c776e23ebcd42f12c4bf7
|
7
|
+
data.tar.gz: 95bdc306c0b0bd5fe76002c40938a2e326b9f1a37cba897b82079bf64ed11d4bf9e3f4ae83e57ae5fccbe1aa7ed8d3651bd886025449dfb902250bf0069c7e48
|
@@ -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,27 @@ 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
|
+
|
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
|
+
|
81
114
|
private
|
82
115
|
|
83
116
|
def template_body
|
@@ -24,10 +24,7 @@ module EffectiveEmailTemplates
|
|
24
24
|
name = File.basename(filepath, '.liquid')
|
25
25
|
email_template = Effective::EmailTemplate.find_or_initialize_by(template_name: name)
|
26
26
|
|
27
|
-
if email_template.persisted? && !overwrite
|
28
|
-
puts("SKIPPED #{filename(filepath)}") unless quiet
|
29
|
-
next
|
30
|
-
end
|
27
|
+
next if email_template.persisted? && !overwrite
|
31
28
|
|
32
29
|
save(email_template, filepath, quiet: quiet)
|
33
30
|
end
|
@@ -60,7 +57,10 @@ module EffectiveEmailTemplates
|
|
60
57
|
email_template.assign_attributes(from: from)
|
61
58
|
email_template.assign_attributes(body: body)
|
62
59
|
|
63
|
-
|
60
|
+
# Save as plain or html
|
61
|
+
save_method = (EffectiveEmailTemplates.select_content_type ? :save_as_html! : :save!)
|
62
|
+
|
63
|
+
if (email_template.send(save_method) rescue false)
|
64
64
|
puts("SUCCESS #{filename(filepath)}") unless quiet
|
65
65
|
else
|
66
66
|
puts "ERROR #{filename(filepath)}: #{email_template.errors.full_messages.to_sentence}"
|
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.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:
|
11
|
+
date: 2025-03-19 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
|