actionmailer_inline_css 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,7 +5,9 @@ gem 'rake'
5
5
  gemspec
6
6
 
7
7
  group :development, :test do
8
- gem 'ruby-debug', :platforms => :mri_18
9
- gem 'ruby-debug19', :platforms => :mri_19
8
+ unless ENV['TRAVIS']
9
+ gem 'ruby-debug', :platform => :mri_18
10
+ gem 'ruby-debug19', :platform => :mri_19, :require => 'ruby-debug'
11
+ end
10
12
  end
11
13
 
data/README.md CHANGED
@@ -42,12 +42,8 @@ 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 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.)
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.
51
47
 
52
48
 
53
49
  ### 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.3.0"
3
+ s.version = "1.3.1"
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,4 +1,3 @@
1
- require 'base64'
2
1
  #
3
2
  # Always inline CSS for HTML emails
4
3
  #
@@ -6,22 +5,19 @@ module ActionMailer
6
5
  class InlineCssHook
7
6
  def self.delivering_email(message)
8
7
  if html_part = (message.html_part || (message.content_type =~ /text\/html/ && message))
9
- premailer = Premailer.new(html_part.body.to_s, :with_html_string => true)
8
+ premailer = ::Premailer.new(html_part.body.to_s, :with_html_string => true)
10
9
  existing_text_part = message.text_part && message.text_part.body.to_s
11
-
12
10
  # Reset the body
13
11
  message.body = nil
14
-
15
- # Add a text part with either the pre-existing text part, or one generated with premailer.
16
- message.text_part do
17
- body existing_text_part || premailer.to_plain_text
18
- end
19
-
20
12
  # Add an HTML part with CSS inlined.
21
13
  message.html_part do
22
14
  content_type "text/html; charset=utf-8"
23
- content_transfer_encoding "base64"
24
- body Base64.encode64(premailer.to_inline_css)
15
+ body premailer.to_inline_css
16
+ end
17
+ # Add a text part with either the pre-existing text part, or one generated with premailer.
18
+ message.text_part do
19
+ content_type "text/plain; charset=utf-8"
20
+ body existing_text_part || premailer.to_plain_text
25
21
  end
26
22
  end
27
23
  end
@@ -6,7 +6,8 @@ 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
- doc = ::Nokogiri::HTML(html.encode('UTF-8')) {|c| c.recover }
9
+ html = html.force_encoding('UTF-8').encode!
10
+ doc = ::Nokogiri::HTML(html) {|c| c.recover }
10
11
  else
11
12
  doc = ::Nokogiri::HTML(html, nil, 'UTF-8') {|c| c.recover }
12
13
  end
@@ -58,31 +58,22 @@ 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.decoded
61
+ assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.body.encoded
62
62
  # Test generated text part
63
- assert_match 'Test', mail.text_part.decoded
63
+ assert_match 'Test', mail.text_part.body.encoded
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.decoded
68
+ assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.body.encoded
69
69
  # Test specified text part
70
- assert_match 'Different Text Part', mail.text_part.decoded
70
+ assert_match 'Different Text Part', mail.text_part.body.encoded
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
-
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
75
+ assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ', mail.html_part.body.encoded
76
+ assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ', mail.text_part.body.encoded
86
77
  end
87
78
  end
88
79
 
@@ -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.decoded
36
+ assert_match "<div class=\"test\" style=\"color: #119911;\">", mail.html_part.body.encoded
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.3.0
4
+ version: 1.3.1
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-19 00:00:00.000000000Z
12
+ date: 2011-09-30 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
16
- requirement: &21170660 !ruby/object:Gem::Requirement
16
+ requirement: &85500100 !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: *21170660
24
+ version_requirements: *85500100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: premailer
27
- requirement: &21170080 !ruby/object:Gem::Requirement
27
+ requirement: &85499400 !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: *21170080
35
+ version_requirements: *85499400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &21169420 !ruby/object:Gem::Requirement
38
+ requirement: &85498930 !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: *21169420
46
+ version_requirements: *85498930
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mocha
49
- requirement: &21168680 !ruby/object:Gem::Requirement
49
+ requirement: &85478310 !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: *21168680
57
+ version_requirements: *85478310
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: 2714414003163735864
92
+ hash: 62806209
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: 2714414003163735864
101
+ hash: 62806209
102
102
  requirements: []
103
103
  rubyforge_project:
104
- rubygems_version: 1.8.8
104
+ rubygems_version: 1.8.10
105
105
  signing_key:
106
106
  specification_version: 3
107
107
  summary: Always send HTML e-mails with inline CSS, using the 'premailer' gem