actionmailer_inline_css 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,9 +5,7 @@ gem 'rake'
5
5
  gemspec
6
6
 
7
7
  group :development, :test do
8
- unless ENV['TRAVIS']
9
- gem 'ruby-debug', :platform => :mri_18
10
- gem 'ruby-debug19', :platform => :mri_19, :require => 'ruby-debug'
11
- end
8
+ gem 'ruby-debug', :platforms => :mri_18
9
+ gem 'ruby-debug19', :platforms => :mri_19
12
10
  end
13
11
 
data/README.md CHANGED
@@ -42,8 +42,12 @@ To use this in your Rails app, simply add `gem "actionmailer_inline_css"` to you
42
42
 
43
43
  #### NOTE:
44
44
 
45
- The current version of premailer doesn't support UTF-8, so I have written a small
46
- workaround to enforce it. This works for both Ruby 1.9 and 1.8.
45
+ The current version of premailer doesn't support UTF-8, so this gem has some built-in workarounds.
46
+ These work for both Ruby 1.9 and 1.8.
47
+
48
+ * Premailer's Nokogiri adapter has been patched to force UTF-8 encoding for the input html.
49
+ * The email's HTML part is always encoded and sent with a transfer type of <tt>base64</tt>.
50
+ (The default 'quoted-printable' type escapes '=' and '?' symbols.)
47
51
 
48
52
 
49
53
  ### Including CSS in Mail Templates
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "actionmailer_inline_css"
3
- s.version = "1.2.1"
3
+ s.version = "1.3.0"
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
  s.summary = "Always send HTML e-mails with inline CSS, using the 'premailer' gem"
6
6
  s.email = "nathan.f77@gmail.com"
@@ -1,3 +1,4 @@
1
+ require 'base64'
1
2
  #
2
3
  # Always inline CSS for HTML emails
3
4
  #
@@ -5,20 +6,23 @@ module ActionMailer
5
6
  class InlineCssHook
6
7
  def self.delivering_email(message)
7
8
  if html_part = (message.html_part || (message.content_type =~ /text\/html/ && message))
8
- premailer = ::Premailer.new(html_part.body.to_s, :with_html_string => true)
9
+ premailer = Premailer.new(html_part.body.to_s, :with_html_string => true)
9
10
  existing_text_part = message.text_part && message.text_part.body.to_s
11
+
10
12
  # Reset the body
11
13
  message.body = nil
12
- # Add an HTML part with CSS inlined.
13
- message.html_part do
14
- content_type "text/html; charset=utf-8"
15
- body premailer.to_inline_css
16
- end
14
+
17
15
  # Add a text part with either the pre-existing text part, or one generated with premailer.
18
16
  message.text_part do
19
- content_type "text/plain; charset=utf-8"
20
17
  body existing_text_part || premailer.to_plain_text
21
18
  end
19
+
20
+ # Add an HTML part with CSS inlined.
21
+ message.html_part do
22
+ content_type "text/html; charset=utf-8"
23
+ content_transfer_encoding "base64"
24
+ body Base64.encode64(premailer.to_inline_css)
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -6,8 +6,7 @@ Premailer::Adapter::Nokogiri.module_eval do
6
6
  def load_html(html)
7
7
  # Force UTF-8 encoding
8
8
  if RUBY_VERSION =~ /1.9/
9
- html = html.force_encoding('UTF-8').encode!
10
- doc = ::Nokogiri::HTML(html) {|c| c.recover }
9
+ doc = ::Nokogiri::HTML(html.encode('UTF-8')) {|c| c.recover }
11
10
  else
12
11
  doc = ::Nokogiri::HTML(html, nil, 'UTF-8') {|c| c.recover }
13
12
  end
@@ -58,22 +58,31 @@ end
58
58
  class InlineCssHookTest < ActionMailer::TestCase
59
59
  def test_inline_css_hook_with_only_html_part
60
60
  mail = HelperMailer.use_inline_css_hook_with_only_html_part.deliver
61
- assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.body.encoded
61
+ assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.decoded
62
62
  # Test generated text part
63
- assert_match 'Test', mail.text_part.body.encoded
63
+ assert_match 'Test', mail.text_part.decoded
64
64
  end
65
65
 
66
66
  def test_inline_css_hook_with_text_and_html_parts
67
67
  mail = HelperMailer.use_inline_css_hook_with_text_and_html_parts.deliver
68
- assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.body.encoded
68
+ assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.decoded
69
69
  # Test specified text part
70
- assert_match 'Different Text Part', mail.text_part.body.encoded
70
+ assert_match 'Different Text Part', mail.text_part.decoded
71
71
  end
72
72
 
73
73
  def test_inline_css_hook_with_utf_8_characters
74
74
  mail = HelperMailer.use_inline_css_hook_with_utf_8.deliver
75
- assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ', mail.html_part.body.encoded
76
- assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ', mail.text_part.body.encoded
75
+
76
+ html, text = mail.html_part.body.decoded, mail.text_part.body.decoded
77
+ if RUBY_VERSION =~ /1.9/
78
+ # In Ruby 1.9, Mail does not set encoding to UTF-8 when decoding the Base64 string.
79
+ # This is an internal issue, and not a problem for email clients.
80
+ html, text = html.force_encoding('UTF-8'), text.force_encoding('UTF-8')
81
+ end
82
+
83
+ [html, text].each do |part|
84
+ assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ', part
85
+ end
77
86
  end
78
87
  end
79
88
 
@@ -33,7 +33,7 @@ class PremailerStylesheetLinkTagTest < ActionMailer::TestCase
33
33
  File.stubs(:read).returns(css_file)
34
34
 
35
35
  mail = HelperMailer.use_stylesheet_link_tag.deliver
36
- assert_match "<div class=\"test\" style=\"color: #119911;\">", mail.html_part.body.encoded
36
+ assert_match "<div class=\"test\" style=\"color: #119911;\">", mail.html_part.decoded
37
37
  end
38
38
  end
39
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmailer_inline_css
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-30 00:00:00.000000000Z
12
+ date: 2011-09-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
16
- requirement: &79452640 !ruby/object:Gem::Requirement
16
+ requirement: &21170660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *79452640
24
+ version_requirements: *21170660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: premailer
27
- requirement: &79451970 !ruby/object:Gem::Requirement
27
+ requirement: &21170080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.7.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *79451970
35
+ version_requirements: *21170080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &79451160 !ruby/object:Gem::Requirement
38
+ requirement: &21169420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.4.4
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *79451160
46
+ version_requirements: *21169420
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mocha
49
- requirement: &79450260 !ruby/object:Gem::Requirement
49
+ requirement: &21168680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.10.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *79450260
57
+ version_requirements: *21168680
58
58
  description: Module for ActionMailer to improve the rendering of HTML emails by using
59
59
  the 'premailer' gem, which inlines CSS and makes relative links absolute.
60
60
  email: nathan.f77@gmail.com
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: 455282451
92
+ hash: 2714414003163735864
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
@@ -98,10 +98,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  segments:
100
100
  - 0
101
- hash: 455282451
101
+ hash: 2714414003163735864
102
102
  requirements: []
103
103
  rubyforge_project:
104
- rubygems_version: 1.8.10
104
+ rubygems_version: 1.8.8
105
105
  signing_key:
106
106
  specification_version: 3
107
107
  summary: Always send HTML e-mails with inline CSS, using the 'premailer' gem