Commit 98a340849c198fad49fedb965812f139494676d3

Authored by Nathan Broadbent
1 parent 7a0a865f
Exists in master and in 1 other branch production

Reorganized Actionmailer inline CSS code. Use sensible default path for mailer s…

…tylesheets. Module is small enough to live in initializer.
config/initializers/actionmailer_inline_css.rb 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +#
  2 +# ActionMailer module for inline css in html emails
  3 +#
  4 +module ActionMailer::InlineCss
  5 + def render(*args)
  6 + if (template = args.first[:template]) && template.mime_type.html?
  7 + premailer = Premailer.new(super, :with_html_string => true,
  8 + :css => default_params[:css] ||
  9 + ["#{Rails.root}/public/stylesheets/mailers/#{mailer_name}.css"])
  10 + premailer.to_inline_css
  11 + else
  12 + super
  13 + end
  14 + end
  15 +end
  16 +
  17 +ActionMailer::Base.send :include, ActionMailer::InlineCss
  18 +
config/initializers/inline_css.rb
@@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
1 -require 'inline_css'  
2 -  
lib/inline_css.rb
@@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
1 -#  
2 -# module for ActionMailer to inline css in html emails  
3 -#  
4 -module InlineCss  
5 - def render(*args)  
6 - if (template = args.first[:template]) && template.mime_type.html?  
7 - premailer = Premailer.new(super,  
8 - :with_html_string => true,  
9 - :css => [Rails.root.join("public/stylesheets/email.css").to_s])  
10 - premailer.to_inline_css  
11 - else  
12 - super  
13 - end  
14 - end  
15 -end  
16 -  
17 -ActionMailer::Base.send :include, InlineCss  
18 -  
public/stylesheets/email.css
@@ -1,55 +0,0 @@ @@ -1,55 +0,0 @@
1 -td.header {  
2 - padding: 10px 20px 8px 20px;  
3 - height: 70px;  
4 - background-color: #11112f;  
5 - text-align: left;  
6 - border-bottom: 1px solid #ccccee;  
7 -}  
8 - td.header a {  
9 - display: block;  
10 - height: 31px;  
11 - width: 88px;  
12 - margin-top: 4px;  
13 - }  
14 - /* Style 'Errbit' logo alt text if image cannot be loaded. */  
15 - td.header a img {  
16 - border: none;  
17 - color: #E3E3E3;  
18 - font-family: helvetica;  
19 - font-size: 30px;  
20 - font-weight: bold;  
21 - min-height: 31px;  
22 - text-shadow: 0 1px 0 #EEEEFF;  
23 - }  
24 -  
25 -td.section, td.content, td.footer {  
26 - font-family: Helvetica,Arial,sans-serif;  
27 - font-size: 14px;  
28 - background-color: #ffffff;  
29 - text-align: left;  
30 -}  
31 -td.section {  
32 - padding: 0;  
33 - border-bottom: 1px solid #dddddd;  
34 -}  
35 -td.content {  
36 - padding: 20px 20px 10px 20px;  
37 - line-height: 1.3em;  
38 -}  
39 -td.footer {  
40 - padding: 10px 20px 20px 20px;  
41 - font-size: 11px;  
42 - font-weight: bold;  
43 - color: #666666;  
44 -}  
45 -  
46 -a.bold, span.bold { font-weight: bold; }  
47 -  
48 -p { margin: 0 0 15px 0; }  
49 -p.heading {  
50 - color: #6a6a6a;  
51 - margin-bottom: 4px;  
52 -}  
53 -p.monospace, p.backtrace { font-family: monospace; }  
54 -p.backtrace { margin-bottom: 2px; }  
55 -  
public/stylesheets/mailers/mailer.css 0 → 100644
@@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
  1 +td.header {
  2 + padding: 10px 20px 8px 20px;
  3 + height: 70px;
  4 + background-color: #11112f;
  5 + text-align: left;
  6 + border-bottom: 1px solid #ccccee;
  7 +}
  8 + td.header a {
  9 + display: block;
  10 + height: 31px;
  11 + width: 88px;
  12 + margin-top: 4px;
  13 + }
  14 + /* Style 'Errbit' logo alt text if image cannot be loaded. */
  15 + td.header a img {
  16 + border: none;
  17 + color: #E3E3E3;
  18 + font-family: helvetica;
  19 + font-size: 30px;
  20 + font-weight: bold;
  21 + min-height: 31px;
  22 + text-shadow: 0 1px 0 #EEEEFF;
  23 + }
  24 +
  25 +td.section, td.content, td.footer {
  26 + font-family: Helvetica,Arial,sans-serif;
  27 + font-size: 14px;
  28 + background-color: #ffffff;
  29 + text-align: left;
  30 +}
  31 +td.section {
  32 + padding: 0;
  33 + border-bottom: 1px solid #dddddd;
  34 +}
  35 +td.content {
  36 + padding: 20px 20px 10px 20px;
  37 + line-height: 1.3em;
  38 +}
  39 +td.footer {
  40 + padding: 10px 20px 20px 20px;
  41 + font-size: 11px;
  42 + font-weight: bold;
  43 + color: #666666;
  44 +}
  45 +
  46 +a.bold, span.bold { font-weight: bold; }
  47 +
  48 +p { margin: 0 0 15px 0; }
  49 +p.heading {
  50 + color: #6a6a6a;
  51 + margin-bottom: 4px;
  52 +}
  53 +p.monospace, p.backtrace { font-family: monospace; }
  54 +p.backtrace { margin-bottom: 2px; }
  55 +
spec/mailers/mailer_spec.rb
@@ -5,11 +5,19 @@ describe Mailer do @@ -5,11 +5,19 @@ describe Mailer do
5 include EmailSpec::Helpers 5 include EmailSpec::Helpers
6 include EmailSpec::Matchers 6 include EmailSpec::Matchers
7 7
8 - it "should html-escape the notice's message for the html part" do 8 + before do
9 @notice = Factory(:notice, :message => "class < ActionController::Base") 9 @notice = Factory(:notice, :message => "class < ActionController::Base")
10 @email = Mailer.err_notification(@notice) 10 @email = Mailer.err_notification(@notice)
  11 + end
  12 +
  13 + it "should html-escape the notice's message for the html part" do
11 @email.should have_body_text("class &lt; ActionController::Base") 14 @email.should have_body_text("class &lt; ActionController::Base")
12 end 15 end
  16 +
  17 + it "should inline css" do
  18 + @email.should have_body_text '<td class="header" style="'
  19 + # ('style' attribute is not present unless premailer works.)
  20 + end
13 end 21 end
14 end 22 end
15 23