forked from premailer/actionmailer_inline_css
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed 'embedded_style_tag' helper, in favour of 'stylesheet_link_tag'
- Loading branch information
1 parent
3fe744b
commit 23b48ae
Showing
8 changed files
with
69 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
require 'premailer' | ||
require 'nokogiri' | ||
require 'action_mailer/inline_css_hook' | ||
require 'action_mailer/inline_css_helper' | ||
require 'overrides/premailer/premailer' | ||
|
||
ActionMailer::Base.register_interceptor ActionMailer::InlineCssHook | ||
ActionMailer::Base.send :helper, ActionMailer::InlineCssHelper | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'premailer' | ||
|
||
Premailer.class_eval do | ||
protected | ||
# When using the 'stylesheet_link_tag' helper in Rails, css URIs are given with | ||
# a leading slash and a cache buster (e.g. ?12412422). | ||
# This override handles these cases, while falling back to the default implementation. | ||
def load_css_from_local_file_with_rails_path!(path) | ||
rails_path = Rails.root.join("public", path.sub(/\?[0-9a-zA-Z]+$/, '').sub(/^\//, '')).to_s | ||
if File.exist?(rails_path) | ||
load_css_from_string(File.read(rails_path)) | ||
else | ||
load_css_from_local_file_without_rails_path!(path) | ||
end | ||
end | ||
alias_method_chain :load_css_from_local_file!, :rails_path | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'abstract_unit' | ||
|
||
ENV["RAILS_ASSET_ID"] = "123456" | ||
|
||
class HelperMailer < ActionMailer::Base | ||
def use_stylesheet_link_tag | ||
mail_with_defaults do |format| | ||
format.html { render(:inline => %Q{ | ||
<html> | ||
<head> | ||
<%= stylesheet_link_tag 'mailers/mailer' %> | ||
</head> | ||
<body> | ||
<div class="test">Test</div> | ||
</body> | ||
</html> | ||
}) } | ||
end | ||
end | ||
|
||
protected | ||
|
||
def mail_with_defaults(&block) | ||
mail(:to => "test@localhost", :from => "tester@example.com", | ||
:subject => "using helpers", &block) | ||
end | ||
end | ||
|
||
class PremailerStylesheetLinkTagTest < ActionMailer::TestCase | ||
def test_premailer_stylesheet_link_tag | ||
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 | ||
end | ||
end | ||
|