actionmailer_inline_css 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "actionmailer_inline_css"
3
- s.version = "1.4.0"
3
+ s.version = "1.5.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"
@@ -5,22 +5,37 @@ module ActionMailer
5
5
  class InlineCssHook
6
6
  def self.delivering_email(message)
7
7
  if html_part = (message.html_part || (message.content_type =~ /text\/html/ && message))
8
+ # Generate an email with all CSS inlined (access CSS a FS path)
8
9
  premailer = ::Premailer.new(html_part.body.to_s,
9
- :with_html_string => true,
10
- :base_url => message.header[:host].to_s)
10
+ :with_html_string => true)
11
+
12
+ # Prepend host to remaning URIs.
13
+ # Two-phase conversion to avoid request deadlock from dev. server (Issue #4)
14
+ premailer = ::Premailer.new(premailer.to_inline_css,
15
+ :with_html_string => true,
16
+ :base_url => message.header[:host].to_s)
11
17
  existing_text_part = message.text_part && message.text_part.body.to_s
18
+ existing_attachments = message.attachments
19
+
12
20
  # Reset the body
13
21
  message.body = nil
22
+
14
23
  # Add an HTML part with CSS inlined.
15
24
  message.html_part do
16
25
  content_type "text/html; charset=utf-8"
17
26
  body premailer.to_inline_css
18
27
  end
28
+
19
29
  # Add a text part with either the pre-existing text part, or one generated with premailer.
20
30
  message.text_part do
21
31
  content_type "text/plain; charset=utf-8"
22
32
  body existing_text_part || premailer.to_plain_text
23
33
  end
34
+
35
+ # Re-add any attachments
36
+ existing_attachments.each {|a| message.body << a }
37
+
38
+ message
24
39
  end
25
40
  end
26
41
  end
@@ -22,7 +22,8 @@ TEST_HTML_UTF8 = %Q{
22
22
  </style>
23
23
  </head>
24
24
  <body>
25
- <div id="test">ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ</div>
25
+ <div id="test">ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ</div>
26
+ <div id="author">Gonçalves</div>
26
27
  </body>
27
28
  </html>}
28
29
 
@@ -57,6 +58,7 @@ class HelperMailer < ActionMailer::Base
57
58
 
58
59
  def use_inline_css_hook_with_utf_8
59
60
  mail_with_defaults do |format|
61
+ charset "utf8"
60
62
  format.html { render(:inline => TEST_HTML_UTF8) }
61
63
  end
62
64
  end
@@ -67,12 +69,20 @@ class HelperMailer < ActionMailer::Base
67
69
  end
68
70
  end
69
71
 
72
+ def with_attachment
73
+ mail_with_defaults do |format|
74
+ attachments["hello"] = File.read('test')
75
+ format.html { render(:inline => TEST_HTML) }
76
+ end
77
+ end
78
+
70
79
  protected
71
80
 
72
81
  def mail_with_defaults(&block)
73
82
  mail(:to => "test@localhost", :from => "tester@example.com",
74
83
  :subject => "using helpers", &block)
75
84
  end
85
+
76
86
  end
77
87
 
78
88
 
@@ -92,9 +102,11 @@ class InlineCssHookTest < ActionMailer::TestCase
92
102
  end
93
103
 
94
104
  def test_inline_css_hook_with_utf_8_characters
105
+ mail = nil
95
106
  mail = HelperMailer.use_inline_css_hook_with_utf_8.deliver
96
- assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ', mail.html_part.body.encoded
97
- assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ', mail.text_part.body.encoded
107
+ assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ', mail.html_part.body.encoded
108
+ assert_match 'Gonçalves', mail.html_part.body.encoded
109
+ assert_match 'ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ', mail.text_part.body.encoded
98
110
  end
99
111
 
100
112
  def test_inline_css_hook_with_base_url
@@ -102,5 +114,15 @@ class InlineCssHookTest < ActionMailer::TestCase
102
114
  assert_match '<img src="http://www.example.com/images/test.png">',
103
115
  mail.html_part.body.encoded
104
116
  end
105
- end
106
117
 
118
+ def test_preservation_of_attachments
119
+ File.stubs(:read).returns("world")
120
+ mail = HelperMailer.with_attachment
121
+ assert mail.attachments["hello"].is_a?(Mail::Part)
122
+ original_hello_attachment_url = mail.attachments["hello"].url
123
+ m = ActionMailer::InlineCssHook.delivering_email(mail.deliver)
124
+ assert m.attachments["hello"].is_a?(Mail::Part)
125
+ assert_equal original_hello_attachment_url, mail.attachments["hello"].url
126
+ end
127
+
128
+ end
@@ -30,10 +30,9 @@ end
30
30
 
31
31
  class PremailerStylesheetLinkTagTest < ActionMailer::TestCase
32
32
  def test_premailer_stylesheet_link_tag
33
- stub_request(:get, /example\.com\/*/).to_return do
34
- css = "div.test { color: #119911; }"
35
- { :status => 200, :body => css }
36
- end
33
+ css_file = "div.test { color: #119911; }"
34
+ File.stubs(:exist?).returns(true)
35
+ File.stubs(:read).returns(css_file)
37
36
 
38
37
  mail = HelperMailer.use_stylesheet_link_tag.deliver
39
38
  assert_match "<div class=\"test\" style=\"color: #119911;\">", mail.html_part.body.encoded
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.4.0
4
+ version: 1.5.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-10-10 00:00:00.000000000Z
12
+ date: 2012-01-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
16
- requirement: &21313620 !ruby/object:Gem::Requirement
16
+ requirement: &73251340 !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: *21313620
24
+ version_requirements: *73251340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: premailer
27
- requirement: &21312220 !ruby/object:Gem::Requirement
27
+ requirement: &73251100 !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: *21312220
35
+ version_requirements: *73251100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &21310540 !ruby/object:Gem::Requirement
38
+ requirement: &73250870 !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: *21310540
46
+ version_requirements: *73250870
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mocha
49
- requirement: &21308720 !ruby/object:Gem::Requirement
49
+ requirement: &73250640 !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: *21308720
57
+ version_requirements: *73250640
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
@@ -87,21 +87,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- segments:
91
- - 0
92
- hash: 12308258948575913
93
90
  required_rubygems_version: !ruby/object:Gem::Requirement
94
91
  none: false
95
92
  requirements:
96
93
  - - ! '>='
97
94
  - !ruby/object:Gem::Version
98
95
  version: '0'
99
- segments:
100
- - 0
101
- hash: 12308258948575913
102
96
  requirements: []
103
97
  rubyforge_project:
104
- rubygems_version: 1.8.8
98
+ rubygems_version: 1.8.10
105
99
  signing_key:
106
100
  specification_version: 3
107
101
  summary: Always send HTML e-mails with inline CSS, using the 'premailer' gem