effective_email_templates 1.0.6 → 1.0.11

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: 46c7c44b667283c6c335d71efd8c146395b621ee28d6f1e50838b6f72d918b91
4
- data.tar.gz: 43fecd6415a60000d4c9180bddfcba793c38f06920032eefd5d1bf7cba8fc77f
3
+ metadata.gz: dd45246572ae7b8d6eab683d911aba2fb4d74e2b9ac9f805fb6faea71ebef8b6
4
+ data.tar.gz: b37ed1adc75b8773d6c5caa57510e434b4537c2512bc63d1adf7b36d1ebe2939
5
5
  SHA512:
6
- metadata.gz: 516ed7e095f233a13486aed1a766631359b69ff0e7d53437f7f8b7114ef4d73c66f5a2114fa2c624666517256ca328b0f4f3448dcf275730b138b0a01a93bc99
7
- data.tar.gz: e5ab639194a6a53a66f9e69ab9353f64696ef558aad299d9c63680c6c4c8be8c1629ffd1b7f4f541a55926a84aa0edbc50decadeb6fdd67ddeb538abbc733eed
6
+ metadata.gz: 93297ce10d8e17183bd52a0c89cf393c42182a7ac4875669ac375f775a9a166770d7d6ffec1f7c9c385e4f40cb8f74e2f240ad2d428bc8b09dd2b4d8ddaaf5c4
7
+ data.tar.gz: 16a24643ba98a5ad269071eb992e3c73ae7f4d02cbab1c331b083cce8d45ad231e8c8a22a554e547aa94fb748aa98d62f5199a8391f6723778e889b50e5d8b03
@@ -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,19 @@
1
1
  module EffectiveEmailTemplatesHelper
2
2
 
3
- def effective_email_review_fields(form, template_name)
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
+ end
9
17
  end
10
18
 
11
19
  render(partial: 'effective/email_reviews/fields', locals: { email_review: email_review, form: form })
@@ -4,7 +4,7 @@
4
4
  module HasOneEmailReview
5
5
  extend ActiveSupport::Concern
6
6
 
7
- module ActiveRecord
7
+ module Base
8
8
  def has_one_email_review
9
9
  include ::HasOneEmailReview
10
10
  end
@@ -44,6 +44,20 @@ module Effective
44
44
  validates :content_type, presence: true, inclusion: { in: CONTENT_TYPES }
45
45
  validates :template_name, presence: true
46
46
 
47
+ # validate(if: -> { content_type == 'text/html' && body.present? }) do
48
+ # unless body.include?('<') && body.include?('>')
49
+ # self.errors.add(:content_type, 'expected html tags in body')
50
+ # self.errors.add(:body, 'expected html tags in body')
51
+ # end
52
+ # end
53
+
54
+ # validate(if: -> { content_type == 'text/plain' && body.present? }) do
55
+ # if body.include?('</a>') || body.include?('</p>')
56
+ # self.errors.add(:content_type, 'expected no html tags in body')
57
+ # self.errors.add(:body, 'expected no html tags in body')
58
+ # end
59
+ # end
60
+
47
61
  def to_s
48
62
  template_name.presence || 'New Email Template'
49
63
  end
@@ -51,14 +65,14 @@ module Effective
51
65
  def render(assigns = {})
52
66
  assigns = deep_stringify_assigns(assigns)
53
67
 
54
- {
68
+ result = {
55
69
  from: from,
56
- cc: cc.presence || false,
57
- bcc: bcc.presence || false,
70
+ cc: cc.presence,
71
+ bcc: bcc.presence,
58
72
  content_type: content_type,
59
73
  subject: template_subject.render(assigns),
60
74
  body: template_body.render(assigns)
61
- }
75
+ }.compact
62
76
  end
63
77
 
64
78
  def template_variables
@@ -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
- = f.select :content_type, Effective::EmailTemplate::CONTENT_TYPES
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
@@ -32,4 +32,7 @@ EffectiveEmailTemplates.setup do |config|
32
32
  admin_email_templates: 'admin'
33
33
  }
34
34
 
35
+ # Not allowed to select text/html by default
36
+ config.select_content_type = false
37
+
35
38
  end
@@ -6,6 +6,7 @@ module EffectiveEmailTemplates
6
6
 
7
7
  mattr_accessor :email_templates_table_name
8
8
  mattr_accessor :authorization_method
9
+ mattr_accessor :select_content_type
9
10
  mattr_accessor :layout
10
11
 
11
12
  def self.setup
@@ -10,7 +10,7 @@ module EffectiveEmailTemplates
10
10
  # Include has_one_email_review concern and allow any ActiveRecord object to call it
11
11
  initializer 'effective_email_templates.active_record' do |app|
12
12
  ActiveSupport.on_load :active_record do
13
- ActiveRecord::Base.extend(HasOneEmailReview::ActiveRecord)
13
+ ActiveRecord::Base.extend(HasOneEmailReview::Base)
14
14
  end
15
15
  end
16
16
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveEmailTemplates
2
- VERSION = '1.0.6'.freeze
2
+ VERSION = '1.0.11'.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.0.6
4
+ version: 1.0.11
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: 2020-04-17 00:00:00.000000000 Z
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -119,7 +119,7 @@ homepage: https://github.com/code-and-effect/effective_email_templates
119
119
  licenses:
120
120
  - MIT
121
121
  metadata: {}
122
- post_install_message:
122
+ post_install_message:
123
123
  rdoc_options: []
124
124
  require_paths:
125
125
  - lib
@@ -134,8 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
- rubygems_version: 3.0.3
138
- signing_key:
137
+ rubygems_version: 3.1.2
138
+ signing_key:
139
139
  specification_version: 4
140
140
  summary: Effective Email Templates provides an admin access to modify email templates
141
141
  test_files: []