premailer-rails 1.9.3 → 1.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88c3e4cb9ff7a5d1bcf7437242957d0882d5c783
4
- data.tar.gz: b89082332333a80f33437e2f424a3c77cf33ce88
3
+ metadata.gz: 6c72ab2474486b2defef2795a17b651f4333b3e4
4
+ data.tar.gz: 10be620db0873f11ebb75e25b0a2684f7e1b6eb0
5
5
  SHA512:
6
- metadata.gz: 16f4d14dcad194bc945ab41f360b88669428408d21e9035ac8c05b1c91095fb51f6658ec160f0ea3b8a1085acb17d253f45cc319d9862060802e2a6121c8e91a
7
- data.tar.gz: a7bd533d813480744b008ac7ba60418588e8c183aaec38c34df993e248ea613b7e3b1744df170180d06a76b589813dc233abf7bafacb72c278b212e0c6d797b3
6
+ metadata.gz: deafb4ba758c0881f42dba0e2c4a3b7da335d1e146d8e2fba30b66bf37f3e899de457ce5435ad95ae2902204cef00d0dee607af89919657256da6b655d9101a8
7
+ data.tar.gz: 00039726a8423529faacdb11788c649f072f7d0a8ff120f70b6476cbea90eb6588826bb63d4f5d13dae104eef0eac9e0ff0b450b9094e8d2c9eae77f77221a5e
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.9.4
4
+
5
+ - Improve check for Rails module
6
+ - Preserve body encoding to prevent garbled mails
7
+
3
8
  ## v1.9.3
4
9
 
5
10
  - Add support for rails' `relative_url_root` config
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.3
1
+ 1.9.4
@@ -14,6 +14,7 @@ class Premailer
14
14
 
15
15
  def asset_pipeline_present?
16
16
  defined?(::Rails) &&
17
+ ::Rails.respond_to?(:application) &&
17
18
  ::Rails.application.respond_to?(:assets) &&
18
19
  ::Rails.application.assets
19
20
  end
@@ -19,7 +19,9 @@ class Premailer
19
19
  end
20
20
 
21
21
  def development_env?
22
- defined?(::Rails) && ::Rails.env.development?
22
+ defined?(::Rails) &&
23
+ ::Rails.respond_to?(:env) &&
24
+ ::Rails.env.development?
23
25
  end
24
26
  end
25
27
  end
@@ -25,7 +25,8 @@ class Premailer
25
25
  end
26
26
 
27
27
  def asset_host_present?
28
- ::Rails.configuration.action_controller.asset_host.present?
28
+ ::Rails.respond_to?(:configuration) &&
29
+ ::Rails.configuration.action_controller.asset_host.present?
29
30
  end
30
31
 
31
32
  def asset_host(url)
@@ -70,17 +70,27 @@ class Premailer
70
70
  # can end up containing CSS rules.
71
71
  generate_text_part if generate_text_part?
72
72
 
73
- Mail::Part.new(
74
- content_transfer_encoding: html_part.content_transfer_encoding,
75
- content_type: "text/html; charset=#{html_part.charset}",
76
- body: premailer.to_inline_css)
73
+ part = html_part
74
+ html = premailer.to_inline_css
75
+ Mail::Part.new do
76
+ content_transfer_encoding part.content_transfer_encoding
77
+ content_type "text/html; charset=#{part.charset}"
78
+ body html
79
+ body_encoding part.body.encoding
80
+ end
77
81
  end
78
82
 
79
83
  def generate_text_part
80
- @text_part ||= Mail::Part.new(
81
- content_transfer_encoding: html_part.content_transfer_encoding,
82
- content_type: "text/plain; charset=#{html_part.charset}",
83
- body: premailer.to_plain_text)
84
+ @text_part ||= begin
85
+ part = html_part
86
+ text = premailer.to_plain_text
87
+ Mail::Part.new do
88
+ content_transfer_encoding part.content_transfer_encoding
89
+ content_type "text/plain; charset=#{part.charset}"
90
+ body text
91
+ body_encoding part.body.encoding
92
+ end
93
+ end
84
94
  end
85
95
 
86
96
  def premailer
@@ -5,6 +5,10 @@ describe Premailer::Rails::Hook do
5
5
  Premailer::Rails::Hook.perform(message)
6
6
  end
7
7
 
8
+ def body_content(message)
9
+ Nokogiri::HTML(message.html_string).at('body').content
10
+ end
11
+
8
12
  class Mail::Message
9
13
  def html_string
10
14
  (html_part || self).body.to_s
@@ -54,6 +58,18 @@ describe Premailer::Rails::Hook do
54
58
  end
55
59
  end
56
60
 
61
+ it 'does not screw up the text by maintaining the original body encoding' do
62
+ raw_msg = Fixtures::Message.latin_message
63
+ processed_msg = Fixtures::Message.latin_message
64
+ run_hook(processed_msg)
65
+ expect(body_content(processed_msg)).to eq(body_content(raw_msg))
66
+
67
+ raw_msg = Fixtures::Message.non_latin_message
68
+ processed_msg = Fixtures::Message.non_latin_message
69
+ run_hook(processed_msg)
70
+ expect(body_content(processed_msg)).to eq(body_content(raw_msg))
71
+ end
72
+
57
73
  it 'generates a text part from the html' do
58
74
  expect { run_hook(message) }.to change(message, :text_part)
59
75
  end
@@ -114,6 +114,22 @@ nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
114
114
  message
115
115
  end
116
116
 
117
+ def latin_message
118
+ base_message.tap do |message|
119
+ message.body = HTML_PART
120
+ message.content_type 'text/html; charset=UTF-8'
121
+ message.ready_to_send!
122
+ end
123
+ end
124
+
125
+ def non_latin_message
126
+ base_message.tap do |message|
127
+ message.body = HTML_PART_WITH_UNICODE
128
+ message.content_type 'text/html; charset=UTF-8'
129
+ message.ready_to_send!
130
+ end
131
+ end
132
+
117
133
  private
118
134
 
119
135
  def base_message
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: premailer-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.3
4
+ version: 1.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipe Fatio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-12 00:00:00.000000000 Z
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: premailer