effective_email_templates 1.0.11 → 1.0.12
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/helpers/effective_email_templates_helper.rb +1 -0
- data/app/models/effective/email_review.rb +19 -12
- data/app/models/effective/email_template.rb +4 -17
- data/lib/effective_email_templates/engine.rb +3 -1
- data/lib/effective_email_templates/importer.rb +10 -8
- data/lib/effective_email_templates/version.rb +1 -1
- data/lib/validators/liquid_validator.rb +15 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4928f9db162ceb9b1b35fcbe367f38689be1f8977f75e46bff4e734c15f7ec90
|
4
|
+
data.tar.gz: 9129d4a60362284332fc2ab16685f0c325846dfe6f199cdd1e3924c974e3fb6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 963de88d3ca0956517777a2445018ecf36bece45bf40165007403b49c347ed4a217d3d6438518318cedb25354694473639da50845cab41cd29173575192acd8c
|
7
|
+
data.tar.gz: 06f6f69fea13c1405bb5e93576ed5779ca412db1955b7543effa2ced254a4af7e781154df370ae97cba887dfb962f29ca424d140040213b3442388f17e640d39
|
@@ -4,25 +4,32 @@ module Effective
|
|
4
4
|
|
5
5
|
attr_accessor :email_template
|
6
6
|
attr_accessor :template_name
|
7
|
+
|
7
8
|
attr_accessor :body
|
9
|
+
attr_accessor :subject
|
10
|
+
attr_accessor :from
|
11
|
+
attr_accessor :cc
|
12
|
+
attr_accessor :bcc
|
8
13
|
|
9
14
|
def self.build(attributes = {})
|
10
|
-
new(attributes)
|
11
|
-
|
12
|
-
email_review.template_name ||= email_review.email_template&.template_name
|
13
|
-
end
|
14
|
-
end
|
15
|
+
email_review = new(attributes)
|
16
|
+
template = email_review.email_template
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
23
25
|
end
|
26
|
+
|
27
|
+
email_review
|
24
28
|
end
|
25
29
|
|
30
|
+
validates :body, presence: true, liquid: true
|
31
|
+
validates :subject, liquid: true
|
32
|
+
|
26
33
|
def email_template
|
27
34
|
@email_template ||= Effective::EmailTemplate.where(template_name: template_name).first
|
28
35
|
end
|
@@ -22,21 +22,8 @@ module Effective
|
|
22
22
|
self.content_type ||= CONTENT_TYPES.first
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
Liquid::Template.parse(body)
|
28
|
-
rescue Liquid::SyntaxError => e
|
29
|
-
errors.add(:body, e.message)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
before_validation(if: -> { subject.present? }) do
|
34
|
-
begin
|
35
|
-
Liquid::Template.parse(subject)
|
36
|
-
rescue Liquid::SyntaxError => e
|
37
|
-
errors.add(:subject, e.message)
|
38
|
-
end
|
39
|
-
end
|
25
|
+
validates :body, liquid: true
|
26
|
+
validates :subject, liquid: true
|
40
27
|
|
41
28
|
validates :subject, presence: true
|
42
29
|
validates :from, presence: true
|
@@ -86,11 +73,11 @@ module Effective
|
|
86
73
|
private
|
87
74
|
|
88
75
|
def template_body
|
89
|
-
Liquid::Template.parse(body)
|
76
|
+
Liquid::Template.parse(body_was || body)
|
90
77
|
end
|
91
78
|
|
92
79
|
def template_subject
|
93
|
-
Liquid::Template.parse(subject)
|
80
|
+
Liquid::Template.parse(subject_was || subject)
|
94
81
|
end
|
95
82
|
|
96
83
|
def deep_stringify_assigns(assigns)
|
@@ -2,6 +2,9 @@ module EffectiveEmailTemplates
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
engine_name 'effective_email_templates'
|
4
4
|
|
5
|
+
config.autoload_paths += Dir["#{config.root}/lib/validators/"]
|
6
|
+
config.eager_load_paths += Dir["#{config.root}/lib/validators/"]
|
7
|
+
|
5
8
|
# Set up our default configuration options.
|
6
9
|
initializer 'effective_email_templates.defaults', before: :load_config_initializers do |app|
|
7
10
|
eval File.read("#{config.root}/config/effective_email_templates.rb")
|
@@ -16,4 +19,3 @@ module EffectiveEmailTemplates
|
|
16
19
|
|
17
20
|
end
|
18
21
|
end
|
19
|
-
|
@@ -9,16 +9,18 @@ module EffectiveEmailTemplates
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def execute(overwrite:, quiet: false)
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
ActionController::Base.view_paths.map(&:path).each do |path|
|
13
|
+
Dir[Rails.root.join(path, '**', '*_mailer/', '*.liquid')].each do |filepath|
|
14
|
+
name = File.basename(filepath, '.liquid')
|
15
|
+
email_template = Effective::EmailTemplate.find_or_initialize_by(template_name: name)
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if email_template.persisted? && !overwrite
|
18
|
+
puts("SKIPPED #{filename(filepath)}") unless quiet
|
19
|
+
next
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
+
save(email_template, filepath, quiet: quiet)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# An ActiveRecord validator for any liquid field that you would use with effective_email_templates or otherwise
|
2
|
+
#
|
3
|
+
# validates :body, liquid: true
|
4
|
+
|
5
|
+
class LiquidValidator < ActiveModel::EachValidator
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
if value.present?
|
8
|
+
begin
|
9
|
+
Liquid::Template.parse(value)
|
10
|
+
rescue Liquid::SyntaxError => e
|
11
|
+
record.errors.add(attribute, e.message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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.0.
|
4
|
+
version: 1.0.12
|
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: 2021-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/effective_email_templates/version.rb
|
116
116
|
- lib/generators/effective_email_templates/install_generator.rb
|
117
117
|
- lib/tasks/effective_email_templates_tasks.rake
|
118
|
+
- lib/validators/liquid_validator.rb
|
118
119
|
homepage: https://github.com/code-and-effect/effective_email_templates
|
119
120
|
licenses:
|
120
121
|
- MIT
|