effective_email_templates 1.1.0 → 1.1.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 +1 -1
- data/app/mailers/concerns/effective_email_templates_mailer.rb +35 -0
- data/app/mailers/effective/email_templates_mailer.rb +1 -29
- data/lib/effective_email_templates/importer.rb +10 -6
- data/lib/effective_email_templates/version.rb +1 -1
- 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: 633c93cac11add92db1adcfdd7d2441dbf928f12abc4182798e4c66d93995fe3
|
4
|
+
data.tar.gz: 85d947fcfd9da53aa93cf0b7e43e677633f250167a43afc67b1c6a71dc376a54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e8ed05ed566941bb48fe9ec8be95bfc4d2019b7dbbee3fd0d282fd7c01061e5e51cfc13468bd466fc09c60b1f95ad8088db37af5095eb2fdb4929c6539bd993
|
7
|
+
data.tar.gz: '089e9291f52db8749cb282b2b087e162acb30c9b0c61da47d5e489a4ab18affd5f77e36aa5018f036efcde410f3ecb1594923c93fa3e57c5ccdb7211f70647f4'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# HasOneEmailReview
|
2
|
+
# Allows any model to easily review an email template and make changes to the body
|
3
|
+
|
4
|
+
module EffectiveEmailTemplatesMailer
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def mail(headers = {}, &block)
|
8
|
+
email_template = Effective::EmailTemplate.where(template_name: action_name).first!
|
9
|
+
assigns = (@assigns || {})
|
10
|
+
|
11
|
+
# Parse assigns. Special keys for body and subject.
|
12
|
+
body = assigns.delete(:body) || headers[:body] || headers['body']
|
13
|
+
email_template.body = body if body.present?
|
14
|
+
|
15
|
+
subject = assigns.delete(:subject) || headers[:subject] || headers['subject']
|
16
|
+
email_template.subject = subject if subject.present?
|
17
|
+
|
18
|
+
# Add any _url helpers
|
19
|
+
assigns = route_url_assigns(email_template).merge(assigns)
|
20
|
+
|
21
|
+
# Render from the template, possibly with updated body
|
22
|
+
rendered = email_template.render(assigns)
|
23
|
+
|
24
|
+
super(rendered.merge(headers.except(:body, :subject, 'body', 'subject')))
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def route_url_assigns(email_template)
|
30
|
+
email_template.template_variables.select { |name| name.ends_with?('_url') }.inject({}) do |h, name|
|
31
|
+
h[name] = public_send(name) if respond_to?(name); h
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -1,33 +1,5 @@
|
|
1
1
|
module Effective
|
2
2
|
class EmailTemplatesMailer < ::ActionMailer::Base
|
3
|
-
|
4
|
-
def mail(headers = {}, &block)
|
5
|
-
email_template = Effective::EmailTemplate.where(template_name: action_name).first!
|
6
|
-
assigns = (@assigns || {})
|
7
|
-
|
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?
|
14
|
-
|
15
|
-
# Add any _url helpers
|
16
|
-
assigns = route_url_assigns(email_template).merge(assigns)
|
17
|
-
|
18
|
-
# Render from the template, possibly with updated body
|
19
|
-
rendered = email_template.render(assigns)
|
20
|
-
|
21
|
-
super(rendered.merge(headers.except(:body, :subject, 'body', 'subject')))
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def route_url_assigns(email_template)
|
27
|
-
email_template.template_variables.select { |name| name.ends_with?('_url') }.inject({}) do |h, name|
|
28
|
-
h[name] = public_send(name) if respond_to?(name); h
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
3
|
+
include EffectiveEmailTemplatesMailer
|
32
4
|
end
|
33
5
|
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module EffectiveEmailTemplates
|
2
2
|
class Importer
|
3
|
-
def self.import(quiet: false)
|
4
|
-
new().execute(overwrite: false, quiet: quiet)
|
3
|
+
def self.import(quiet: false, paths: nil)
|
4
|
+
new().execute(overwrite: false, paths: paths, quiet: quiet)
|
5
5
|
end
|
6
6
|
|
7
|
-
def self.overwrite(quiet: false)
|
8
|
-
new().execute(overwrite: true, quiet: quiet)
|
7
|
+
def self.overwrite(quiet: false, paths: nil)
|
8
|
+
new().execute(overwrite: true, paths: paths, quiet: quiet)
|
9
9
|
end
|
10
10
|
|
11
|
-
def execute(overwrite:, quiet: false)
|
12
|
-
|
11
|
+
def execute(overwrite:, paths: nil, quiet: false)
|
12
|
+
return false unless ActiveRecord::Base.connection.table_exists?(EffectiveEmailTemplates.email_templates_table_name)
|
13
|
+
|
14
|
+
paths ||= ActionController::Base.view_paths.map(&:path)
|
15
|
+
|
16
|
+
paths.each do |path|
|
13
17
|
Dir[Rails.root.join(path, '**', '*_mailer/', '*.liquid')].each do |filepath|
|
14
18
|
name = File.basename(filepath, '.liquid')
|
15
19
|
email_template = Effective::EmailTemplate.find_or_initialize_by(template_name: name)
|
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.1.
|
4
|
+
version: 1.1.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: 2021-
|
11
|
+
date: 2021-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- app/controllers/admin/email_templates_controller.rb
|
93
93
|
- app/datatables/effective_email_templates_datatable.rb
|
94
94
|
- app/helpers/effective_email_templates_helper.rb
|
95
|
+
- app/mailers/concerns/effective_email_templates_mailer.rb
|
95
96
|
- app/mailers/effective/email_templates_mailer.rb
|
96
97
|
- app/models/concerns/has_one_email_review.rb
|
97
98
|
- app/models/effective/email_review.rb
|