actionmailer-instyle 0.0.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard 'rspec', :version => 2 do
4
+ guard 'rspec', version: 2 do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
data/README.md CHANGED
@@ -1,46 +1,137 @@
1
1
  # ActionMailer::InStyle
2
2
 
3
- ![TestPilot Build Status](http://testpilot.me/testpilot/actionmailer-instyle.png)
3
+ [![TestPilot Build Status](http://testpilot.me/testpilot/actionmailer-instyle.png)](http://testpilot.me/testpilot/actionmailer-instyle)
4
4
 
5
- HTML Email is hard, especially when you find yourself wrestling with inline CSS to make it look good, luckily for you we're here to make it easy, ActionMailer::InStyle
6
- lets you write standard CSS, using Sass or the likes within the Rails 3.1 Asset Pipeline and automatically converts it to inline CSS using Premailer.
5
+ HTML Emails can be a PITN, especially when you want maximum email client compatibility, of which the best way to achieve this is inline CSS. Unfortunately nobody actually wants to be forced into writing crap like that so we've created **InStyle**, it will automatically intercept your emails and look for a `stylesheet` linking to something inside your assets folder, extract all the styles, and convert them to inline styles on the fly.
7
6
 
8
- ## Requirements
7
+ _There are a couple of other projects which do this, some have not been updated for a while and none of them work with the Rails 3.1 asset pipeline._ *InStyle* uses Sprockets to render CSS which means you can use Sass, Compass, and any other CSS hackery you desire, including using stylesheets you would usually only use within your views e.g If you want to email an activity digest and make it look the same as what the user is used to seeing within your application (think Yammer).
9
8
 
10
- This gem is built specifically to take advantage of the Rails 3.1 Asset Pipeline, as such you must be using Rails ~>3.1
9
+ ## Requirements
11
10
 
11
+ This gem is built specifically to take advantage of the Rails 3.1 Asset Pipeline, as such you must be using Rails ~>3.1 and have the Asset Pipeline enabled (default)
12
12
  _Additonally Ruby 1.8.7 is not supported due to favouring the Ruby 1.9 Hash syntax. If you want 1.8.7 support, issue a pull request._
13
13
 
14
14
  ## Installation
15
15
 
16
16
  Add this line to your application's Gemfile:
17
17
 
18
- gem 'actionmailer-instyle'
18
+ ```ruby
19
+ gem 'actionmailer-instyle', :require => 'action_mailer/in_style'
20
+ ```
19
21
 
20
22
  And then execute:
21
23
 
22
- $ bundle
24
+ ```bash
25
+ $ bundle
26
+ ```
23
27
 
24
28
  ## Usage
25
29
 
26
- Once installed it will add the required hooks out of the box.
30
+ Once installed it will add the required hooks out of the box to intercept each email being sent.
27
31
 
28
- *Stylesheets*
32
+ **Stylesheets**
29
33
 
30
34
  As with all your other stylesheets, put them in `app/assets/stylesheets` and include them into your mailer
31
- template using `stylesheet_include_tag "account_mailer"`, where `account_mailer` is the filename less the extension of the stylesheet you want to
32
- include.
35
+ template using `stylesheet_link_tag "account_mailer"`, where `account_mailer` is the filename less the extension of the stylesheet you want to use.
33
36
 
34
37
  Everything runs through the Asset Pipeline so you can use Sass simply by adding the `.scss` extension as you would with all other stylesheets.
35
38
 
36
- *Compass*
39
+ **Compass**
37
40
 
38
- Because Sass works out of the box, you can also include compass for browser specific mixins, keeping in mind that some email client (Outlook for example)
39
- use very crappy rendering engines and some CSS properties may have undesired effects or not work at all.
41
+ Because Sass works out of the box, you can also include Compass for browser specific mixins and useful CSS3 helpers, keeping in mind that some email clients (Outlook for example) use very dated rendering engines and a lot of CSS properties may have undesired effects or not work at all.
40
42
 
41
43
  For a complete rundown on what is supported, checkout this guide which CampaignMonitor has compiled.
42
44
 
43
- (CampaignMonitor's guide to CSS support in email)[http://www.campaignmonitor.com/css/]
45
+ [CampaignMonitor's guide to CSS support in email](http://www.campaignmonitor.com/css/)
46
+
47
+ ## Tutorial
48
+
49
+ **1. Generate a Mailer:**
50
+
51
+ rails g mailer account_mailer account_created_email
52
+
53
+ **2. Create a template to be used for emails this Mailer sends:**
54
+
55
+ In `app/views/layouts/account_mailer.html.haml`
56
+
57
+ ```haml
58
+ %html
59
+ %head
60
+ = stylesheet_link_tag "account_mailer"
61
+
62
+ %body
63
+ %table.main
64
+ %tr
65
+ %td= yield
66
+ ```
67
+
68
+ You will notice that we have added a stylesheet link in the `head`, this location is not crucial, but the use of `stylesheet_link_tag` is because it will generate a link which we can process and feed through Sprockets in order to generate the inline styles.
69
+
70
+ **3. The stylesheet.**
71
+
72
+ You can use any style off CSS you like, we're using Sass.
73
+
74
+ `app/assets/stylesheets/account_mailer.css.scss`:
75
+
76
+ ```css
77
+ body {
78
+ font-family: 'Helvetica Neue', Helvetica, sans-serif;
79
+ -webkit-font-smoothing: antialiased;
80
+ width: 100%;
81
+ background: darken(white, 8%);
82
+ }
83
+
84
+ table {
85
+ background: white;
86
+ &.main {
87
+ width: 430px;
88
+ tr td {
89
+ padding: 5px;
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ **4. Email views.**
96
+
97
+ In order to take advantage of all this fancy work, you must define a html view for your email, and optionally a text version. By default we will automatically generate a text version from the text content of the html view if none is supplied.
98
+
99
+ `app/views/account_mailer/account_created_email.html.haml`:
100
+
101
+ ```haml
102
+ %p Hi #{@user.first_name},
103
+ %p Your account has been successfully created, so don't waste any time, #{link_to "Get started now", get_started_url}
104
+ ```
105
+
106
+ **5. Send**
107
+
108
+ ```ruby
109
+ AccountMailer.account_created_email(@user).deliver
110
+ ```
111
+
112
+ **6. Send awesome emails.**
113
+
114
+ The resulting email will look something like this:
115
+
116
+ ```html
117
+ <html>
118
+ <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
119
+ <body style="font-family: 'Helvetica Neue', Helvetica, sans-serif; -webkit-font-smoothing: antialiased; width: 100%; background-color: #ebebeb;" bgcolor="#ebebeb">
120
+ <table style="width: 430px; background-color: white;" bgcolor="white">
121
+ <tr>
122
+ <td style="padding: 5px;">
123
+ <p>Hi Michael,</p>
124
+ <p>Your account has been successfully created, so don't waste any time, <a href="/started">Get started now</a></p>
125
+ </td>
126
+ </tr>
127
+ </table>
128
+ </body>
129
+ </html>
130
+ ```
131
+
132
+ **7. Grab a beer.**
133
+
134
+ As above.
44
135
 
45
136
  ## Contributing
46
137
 
@@ -49,3 +140,9 @@ For a complete rundown on what is supported, checkout this guide which CampaignM
49
140
  3. Commit your changes (`git commit -am 'Added some feature'`)
50
141
  4. Push to the branch (`git push origin my-new-feature`)
51
142
  5. Create new Pull Request
143
+
144
+ ## Meta
145
+
146
+ | Author | Twitter |
147
+ |------:|:------------|
148
+ | Ivan Vanderbyl | [@IvanVanderbyl](http://twitter.com/ivanvanderbyl) |
data/Rakefile CHANGED
@@ -4,5 +4,4 @@ require "bundler/gem_tasks"
4
4
  require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
7
- task :default => :spec
8
-
7
+ task default: :spec
@@ -17,7 +17,7 @@ module ActionMailer
17
17
  @message = message
18
18
 
19
19
  @existing_html_part = message.html_part || (message.content_type =~ /text\/html/ && message)
20
- @premailer = ActionMailer::InStyle::Premailer.new(html_part.body.to_s, :with_html_string => true, :remove_classes => true)
20
+ @premailer = ActionMailer::InStyle::Premailer.new(html_part.body.to_s, with_html_string: true, remove_classes: true)
21
21
  end
22
22
 
23
23
  def html_part
@@ -35,8 +35,8 @@ module ActionMailer
35
35
  capture_existing_message_parts
36
36
  reset_message_body!
37
37
 
38
- add_html_part!
39
38
  add_text_part!
39
+ add_html_part!
40
40
  add_attachments!
41
41
 
42
42
  message
@@ -47,8 +47,7 @@ module ActionMailer
47
47
  part = Mail::Part.new
48
48
  part.body = premailer.to_inline_css
49
49
  part.content_type = "text/html; charset=#{@msg_charset}"
50
-
51
- message.add_part(part)
50
+ message.html_part = part
52
51
  end
53
52
 
54
53
  # Add a text part with either the pre-existing text part, or one generated with premailer.
@@ -56,7 +55,7 @@ module ActionMailer
56
55
  part = Mail::Part.new
57
56
  part.body = @existing_text_part || premailer.to_plain_text
58
57
  part.content_type = "text/plain; charset=#{@msg_charset}"
59
- message.add_part(part)
58
+ message.text_part = part
60
59
  end
61
60
 
62
61
  # Re-add any attachments
@@ -1,5 +1,5 @@
1
1
  module ActionMailer
2
2
  module InStyle
3
- VERSION = "0.0.1"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ require "action_mailer/in_style"
@@ -0,0 +1,3 @@
1
+ require "action_mailer/in_style"
2
+
3
+ # This file serves only one purpose: TO allow bunder to automatically include this gem
@@ -4,15 +4,15 @@ class NotificationMailer < ActionMailer::Base
4
4
  default from: "Johnny Quids<quidlicker@example.com>"
5
5
 
6
6
  def welcome_email
7
- mail(to: "archie@example.com", :subject => "We need dry ice")
7
+ mail(to: "archie@example.com", subject: "We need dry ice")
8
8
  end
9
9
 
10
10
  def email_with_html_only
11
- mail(to: "archie@example.com", :subject => "We need dry ice")
11
+ mail(to: "archie@example.com", subject: "We need dry ice")
12
12
  end
13
13
 
14
14
  def welcome_html_email
15
- mail(to: "archie@example.com", :subject => "We need dry ice")
15
+ mail(to: "archie@example.com", subject: "We need dry ice")
16
16
  end
17
17
 
18
18
  end
@@ -4,7 +4,7 @@ class NotificationMailerNoStyle < ActionMailer::Base
4
4
  default from: "Johnny Quids<quidlicker@example.com>"
5
5
 
6
6
  def email_with_no_style
7
- mail(to: "archie@example.com", :subject => "We need dry ice")
7
+ mail(to: "archie@example.com", subject: "We need dry ice")
8
8
  end
9
9
  end
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmailer-instyle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.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: 2012-01-27 00:00:00.000000000 Z
12
+ date: 2012-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: premailer
16
- requirement: &70322805055240 !ruby/object:Gem::Requirement
16
+ requirement: &70161609476920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70322805055240
24
+ version_requirements: *70161609476920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70322805054720 !ruby/object:Gem::Requirement
27
+ requirement: &70161609476400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70322805054720
35
+ version_requirements: *70161609476400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &70322805054260 !ruby/object:Gem::Requirement
38
+ requirement: &70161609475940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.8.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70322805054260
46
+ version_requirements: *70161609475940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
- requirement: &70322805053880 !ruby/object:Gem::Requirement
49
+ requirement: &70161609475560 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70322805053880
57
+ version_requirements: *70161609475560
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sass
60
- requirement: &70322805053340 !ruby/object:Gem::Requirement
60
+ requirement: &70161609475020 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.1'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70322805053340
68
+ version_requirements: *70161609475020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &70322805052840 !ruby/object:Gem::Requirement
71
+ requirement: &70161609474520 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - =
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.3.5
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70322805052840
79
+ version_requirements: *70161609474520
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: mail
82
- requirement: &70322805052460 !ruby/object:Gem::Requirement
82
+ requirement: &70161609474140 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70322805052460
90
+ version_requirements: *70161609474140
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: nokogiri
93
- requirement: &70322805052000 !ruby/object:Gem::Requirement
93
+ requirement: &70161609473680 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70322805052000
101
+ version_requirements: *70161609473680
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: combustion
104
- requirement: &70322938609240 !ruby/object:Gem::Requirement
104
+ requirement: &70161605530780 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: 0.3.1
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70322938609240
112
+ version_requirements: *70161605530780
113
113
  description: Easily create HTML emails in Rails ~>3.1
114
114
  email:
115
115
  - ivanvanderbyl@me.com
@@ -130,6 +130,8 @@ files:
130
130
  - lib/action_mailer/in_style/premailer.rb
131
131
  - lib/action_mailer/in_style/processor.rb
132
132
  - lib/action_mailer/in_style/version.rb
133
+ - lib/action_mailer/instyle.rb
134
+ - lib/actionmailer-instyle.rb
133
135
  - spec/internal/app/assets/stylesheets/notification_mailer.css.scss
134
136
  - spec/internal/app/mailers/notification_mailer.rb
135
137
  - spec/internal/app/mailers/notification_mailer_no_layout.rb