effective_email_templates 1.0.3 → 1.0.8

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: d25efc5fcbfdd39c8db6714777574361d0658757e68cfee0e88c075c0b84faa4
4
- data.tar.gz: fc54755485ddc9a80b081ea1448ce4b2ecbccdb546c1b08146dbc36982499100
3
+ metadata.gz: c84d011bfae37921bb40271777c47e7a3d2160152c0b408ab7dd76df71eea2e7
4
+ data.tar.gz: 9a4e13582f66232d044cf19eb5691f654313946b4a8eaa0b489b9d71b2cd9997
5
5
  SHA512:
6
- metadata.gz: 6727c12728c12a03a74c9b126b0a16a3c2bf12b16e2dcb8efc53c66b3f9efef9a0f71df34c4a97bf3336b6e1586e606b1ae91e3cbaccfbc833c4c0653c273f51
7
- data.tar.gz: cc09e802861ebbfb5564a6670fb8422c9acf9f522a5230ffdeeb56a0c5e5af7f42d80826335c4ada8cb36649b45a3589e7395228ce45b9541e0d9441d4c70a0a
6
+ metadata.gz: c8a0b4e52f4746b5e5a1d174133350838eed9e3ae2e6198400defcede6d4aad45fac66563c19cf4c9c32190f3e9226fe8df69af654029be9061037f1cf78750d
7
+ data.tar.gz: 30bed477a7ff6817bbe9b2a4887b69fca67b5bc4578de17951d336b4c3c1e50a2bcb87610d9ecef696f38b093ce16cedc6b877d4facd8dfe0ee59b7649c472c9
@@ -34,7 +34,11 @@ module Admin
34
34
  end
35
35
 
36
36
  def edit
37
- @email_template = Effective::EmailTemplate.find(params[:id])
37
+ @email_template =
38
+ Effective::EmailTemplate.where(id: params[:id]).or(
39
+ Effective::EmailTemplate.where(template_name: params[:id])
40
+ ).first!
41
+
38
42
  @page_title = 'Edit Email Template'
39
43
 
40
44
  authorize_effective_email_templates!
@@ -3,9 +3,9 @@ module EffectiveEmailTemplatesHelper
3
3
  def effective_email_review_fields(form, template_name)
4
4
  email_review = form.object.email_review
5
5
 
6
- email_review ||= begin
6
+ unless email_review&.template_name == template_name.to_s
7
7
  email_template = Effective::EmailTemplate.where(template_name: template_name).first!
8
- form.object.build_email_review(email_template: email_template)
8
+ email_review = Effective::EmailReview.build(email_template: email_template)
9
9
  end
10
10
 
11
11
  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
@@ -3,11 +3,13 @@ module Effective
3
3
  include ActiveModel::Model
4
4
 
5
5
  attr_accessor :email_template
6
+ attr_accessor :template_name
6
7
  attr_accessor :body
7
8
 
8
9
  def self.build(attributes = {})
9
10
  new(attributes).tap do |email_review|
10
11
  email_review.body ||= email_review.email_template&.body
12
+ email_review.template_name ||= email_review.email_template&.template_name
11
13
  end
12
14
  end
13
15
 
@@ -21,5 +23,9 @@ module Effective
21
23
  end
22
24
  end
23
25
 
26
+ def email_template
27
+ @email_template ||= Effective::EmailTemplate.where(template_name: template_name).first
28
+ end
29
+
24
30
  end
25
31
  end
@@ -2,6 +2,8 @@ module Effective
2
2
  class EmailTemplate < ActiveRecord::Base
3
3
  self.table_name = EffectiveEmailTemplates.email_templates_table_name.to_s
4
4
 
5
+ log_changes if respond_to?(:log_changes)
6
+
5
7
  CONTENT_TYPES = ['text/plain', 'text/html']
6
8
 
7
9
  # Attributes
@@ -49,14 +51,14 @@ module Effective
49
51
  def render(assigns = {})
50
52
  assigns = deep_stringify_assigns(assigns)
51
53
 
52
- {
54
+ result = {
53
55
  from: from,
54
- cc: cc.presence || false,
55
- bcc: bcc.presence || false,
56
+ cc: cc.presence,
57
+ bcc: bcc.presence,
56
58
  content_type: content_type,
57
59
  subject: template_subject.render(assigns),
58
60
  body: template_body.render(assigns)
59
- }
61
+ }.compact
60
62
  end
61
63
 
62
64
  def template_variables
@@ -1,2 +1,13 @@
1
1
  = form.fields_for(:email_review, email_review) do |f|
2
- = f.text_area :body, rows: 10
2
+ = f.hidden_field :template_name
3
+ = f.text_area :body, required: true, rows: 10
4
+
5
+ = collapse('Show / hide email variables') do
6
+ %p The available variables are:
7
+
8
+ %ul
9
+ - Array(f.object.email_template&.template_variables).each do |variable|
10
+ %li {{ #{variable} }}
11
+
12
+ %small.text-muted Only a developer can add additional variables
13
+
@@ -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.3'.freeze
2
+ VERSION = '1.0.8'.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.3
4
+ version: 1.0.8
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: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails