effective_email_templates 0.3.3 → 0.3.4

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
  SHA1:
3
- metadata.gz: a750f7470cb2821cf09fcda4fada4b4128e43d0a
4
- data.tar.gz: 93aeb104da26368d60c81152fb69af94be98186a
3
+ metadata.gz: bbda63e6020c397791488952b40f7a399cecb631
4
+ data.tar.gz: 55b24c07d7248e8d3c888cd81203a291a23e3f0e
5
5
  SHA512:
6
- metadata.gz: 5edcec2f892ae8cbe1e945df57ea0895edae1faf245f0de80dd1eae5126009fc7bdf29ce9bdfd5f10a161942a4187f206c498bd1d67e8b5d90dec17d1bbd786d
7
- data.tar.gz: a889e773667891eefca64c1400f8ccb904010e4b3575375e5620904cf421edcb5a2f2d803b14fa71a83cb6dc5cc422793b19484160d67ce08977fe0a6d1427e0
6
+ metadata.gz: 07aec10a988bb330f44e0f8ee30fe33fda75a8de36234490ab999ccbb70ccf9d45ce0d0c0c1f41e2ca38f3b7b06183680e47d9a6c0014e4debd36779fad12dba
7
+ data.tar.gz: 8590029f42da810df46197674588f5b9e406bfd77d12601d91f0ca0b4111e754cfe9e0375deb7b3c9e6193201f4c1b624b87170bd5c71ccd5c7c2046947d4c53
@@ -2,11 +2,14 @@ module Effective
2
2
  class LiquidMailer < ::ActionMailer::Base
3
3
  def mail(headers = {}, &block)
4
4
  # this be dangerous and requires ruby 2.0+
5
- mail_method = caller_locations(1,1)[0].label
6
- email_template = EffectiveEmailTemplates.get(mail_method)
7
- headers = headers.merge(email_template.mail_options)
8
- super(headers, &block)
5
+ mail_method = caller_locations(1, 1)[0].label
6
+ options = EffectiveEmailTemplates.get(mail_method).mail_options
7
+
8
+ if options[:subject].present?
9
+ options[:subject] = Liquid::Template.parse(options[:subject]).render(@to_liquid) rescue options[:subject]
10
+ end
11
+
12
+ super(headers.merge(options), &block)
9
13
  end
10
14
  end
11
15
  end
12
-
@@ -1,3 +1,3 @@
1
1
  module EffectiveEmailTemplates
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
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: 0.3.3
4
+ version: 0.3.4
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: 2015-09-16 00:00:00.000000000 Z
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -209,9 +209,7 @@ files:
209
209
  - lib/effective_email_templates/engine.rb
210
210
  - lib/effective_email_templates/liquid_resolver.rb
211
211
  - lib/effective_email_templates/template_importer.rb
212
- - lib/effective_email_templates/template_importer.rb~
213
212
  - lib/effective_email_templates/version.rb
214
- - lib/effective_email_templates/version.rb~
215
213
  - lib/generators/effective_email_templates/install_generator.rb
216
214
  - lib/generators/templates/README
217
215
  - lib/generators/templates/effective_email_templates.rb
@@ -277,7 +275,6 @@ files:
277
275
  - spec/factories/user.rb
278
276
  - spec/factory_spec.rb
279
277
  - spec/lib/effective_email_templates/template_importer_spec.rb
280
- - spec/lib/effective_email_templates/template_importer_spec.rb~
281
278
  - spec/mailers/liquid_resolved_mailer_spec.rb
282
279
  - spec/models/email_template_spec.rb
283
280
  - spec/models/user_spec.rb
@@ -369,7 +366,6 @@ test_files:
369
366
  - spec/factories/user.rb
370
367
  - spec/factory_spec.rb
371
368
  - spec/lib/effective_email_templates/template_importer_spec.rb
372
- - spec/lib/effective_email_templates/template_importer_spec.rb~
373
369
  - spec/mailers/liquid_resolved_mailer_spec.rb
374
370
  - spec/models/email_template_spec.rb
375
371
  - spec/models/user_spec.rb
@@ -1,48 +0,0 @@
1
- module EffectiveEmailTemplates
2
- class TemplateImporter
3
- def self.invoke(importer = new)
4
- importer.invoke
5
- end
6
-
7
- def invoke
8
- binding.pry
9
- Dir[Rails.root.join('app', 'views', '**', '*.liquid')].each do |liquid_template_filepath|
10
- slug = File.basename(liquid_template_filepath, '.liquid')
11
- binding.pry
12
- next if Effective::EmailTemplate.where(slug: slug).present?
13
-
14
- template = Effective::EmailTemplate.new(slug: slug)
15
-
16
- file = File.new(liquid_template_filepath, "r")
17
- template = add_template_meta(file, template)
18
- template.body = extract_template_body(file)
19
- template.save
20
- print_errors(template, liquid_template_filepath) unless template.valid?
21
- end
22
- end
23
-
24
- private
25
-
26
- def add_template_meta(file, template)
27
- template.attributes = File.open(file) do |f|
28
- attr = YAML::load(f)
29
- attr.is_a?(Hash) ? attr : {}
30
- end
31
- template
32
- end
33
-
34
- def extract_template_body file
35
- contents = file.read
36
- return unless match = contents.match(/(---+(.|\n)+---+)/)
37
- contents.gsub(match[1], '').strip
38
- end
39
-
40
- def print_errors(template, liquid_template_filepath)
41
- puts "ERROR -- There was one or more validation errors while uploading:"
42
- puts " Email Template: #{liquid_template_filepath}"
43
- template.errors.each do |attribute, error|
44
- puts " -> #{attribute} #{error}"
45
- end
46
- end
47
- end
48
- end
@@ -1,3 +0,0 @@
1
- module EffectiveEmailTemplates
2
- VERSION = '0.3.2'
3
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
- require 'effective_email_templates/template_importer'
3
-
4
- describe EffectiveEmailTemplates::TemplateImporter do
5
-
6
- describe 'well formatted template files' do
7
- it 'imports templates from view files' do
8
- Effective::EmailTemplate.delete_all
9
- expect{ EffectiveEmailTemplates::TemplateImporter.invoke }.to change { Effective::EmailTemplate.count }
10
- end
11
-
12
- it 'does not import templates if a template already exists in the database' do
13
- Effective::EmailTemplate.delete_all
14
- expect{ EffectiveEmailTemplates::TemplateImporter.invoke }.to change { Effective::EmailTemplate.count }
15
- expect{ EffectiveEmailTemplates::TemplateImporter.invoke }.to_not change { Effective::EmailTemplate.count }
16
- end
17
-
18
- it 'does not print errors' do
19
- importer = EffectiveEmailTemplates::TemplateImporter.new
20
- expect(importer).to_not receive(:print_errors)
21
- EffectiveEmailTemplates::TemplateImporter.invoke(importer)
22
- end
23
- end
24
-
25
- describe 'poorly formatted template files' do
26
- let(:filepath) { Rails.root.join('app', 'views', 'user_liquid', 'some_template.liquid') }
27
- before do
28
- File.open(filepath, 'w') do |f|
29
- f.write("--\n---\nbody")
30
- end
31
- end
32
-
33
- after do
34
- File.delete(filepath)
35
- end
36
-
37
- it 'prints errors if there is a problem with a template' do
38
- importer = EffectiveEmailTemplates::TemplateImporter.new
39
- expect(importer).to receive(:print_errors)
40
- EffectiveEmailTemplates::TemplateImporter.invoke(importer)
41
- end
42
- end
43
- end