effective_email_templates 1.0.11 → 1.0.12

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: dd45246572ae7b8d6eab683d911aba2fb4d74e2b9ac9f805fb6faea71ebef8b6
4
- data.tar.gz: b37ed1adc75b8773d6c5caa57510e434b4537c2512bc63d1adf7b36d1ebe2939
3
+ metadata.gz: 4928f9db162ceb9b1b35fcbe367f38689be1f8977f75e46bff4e734c15f7ec90
4
+ data.tar.gz: 9129d4a60362284332fc2ab16685f0c325846dfe6f199cdd1e3924c974e3fb6e
5
5
  SHA512:
6
- metadata.gz: 93297ce10d8e17183bd52a0c89cf393c42182a7ac4875669ac375f775a9a166770d7d6ffec1f7c9c385e4f40cb8f74e2f240ad2d428bc8b09dd2b4d8ddaaf5c4
7
- data.tar.gz: 16a24643ba98a5ad269071eb992e3c73ae7f4d02cbab1c331b083cce8d45ad231e8c8a22a554e547aa94fb748aa98d62f5199a8391f6723778e889b50e5d8b03
6
+ metadata.gz: 963de88d3ca0956517777a2445018ecf36bece45bf40165007403b49c347ed4a217d3d6438518318cedb25354694473639da50845cab41cd29173575192acd8c
7
+ data.tar.gz: 06f6f69fea13c1405bb5e93576ed5779ca412db1955b7543effa2ced254a4af7e781154df370ae97cba887dfb962f29ca424d140040213b3442388f17e640d39
@@ -13,6 +13,7 @@ module EffectiveEmailTemplatesHelper
13
13
 
14
14
  if mail.present?
15
15
  email_review.body = mail.message.body
16
+ email_review.subject = mail.message.subject
16
17
  end
17
18
  end
18
19
 
@@ -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).tap do |email_review|
11
- email_review.body ||= email_review.email_template&.body
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
- validates :body, presence: true
17
-
18
- validate(if: -> { body.present? }) do
19
- begin
20
- Liquid::Template.parse(body)
21
- rescue Liquid::SyntaxError => e
22
- errors.add(:body, e.message)
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
- before_validation(if: -> { body.present? }) do
26
- begin
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
@@ -86,11 +73,11 @@ module Effective
86
73
  private
87
74
 
88
75
  def template_body
89
- Liquid::Template.parse(body)
76
+ Liquid::Template.parse(body_was || body)
90
77
  end
91
78
 
92
79
  def template_subject
93
- Liquid::Template.parse(subject)
80
+ Liquid::Template.parse(subject_was || subject)
94
81
  end
95
82
 
96
83
  def deep_stringify_assigns(assigns)
@@ -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
- Dir[Rails.root.join('app', 'views', '**', '*.liquid')].each do |filepath|
13
- name = File.basename(filepath, '.liquid')
14
- email_template = Effective::EmailTemplate.find_or_initialize_by(template_name: name)
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
- if email_template.persisted? && !overwrite
17
- puts("SKIPPED #{filename(filepath)}") unless quiet
18
- next
19
- end
17
+ if email_template.persisted? && !overwrite
18
+ puts("SKIPPED #{filename(filepath)}") unless quiet
19
+ next
20
+ end
20
21
 
21
- save(email_template, filepath, quiet: quiet)
22
+ save(email_template, filepath, quiet: quiet)
23
+ end
22
24
  end
23
25
  end
24
26
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveEmailTemplates
2
- VERSION = '1.0.11'.freeze
2
+ VERSION = '1.0.12'.freeze
3
3
  end
@@ -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.11
4
+ version: 1.0.12
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-09-04 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -115,6 +115,7 @@ 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