effective_email_templates 1.1.0 → 1.1.3

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: 42f8567bcf6351ab1762ee602ac678e4b63e8bbde2ae4e2c2858a7eff70a2a8d
4
- data.tar.gz: df20ca47c9a70a8a4867dc961da769db6f49a490fe80756e3fe9948b75dba5cc
3
+ metadata.gz: 8ba53c8fd6aed111fca06838d4095c43968032cd0b99dc14cccefb4781c74678
4
+ data.tar.gz: c460758e1f9faace00d5aa93b75f9bb8ec1658a990490a2486f9e569c25a0d9a
5
5
  SHA512:
6
- metadata.gz: c17a239840a85a12f9768b84be0315c7d0fddf924b435809af78bad8e203b145de905d40eef06d0473a18041e5483187deb4fc4db61df01428317d7c678a9974
7
- data.tar.gz: f10cfa33b6973e58b2b9e82a33c019b5ef7b8f532f23048682a6367e8e654304d61556c2a3a4e5de9114536d8a36deff4150301f68a107d462b0b3d47d1fd1c8
6
+ metadata.gz: af09166b147429ab8e85aaa7b3774a3aee90b762a57286d368cb3c0e1076d696d0489ebe850c69d872da52307658286b6874e73b75d5713c1012e8d86ec2b2e1
7
+ data.tar.gz: deabb27642aa03325530cc440f448df8b8a12bb2db15de4dad5bfc473e7b588c305ac9f677a34e2b264d9fb8c6586478e142e5f82781d3209cbd20792fb1e061
@@ -18,11 +18,15 @@ class EffectiveEmailTemplatesDatatable < Effective::Datatable
18
18
  end
19
19
 
20
20
  col :bcc do |email_template|
21
- html_escape(email_template.cc)
21
+ html_escape(email_template.bcc)
22
22
  end
23
23
 
24
24
  col :subject
25
- col :body
25
+
26
+ col :body do |email_template|
27
+ simple_format(email_template.body)
28
+ end
29
+
26
30
  col :content_type, visible: false
27
31
 
28
32
  actions_col
@@ -0,0 +1,35 @@
1
+ # Added to effective email templates mailers
2
+
3
+ module EffectiveEmailTemplatesMailer
4
+ extend ActiveSupport::Concern
5
+
6
+ def mail(headers = {}, &block)
7
+ email_template = Effective::EmailTemplate.where(template_name: action_name).first!
8
+ assigns = (@assigns || {})
9
+
10
+ # Parse assigns. Special keys for body and subject.
11
+ body = assigns.delete(:body) || headers[:body] || headers['body']
12
+ email_template.body = body if body.present?
13
+
14
+ # Ignore the subject when passed in via mail method subject: key.
15
+ subject = assigns.delete(: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
@@ -29,7 +29,7 @@ module Effective
29
29
  validates :subject, liquid: true
30
30
 
31
31
  validates :subject, presence: true
32
- validates :from, presence: true
32
+ validates :from, presence: true, email: true
33
33
  validates :body, presence: true
34
34
  validates :content_type, presence: true, inclusion: { in: CONTENT_TYPES }
35
35
  validates :template_name, presence: true
@@ -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
- ActionController::Base.view_paths.map(&:path).each do |path|
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)
@@ -1,3 +1,3 @@
1
1
  module EffectiveEmailTemplates
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.1.3'.freeze
3
3
  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.1.0
4
+ version: 1.1.3
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-06-24 00:00:00.000000000 Z
11
+ date: 2022-03-07 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