actionmailer_inline_css 1.1.0 → 1.2.0

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.
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
data/README.md CHANGED
@@ -5,24 +5,11 @@ Seamlessly integrate [Alex Dunae's premailer](http://premailer.dialect.ca/) gem
5
5
 
6
6
  ## Problem?
7
7
 
8
- The [Guide to CSS support in email](http://www.campaignmonitor.com/css/) from
9
- [campaignmonitor.com](http://www.campaignmonitor.com) shows that Gmail doesn't
10
- support `<style>` tags.
8
+ Gmail doesn't support `<style>` or `<link>` tags for HTML emails. Other webmail clients also
9
+ have problems with `<link>` tags.
11
10
 
12
- Thus, the only correct way to send HTML emails is when CSS is inlined on each element.
13
-
14
-
15
- ### [Email Client Popularity](http://www.campaignmonitor.com/stats/email-clients/):
16
-
17
- | Outlook | 27.62% |
18
- |------:|:------------|
19
- | iOS Devices | 16.01% |
20
- | Hotmail | 12.14% |
21
- | Apple Mail | 11.13% |
22
- | Yahoo! Mail | 9.54% |
23
- | Gmail | 7.02% |
24
-
25
- Gmail may only make up 7% of all email clients, but it's a percentage you can't ignore!
11
+ This means that CSS must be inlined on each element, otherwise
12
+ the email will not be displayed correctly in every client.
26
13
 
27
14
 
28
15
  ## Solution
@@ -33,12 +20,12 @@ Inlining CSS is a pain to do by hand, and that's where the
33
20
  From http://premailer.dialect.ca/:
34
21
 
35
22
  * CSS styles are converted to inline style attributes.
36
- Checks style and link[rel=stylesheet] tags and preserves existing inline attributes.
23
+ Checks <tt>style</tt> and <tt>link[rel=stylesheet]</tt> tags, and preserves existing inline attributes.
37
24
  * Relative paths are converted to absolute paths.
38
- Checks links in href, src and CSS url('')
25
+ Checks links in <tt>href</tt>, <tt>src</tt> and CSS <tt>url('')</tt>
39
26
 
40
27
 
41
- The <tt>actionmailer_inline_css</tt> gem is a tiny integration between ActionMailer and premailer.
28
+ This <tt>actionmailer_inline_css</tt> gem is a tiny integration between ActionMailer and premailer.
42
29
 
43
30
  Inspiration comes from [@fphilipe](https://github.com/fphilipe)'s
44
31
  [premailer-rails3](https://github.com/fphilipe/premailer-rails3) gem, but I wasn't
@@ -53,6 +40,11 @@ To use this in your Rails app, simply add `gem "actionmailer_inline_css"` to you
53
40
  * If you don't include a text email template, <tt>premailer</tt> will generate one from the HTML part.
54
41
  (Having said that, it is recommended that you write your text templates by hand.)
55
42
 
43
+ #### NOTE:
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.
47
+
56
48
 
57
49
  ### Including CSS in Mail Templates
58
50
 
@@ -64,8 +56,25 @@ these CSS URIs.
64
56
 
65
57
  Add the following line to the `<head>` section of <tt>app/views/layouts/build_mailer.html.erb</tt>:
66
58
 
67
- <%= stylesheet_link_tag 'mailers/build_mailer' %>
59
+ <%= stylesheet_link_tag '/stylesheets/mailers/build_mailer' %>
68
60
 
69
- This will add a stylesheet link for <tt>/stylesheets/mailers/build_mailer.css</tt>.
61
+ This will add a stylesheet link for <tt>public/stylesheets/mailers/build_mailer.css</tt>.
70
62
  Premailer will then inline the CSS from that file, and remove the link tag.
71
63
 
64
+
65
+ ## More Info
66
+
67
+ See this [Guide to CSS support in email](http://www.campaignmonitor.com/css/) from
68
+ [campaignmonitor.com](http://www.campaignmonitor.com) for more info about CSS in emails.
69
+
70
+
71
+ ### [Email Client Popularity](http://www.campaignmonitor.com/stats/email-clients/):
72
+
73
+ | Outlook | 27.62% |
74
+ |------:|:------------|
75
+ | iOS Devices | 16.01% |
76
+ | Hotmail | 12.14% |
77
+ | Apple Mail | 11.13% |
78
+ | Yahoo! Mail | 9.54% |
79
+ | Gmail | 7.02% |
80
+
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "actionmailer_inline_css"
3
- s.version = "1.1.0"
3
+ s.version = "1.2.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 = "[email protected]"
@@ -4,6 +4,7 @@
4
4
  module ActionMailer
5
5
  class InlineCssHook
6
6
  def self.delivering_email(message)
7
+ message.charset = 'UTF-8'
7
8
  if html_part = (message.html_part || (message.content_type =~ /text\/html/ && message))
8
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
@@ -2,6 +2,7 @@ require 'premailer'
2
2
  require 'nokogiri'
3
3
  require 'action_mailer/inline_css_hook'
4
4
  require 'overrides/premailer/premailer'
5
+ require 'overrides/premailer/adapter/nokogiri'
5
6
 
6
7
  ActionMailer::Base.register_interceptor ActionMailer::InlineCssHook
7
8
 
@@ -0,0 +1,18 @@
1
+ require 'premailer/adapter/nokogiri'
2
+
3
+ Premailer::Adapter::Nokogiri.module_eval do
4
+ # Patch load_html method to fix character encoding issues.
5
+ # Assume that actionmailer_inline_css will always be loading html from a UTF-8 string.
6
+ def load_html(html)
7
+ # Force UTF-8 encoding
8
+ if RUBY_VERSION =~ /1.9/
9
+ html = html.force_encoding('UTF-8').encode!
10
+ doc = ::Nokogiri::HTML(html) {|c| c.recover }
11
+ else
12
+ doc = ::Nokogiri::HTML(html, nil, 'UTF-8') {|c| c.recover }
13
+ end
14
+
15
+ return doc
16
+ end
17
+ end
18
+
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'abstract_unit'
2
4
 
3
5
  TEST_HTML = %Q{
@@ -12,6 +14,18 @@ TEST_HTML = %Q{
12
14
  </body>
13
15
  </html>}
14
16
 
17
+ TEST_HTML_UTF8 = %Q{
18
+ <html>
19
+ <head>
20
+ <style>
21
+ #test { color: #123456; }
22
+ </style>
23
+ </head>
24
+ <body>
25
+ <div id="test">ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ</div>
26
+ </body>
27
+ </html>}
28
+
15
29
  class HelperMailer < ActionMailer::Base
16
30
  def use_inline_css_hook_with_only_html_part
17
31
  mail_with_defaults do |format|
@@ -26,6 +40,12 @@ class HelperMailer < ActionMailer::Base
26
40
  end
27
41
  end
28
42
 
43
+ def use_inline_css_hook_with_utf_8
44
+ mail_with_defaults do |format|
45
+ format.html { render(:inline => TEST_HTML_UTF8) }
46
+ end
47
+ end
48
+
29
49
  protected
30
50
 
31
51
  def mail_with_defaults(&block)
@@ -49,5 +69,11 @@ class InlineCssHookTest < ActionMailer::TestCase
49
69
  # Test specified text part
50
70
  assert_match 'Different Text Part', mail.text_part.body.encoded
51
71
  end
72
+
73
+ def test_inline_css_hook_with_utf_8_characters
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
77
+ end
52
78
  end
53
79
 
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.1.0
4
+ version: 1.2.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-13 00:00:00.000000000Z
12
+ date: 2011-09-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
16
- requirement: &23025380 !ruby/object:Gem::Requirement
16
+ requirement: &13196380 !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: *23025380
24
+ version_requirements: *13196380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: premailer
27
- requirement: &23024840 !ruby/object:Gem::Requirement
27
+ requirement: &13195380 !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: *23024840
35
+ version_requirements: *13195380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &23024260 !ruby/object:Gem::Requirement
38
+ requirement: &13194580 !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: *23024260
46
+ version_requirements: *13194580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mocha
49
- requirement: &23023760 !ruby/object:Gem::Requirement
49
+ requirement: &13193500 !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: *23023760
57
+ version_requirements: *13193500
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: [email protected]
@@ -63,12 +63,14 @@ extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
65
  - .gitignore
66
+ - .travis.yml
66
67
  - Gemfile
67
68
  - README.md
68
69
  - Rakefile
69
70
  - actionmailer_inline_css.gemspec
70
71
  - lib/action_mailer/inline_css_hook.rb
71
72
  - lib/actionmailer_inline_css.rb
73
+ - lib/overrides/premailer/adapter/nokogiri.rb
72
74
  - lib/overrides/premailer/premailer.rb
73
75
  - test/abstract_unit.rb
74
76
  - test/inline_css_hook_test.rb
@@ -87,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
89
  version: '0'
88
90
  segments:
89
91
  - 0
90
- hash: 4032464049642912323
92
+ hash: 397510790940445982
91
93
  required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  none: false
93
95
  requirements:
@@ -96,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
98
  version: '0'
97
99
  segments:
98
100
  - 0
99
- hash: 4032464049642912323
101
+ hash: 397510790940445982
100
102
  requirements: []
101
103
  rubyforge_project:
102
104
  rubygems_version: 1.8.8
OSZAR »