effective_email_templates 1.0.8 → 1.0.13
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 +2 -1
- data/app/helpers/effective_email_templates_helper.rb +10 -1
- data/app/mailers/effective/email_templates_mailer.rb +8 -6
- data/app/models/effective/email_review.rb +19 -12
- data/app/models/effective/email_template.rb +16 -15
- data/app/views/admin/email_templates/_form.html.haml +3 -1
- data/config/effective_email_templates.rb +3 -0
- data/lib/effective_email_templates.rb +1 -0
- 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 +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea4dc4be1510a05879a7ff2c084a17126b4d8bcaa228c693a7cb8a4093a2ffc
|
4
|
+
data.tar.gz: 74936efb073fc46f09e04d8543858c2a667e4737eeccc86b64882d1f5d9cf402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cefe7ba9a4d3da5a15e4f1e7429167e7ff1d3570f2b381f5ca2c4a2f1379066748a6b0436868099badf1eb3ea178ba347f2d7889ea170b1108e14c80f0d1d61
|
7
|
+
data.tar.gz: d1e69f8c657c791cc2af22be8ef22fb5a0c4acecb1670727fc9e83b6e6de0ad0f3c9972f8990c3251b0b569148a23c763d64157a55a2ccb6c850bc11f969b200
|
@@ -14,6 +14,8 @@ class EffectiveEmailTemplatesDatatable < Effective::Datatable
|
|
14
14
|
col :subject
|
15
15
|
col :body
|
16
16
|
|
17
|
+
col :content_type, visible: false
|
18
|
+
|
17
19
|
actions_col partial: '/admin/email_templates/actions', partial_as: 'email_template'
|
18
20
|
end
|
19
21
|
|
@@ -21,4 +23,3 @@ class EffectiveEmailTemplatesDatatable < Effective::Datatable
|
|
21
23
|
Effective::EmailTemplate.all
|
22
24
|
end
|
23
25
|
end
|
24
|
-
|
@@ -1,11 +1,20 @@
|
|
1
1
|
module EffectiveEmailTemplatesHelper
|
2
2
|
|
3
|
-
|
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
|
+
|
4
8
|
email_review = form.object.email_review
|
5
9
|
|
6
10
|
unless email_review&.template_name == template_name.to_s
|
7
11
|
email_template = Effective::EmailTemplate.where(template_name: template_name).first!
|
8
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
|
9
18
|
end
|
10
19
|
|
11
20
|
render(partial: 'effective/email_reviews/fields', locals: { email_review: email_review, form: form })
|
@@ -3,20 +3,22 @@ module Effective
|
|
3
3
|
|
4
4
|
def mail(headers = {}, &block)
|
5
5
|
email_template = Effective::EmailTemplate.where(template_name: action_name).first!
|
6
|
-
|
7
|
-
# Parse Assigns. :body is a special key
|
8
6
|
assigns = (@assigns || {})
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
# Parse assigns. Special keys for body and subject.
|
9
|
+
body = assigns.delete(:body) || headers[:body] || headers['body']
|
10
|
+
email_template.body = body if body.present?
|
11
|
+
|
12
|
+
subject = assigns.delete(:subject) || headers[:subject] || headers['subject']
|
13
|
+
email_template.subject = subject if subject.present?
|
13
14
|
|
15
|
+
# Add any _url helpers
|
14
16
|
assigns = route_url_assigns(email_template).merge(assigns)
|
15
17
|
|
16
18
|
# Render from the template, possibly with updated body
|
17
19
|
rendered = email_template.render(assigns)
|
18
20
|
|
19
|
-
super(rendered.merge(headers))
|
21
|
+
super(rendered.merge(headers.except(:body, :subject, 'body', 'subject')))
|
20
22
|
end
|
21
23
|
|
22
24
|
private
|
@@ -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
|
@@ -44,6 +31,20 @@ module Effective
|
|
44
31
|
validates :content_type, presence: true, inclusion: { in: CONTENT_TYPES }
|
45
32
|
validates :template_name, presence: true
|
46
33
|
|
34
|
+
# validate(if: -> { content_type == 'text/html' && body.present? }) do
|
35
|
+
# unless body.include?('<') && body.include?('>')
|
36
|
+
# self.errors.add(:content_type, 'expected html tags in body')
|
37
|
+
# self.errors.add(:body, 'expected html tags in body')
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
|
41
|
+
# validate(if: -> { content_type == 'text/plain' && body.present? }) do
|
42
|
+
# if body.include?('</a>') || body.include?('</p>')
|
43
|
+
# self.errors.add(:content_type, 'expected no html tags in body')
|
44
|
+
# self.errors.add(:body, 'expected no html tags in body')
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
|
47
48
|
def to_s
|
48
49
|
template_name.presence || 'New Email Template'
|
49
50
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
= effective_form_with(model: email_template, url: email_template.persisted? ? effective_email_templates.admin_email_template_path(email_template.id) : effective_email_templates.admin_email_templates_path) do |f|
|
2
2
|
= f.static_field :template_name, label: 'Name'
|
3
|
-
|
3
|
+
|
4
|
+
- if EffectiveEmailTemplates.select_content_type
|
5
|
+
= f.select :content_type, Effective::EmailTemplate::CONTENT_TYPES
|
4
6
|
|
5
7
|
= f.email_field :from, hint: 'Whom the email will be sent from'
|
6
8
|
= f.text_field :cc
|
@@ -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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -115,11 +115,12 @@ 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
|
121
122
|
metadata: {}
|
122
|
-
post_install_message:
|
123
|
+
post_install_message:
|
123
124
|
rdoc_options: []
|
124
125
|
require_paths:
|
125
126
|
- lib
|
@@ -134,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
- !ruby/object:Gem::Version
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
138
|
-
signing_key:
|
138
|
+
rubygems_version: 3.1.2
|
139
|
+
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: Effective Email Templates provides an admin access to modify email templates
|
141
142
|
test_files: []
|