Commit fc91d2f95b1c28647bb0c4c172fb30d80fc081b4

Authored by Nathan Broadbent
1 parent 5a8cf044
Exists in master and in 1 other branch production

Use 'tamtam' gem to inline CSS for html emails. Created shared mailer layouts. R…

…e-added full backtrace, as well as including the 'app_backtrace' in the WHERE section.
Gemfile
... ... @@ -16,6 +16,7 @@ gem 'octokit'
16 16 gem 'inherited_resources'
17 17 gem 'SystemTimer', :platform => :ruby_18
18 18 gem 'hoptoad_notifier', "~> 2.4"
  19 +gem 'tamtam'
19 20  
20 21 platform :ruby do
21 22 gem 'bson_ext', '~> 1.3.1'
... ...
Gemfile.lock
... ... @@ -75,6 +75,7 @@ GEM
75 75 hoptoad_notifier (2.4.11)
76 76 activesupport
77 77 builder
  78 + hpricot (0.8.4)
78 79 i18n (0.5.0)
79 80 inherited_resources (1.2.2)
80 81 has_scope (~> 0.5.0)
... ... @@ -177,6 +178,8 @@ GEM
177 178 typhoeus
178 179 ruby_core_source (0.1.5)
179 180 archive-tar-minitar (>= 0.5.2)
  181 + tamtam (0.0.3)
  182 + hpricot
180 183 thin (1.2.11)
181 184 daemons (>= 1.0.9)
182 185 eventmachine (>= 0.12.6)
... ... @@ -222,6 +225,7 @@ DEPENDENCIES
222 225 ruby-debug
223 226 ruby-debug19
224 227 ruby-fogbugz
  228 + tamtam
225 229 thin
226 230 useragent (~> 0.3.1)
227 231 webmock
... ...
app/mailers/mailer.rb
... ... @@ -3,6 +3,8 @@
3 3 require Rails.root.join('config/routes.rb')
4 4  
5 5 class Mailer < ActionMailer::Base
  6 + include InlineCss
  7 +
6 8 default :from => Errbit::Config.email_from
7 9  
8 10 def err_notification(notice)
... ...
app/views/layouts/mailer.html.haml 0 → 100644
... ... @@ -0,0 +1,70 @@
  1 +%html
  2 + %head
  3 + :css
  4 + td.header {
  5 + padding: 10px 20px 10px 20px;
  6 + height: 75px;
  7 + background-color: #11112f;
  8 + text-align: left;
  9 + border-bottom: 1px solid #ccccee;
  10 + }
  11 + td.header a {
  12 + display: block;
  13 + height: 31px;
  14 + width: 88px;
  15 + margin-top: 10px;
  16 + }
  17 + td.header a img {
  18 + border: none;
  19 + }
  20 +
  21 + td.section, td.content, td.footer {
  22 + font-family: Helvetica,Arial,sans-serif;
  23 + font-size: 14px;
  24 + background-color: #ffffff;
  25 + text-align: left;
  26 + }
  27 + td.section {
  28 + padding: 0;
  29 + border-bottom: 1px solid #dddddd;
  30 + }
  31 + td.content {
  32 + padding: 20px 20px 10px 20px;
  33 + line-height: 1.3em;
  34 + }
  35 + td.footer {
  36 + padding: 10px 20px 20px 20px;
  37 + font-size: 11px;
  38 + font-weight: bold;
  39 + color: #666666;
  40 + }
  41 +
  42 + a.bold, span.bold { font-weight: bold; }
  43 +
  44 + p { margin: 0 0 15px 0; }
  45 + p.heading {
  46 + color: #6a6a6a;
  47 + margin-bottom: 4px;
  48 + }
  49 + p.monospace, p.backtrace { font-family: monospace; }
  50 + p.backtrace { margin-bottom: 2px; }
  51 +
  52 + %body
  53 + %div
  54 + %table(cellpadding="0" cellspacing="0" border="0" width="100%")
  55 + %tbody
  56 + %tr
  57 + %td.header
  58 + = link_to image_tag(URI.join(root_url,"stylesheets/images/logo.png").to_s), root_url
  59 +
  60 + = yield
  61 +
  62 + %table(cellpadding="0" cellspacing="0" border="0" align="left" width="100%")
  63 + %tbody
  64 + %tr
  65 + %td.footer
  66 + Your loyal servant,
  67 + = link_to 'Errbit', root_path
  68 +
  69 + %br
  70 +
... ...
app/views/layouts/mailer.text.erb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<%= yield %>
  2 +
  3 +
  4 +Your loyal servant,
  5 +Errbit
  6 +
... ...
app/views/mailer/_signature.html.haml
... ... @@ -1,7 +0,0 @@
1   -%table(cellpadding="0" cellspacing="0" border="0" align="left" width="100%")
2   - %tbody
3   - %tr
4   - %td(style="padding:10px 20px 20px 20px; font-size:11px; font-family:Helvetica,Arial,sans-serif; font-weight:bold; color:#666666; text-align:left; border-top:1px solid #dddddd;")
5   - Your loyal servant,
6   - = link_to 'Errbit', root_path
7   -
app/views/mailer/_signature.text.erb
... ... @@ -1,2 +0,0 @@
1   -Your loyal servant,
2   -Errbit
3 0 \ No newline at end of file
app/views/mailer/deploy_notification.text.erb
1 1 <%= @app.name %> was just deployed to <%= @deploy.environment %> by <%= @deploy.username %>.
2 2  
3 3 Details:
4   -
  4 +
5 5 What: <%= @app.name %><%= "@#{@deploy.revision}" unless @deploy.revision.blank? %>
6 6 When: <%= @deploy.created_at.to_s %>
7 7 From: <%= @deploy.repository.blank? ? 'n/a' : @deploy.repository %>
8 8  
9   -<%= render :partial => 'signature' %>
10 9 \ No newline at end of file
... ...
app/views/mailer/err_notification.html.haml
1   -%html
2   - %head
3   - %body
4   - %div
5   - %table(cellpadding="0" cellspacing="0" border="0" width="100%")
6   - %tbody
7   - %tr
8   - %td(style="padding:10px 20px 10px 20px; height: 75px; background-color: #11112f; text-align:left; border-bottom:1px solid #ccccee;")
9   - = link_to image_tag(URI.join(root_url,"stylesheets/images/logo.png").to_s, :style => "border: none;"), root_url, :style => "display: block; height: 31px; width: 88px; margin-top: 10px;"
10   - %tr
11   - %td(style="padding:0px 0px 10px 0px; font-family:Helvetica,Arial,sans-serif; font-size:14px; background-color:#ffffff; text-align:left; border-bottom:1px solid #dddddd;")
12   - %table(cellpadding="0" cellspacing="0" border="0" align="left")
13   - %tbody
14   - %tr
15   - %td(valign="top" style="padding:0px 20px 10px 20px; font-family:Helvetica,Arial,sans-serif; font-size:14px; background-color:#ffffff; text-align:left;")
16   - %div(style="line-height:1.3em;")
17   - %p(style="margin-top: 22px; margin-bottom:2px")
18   - An err has just occurred in
19   - = link_to(@app.name, app_url(@app), :style => "color:#000; font-weight: bold;") << ","
20   - on the
21   - %span(style="color:#000; font-weight: bold;")= @notice.err.environment
22   - environment.
23   - %p(style="margin-top: 0; margin-bottom:2px")
24   - This err has occurred #{pluralize @notice.err.notices_count, 'time'}.
25   - %p(style="padding:10px 0 5px 0; margin: 0;")
26   - = link_to("Click here to view the error on Errbit", app_err_url(@app, @notice.err), :style => "font-weight:bold;") << "."
27   - %tr
28   - %td(style="padding-top:0; padding-bottom:10px; text-align:left;")
29   - %table(cellpadding="0" cellspacing="0" border="0" align="left")
30   - %tbody
31   - %tr
32   - %td(valign="top" style="padding:10px 20px 10px 20px; font-family:Helvetica,Arial,sans-serif; font-size:14px; background-color:#ffffff; text-align:left;")
33   - %div(style="line-height:1.3em;")
34   - %p(style="color:#777777; margin-top: 10px; margin-bottom: 2px;")
35   - Error Message:
36   - %p(style="margin-top:0;")
37   - = raw(@notice.err.message)
38   - %p(style="color:#777777; padding:10px 0 0 0; margin-bottom:0px;")
39   - Where:
40   - %p(style="margin-top:0; font-family:monospace")
41   - = @notice.err.where
42   - %p(style="color:#777777; padding:10px 0 0 0; margin-bottom:0px;")
43   - URL:
44   - %p(style="margin-top:0; margin-bottom:0; font-family:monospace;")
45   - - if @notice.request['url'].present?
46   - = link_to @notice.request['url'], @notice.request['url']
47   - %p(style="color:#777777; padding:10px 0 0 0; margin-bottom:0px;")
48   - App Backtrace:
49   - - @notice.app_backtrace.map{|l| "#{l['file']}:#{l['number']}" }.each do |backtrace_line|
50   - %p(style="margin-top:0; margin-bottom:0; font-family:monospace")= backtrace_line
51   -
52   - = render :partial => 'signature'
53   - %br
  1 +%tr
  2 + %td.section
  3 + %table(cellpadding="0" cellspacing="0" border="0" align="left")
  4 + %tbody
  5 + %tr
  6 + %td.content(valign="top")
  7 + %div
  8 + %p
  9 + An err has just occurred in
  10 + = link_to(@app.name, app_url(@app), :class => "bold") << ","
  11 + on the
  12 + %span.bold= @notice.err.environment
  13 + environment.
  14 + %br
  15 + This err has occurred #{pluralize @notice.err.notices_count, 'time'}.
  16 + %p
  17 + = link_to("Click here to view the error on Errbit", app_err_url(@app, @notice.err), :class => "bold") << "."
  18 +%tr
  19 + %td.section
  20 + %table(cellpadding="0" cellspacing="0" border="0" align="left")
  21 + %tbody
  22 + %tr
  23 + %td.content(valign="top")
  24 + %div
  25 + %p.heading ERROR MESSAGE:
  26 + %p= raw(@notice.err.message)
  27 + %p.heading WHERE:
  28 + %p.monospace
  29 + = @notice.err.where
  30 + - if (app_backtrace = @notice.app_backtrace).any?
  31 + - app_backtrace.map {|l| "#{l['file']}:#{l['number']}" }.each do |line|
  32 + %p.backtrace= line
  33 + %br
  34 + %p.heading URL:
  35 + %p.monospace
  36 + - if @notice.request['url'].present?
  37 + = link_to @notice.request['url'], @notice.request['url']
  38 + %p.heading BACKTRACE:
  39 + - @notice.backtrace.map {|l| l ? "#{l['file']}:#{l['number']}" : nil }.compact.each do |line|
  40 + %p.backtrace= line
  41 + %br
54 42  
... ...
app/views/mailer/err_notification.text.erb
... ... @@ -7,5 +7,4 @@ This err has occurred &lt;%= pluralize @notice.err.notices_count, &#39;time&#39; %&gt;. You sh
7 7 Backtrace follows:
8 8  
9 9 <%= @notice.backtrace.collect { |l| l ? " #{l['file']}:#{l['number']}" : nil }.compact.join("\n") %>
10   -
11   -<%= render :partial => 'signature' %>
  10 +
... ...
config/initializers/inline_css.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +require 'inline_css'
  2 +
... ...
lib/inline_css.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  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 + # TamTam expects a <style> tag in the head of your layout.
  8 + TamTam.inline(:document => super)
  9 + else
  10 + super
  11 + end
  12 + end
  13 +end
  14 +
... ...