Skip to content

Commit

Permalink
Two-phase conversion to avoid requests deadlocks. Closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
guiocavalcanti committed Oct 11, 2011
1 parent f7c0d5c commit 081306d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 8 additions & 2 deletions lib/action_mailer/inline_css_hook.rb
Expand Up @@ -5,9 +5,15 @@ module ActionMailer
class InlineCssHook
def self.delivering_email(message)
if html_part = (message.html_part || (message.content_type =~ /text\/html/ && message))
# Generate an email with all CSS inlined (access CSS a FS path)
premailer = ::Premailer.new(html_part.body.to_s,
:with_html_string => true,
:base_url => message.header[:host].to_s)
:with_html_string => true)

# Prepend host to remaning URIs.
# Two-phase conversion to avoid request deadlock from dev. server (Issue #4)
premailer = ::Premailer.new(premailer.to_inline_css,
:with_html_string => true,
:base_url => message.header[:host].to_s)
existing_text_part = message.text_part && message.text_part.body.to_s
# Reset the body
message.body = nil
Expand Down
7 changes: 3 additions & 4 deletions test/premailer_stylesheet_link_tag_test.rb
Expand Up @@ -30,10 +30,9 @@ def mail_with_defaults(&block)

class PremailerStylesheetLinkTagTest < ActionMailer::TestCase
def test_premailer_stylesheet_link_tag
stub_request(:get, /example\.com\/*/).to_return do
css = "div.test { color: #119911; }"
{ :status => 200, :body => css }
end
css_file = "div.test { color: #119911; }"
File.stubs(:exist?).returns(true)
File.stubs(:read).returns(css_file)

mail = HelperMailer.use_stylesheet_link_tag.deliver
assert_match "<div class=\"test\" style=\"color: #119911;\">", mail.html_part.body.encoded
Expand Down

0 comments on commit 081306d

Please sign in to comment.