actionmailer-instyle 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/Guardfile +17 -0
- data/LICENSE +22 -0
- data/README.md +51 -0
- data/Rakefile +8 -0
- data/actionmailer-instyle.gemspec +32 -0
- data/config.ru +7 -0
- data/lib/action_mailer/in_style.rb +21 -0
- data/lib/action_mailer/in_style/premailer.rb +34 -0
- data/lib/action_mailer/in_style/processor.rb +91 -0
- data/lib/action_mailer/in_style/version.rb +5 -0
- data/spec/internal/app/assets/stylesheets/notification_mailer.css.scss +9 -0
- data/spec/internal/app/mailers/notification_mailer.rb +18 -0
- data/spec/internal/app/mailers/notification_mailer_no_layout.rb +10 -0
- data/spec/internal/app/views/layouts/notification_mailer.html.erb +12 -0
- data/spec/internal/app/views/layouts/notification_mailer_without_style.html.erb +11 -0
- data/spec/internal/app/views/notification_mailer/email_with_html_only.html.erb +9 -0
- data/spec/internal/app/views/notification_mailer/welcome_html_email.html.erb +7 -0
- data/spec/internal/app/views/notification_mailer/welcome_html_email.text.erb +1 -0
- data/spec/internal/app/views/notification_mailer_no_style/email_with_no_style.html.erb +8 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/schema.rb +3 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/lib/action_mailer/inline/css_helper_spec.rb +9 -0
- data/spec/lib/action_mailer/inline/processor_spec.rb +73 -0
- data/spec/lib/action_mailer/inline_spec.rb +48 -0
- data/spec/spec_helper.rb +24 -0
- metadata +195 -0
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.sass-cache
|
19
|
+
|
20
|
+
spec/internal/db/combustion_test.sqlite
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color -f d
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ivan Vanderbyl
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# ActionMailer::InStyle
|
2
|
+
|
3
|
+
![TestPilot Build Status](http://testpilot.me/testpilot/actionmailer-instyle.png)
|
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.
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
|
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
|
11
|
+
|
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
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'actionmailer-instyle'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Once installed it will add the required hooks out of the box.
|
27
|
+
|
28
|
+
*Stylesheets*
|
29
|
+
|
30
|
+
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.
|
33
|
+
|
34
|
+
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
|
+
|
36
|
+
*Compass*
|
37
|
+
|
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.
|
40
|
+
|
41
|
+
For a complete rundown on what is supported, checkout this guide which CampaignMonitor has compiled.
|
42
|
+
|
43
|
+
(CampaignMonitor's guide to CSS support in email)[http://www.campaignmonitor.com/css/]
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/action_mailer/in_style/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ivan Vanderbyl"]
|
6
|
+
gem.email = ["ivanvanderbyl@me.com"]
|
7
|
+
gem.description = %q{Easily create HTML emails in Rails ~>3.1}
|
8
|
+
gem.summary = %q{This gem brings you the power of the premailer gem to Rails 3
|
9
|
+
without any configuration needs. Create HTML emails, include a
|
10
|
+
CSS file as you do in a normal HTML document and premailer will
|
11
|
+
inline the included CSS.}
|
12
|
+
gem.homepage = "http://github.com/testpilot/actionmailer-instyle"
|
13
|
+
|
14
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
gem.name = "actionmailer-instyle"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = ActionMailer::InStyle::VERSION
|
20
|
+
|
21
|
+
gem.add_dependency("premailer", ["~> 1.7"])
|
22
|
+
gem.add_dependency("rails", ["~> 3.1"])
|
23
|
+
|
24
|
+
gem.add_development_dependency 'rspec-rails', '~> 2.8.0'
|
25
|
+
gem.add_development_dependency 'guard-rspec'
|
26
|
+
gem.add_development_dependency 'sass', '~> 3.1'
|
27
|
+
gem.add_development_dependency 'sqlite3', '1.3.5'
|
28
|
+
gem.add_development_dependency 'mail'
|
29
|
+
gem.add_development_dependency 'nokogiri'
|
30
|
+
gem.add_development_dependency 'combustion', '~> 0.3.1'
|
31
|
+
|
32
|
+
end
|
data/config.ru
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "action_mailer/in_style/version"
|
2
|
+
require "action_mailer/base"
|
3
|
+
|
4
|
+
module ActionMailer
|
5
|
+
module InStyle
|
6
|
+
autoload :Processor, 'action_mailer/in_style/processor'
|
7
|
+
autoload :Premailer, 'action_mailer/in_style/premailer'
|
8
|
+
|
9
|
+
# delivering_email hook within Mail
|
10
|
+
#
|
11
|
+
# This is where the whole process kicks off.
|
12
|
+
def self.delivering_email(message)
|
13
|
+
# If the email contains a html part or is only html
|
14
|
+
if message.html_part || (message.content_type =~ /text\/html/ && message)
|
15
|
+
InStyle::Processor.inline!(message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
ActionMailer::Base.register_interceptor(ActionMailer::InStyle)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'premailer'
|
2
|
+
module ActionMailer
|
3
|
+
module InStyle
|
4
|
+
class Premailer < ::Premailer
|
5
|
+
|
6
|
+
def load_css_from_html!
|
7
|
+
load_css_from_asset_pipeline!
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
# Uses sprockets and the Rails ~>3.1 asset pipeline
|
12
|
+
# to load the compiled CSS from stylesheet links within the header of the
|
13
|
+
# email temoplate.
|
14
|
+
def load_css_from_asset_pipeline!
|
15
|
+
if tags = @doc.search("link[@rel='stylesheet'], style")
|
16
|
+
tags.each do |tag|
|
17
|
+
if tag.to_s.strip =~ /^\<link/i && tag.attributes['href'] && media_type_ok?(tag.attributes['media'])
|
18
|
+
|
19
|
+
# If the stylesheet link begins with /assets we must be using the asset pipeline
|
20
|
+
# to generate the css. In this case we should be able to retrieve the css directly
|
21
|
+
# from sprockets
|
22
|
+
if tag.attributes['href'].to_s =~ /\/assets\//
|
23
|
+
link_uri = tag.attributes['href'].to_s
|
24
|
+
asset = Rails.application.assets.find_asset(link_uri.sub(/\/assets\//, ''))
|
25
|
+
@css_parser.add_block!(asset.body) if asset
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require "premailer"
|
2
|
+
|
3
|
+
module ActionMailer
|
4
|
+
module InStyle
|
5
|
+
class Processor
|
6
|
+
|
7
|
+
def self.inline!(message)
|
8
|
+
new(message).inline!
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :message, :premailer
|
12
|
+
|
13
|
+
# Initialize
|
14
|
+
# Accepts one argument:
|
15
|
+
# - ActionMailer message object
|
16
|
+
def initialize(message)
|
17
|
+
@message = message
|
18
|
+
|
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)
|
21
|
+
end
|
22
|
+
|
23
|
+
def html_part
|
24
|
+
@existing_html_part
|
25
|
+
end
|
26
|
+
|
27
|
+
# InStyle!
|
28
|
+
# Processes the message object, replacing the html part with an inlined
|
29
|
+
# html version.
|
30
|
+
#
|
31
|
+
# If the message contains attachments or text parts, these parts are preserved.
|
32
|
+
# If the message does not contain a text part, one will be constructed from the text
|
33
|
+
# content available in the html part.
|
34
|
+
def inline!
|
35
|
+
capture_existing_message_parts
|
36
|
+
reset_message_body!
|
37
|
+
|
38
|
+
add_html_part!
|
39
|
+
add_text_part!
|
40
|
+
add_attachments!
|
41
|
+
|
42
|
+
message
|
43
|
+
end
|
44
|
+
|
45
|
+
# Add an HTML part with CSS inlined.
|
46
|
+
def add_html_part!
|
47
|
+
part = Mail::Part.new
|
48
|
+
part.body = premailer.to_inline_css
|
49
|
+
part.content_type = "text/html; charset=#{@msg_charset}"
|
50
|
+
|
51
|
+
message.add_part(part)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Add a text part with either the pre-existing text part, or one generated with premailer.
|
55
|
+
def add_text_part!
|
56
|
+
part = Mail::Part.new
|
57
|
+
part.body = @existing_text_part || premailer.to_plain_text
|
58
|
+
part.content_type = "text/plain; charset=#{@msg_charset}"
|
59
|
+
message.add_part(part)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Re-add any attachments
|
63
|
+
def add_attachments!
|
64
|
+
@existing_attachments.each {|a| message.body << a }
|
65
|
+
end
|
66
|
+
|
67
|
+
def capture_existing_message_parts
|
68
|
+
@existing_text_part = message.text_part && message.text_part.body.to_s
|
69
|
+
@existing_attachments = message.attachments
|
70
|
+
@msg_charset = message.charset
|
71
|
+
end
|
72
|
+
|
73
|
+
def original_message_parts
|
74
|
+
capture_existing_message_parts
|
75
|
+
|
76
|
+
{
|
77
|
+
html_part: html_part,
|
78
|
+
text_part: @existing_text_part,
|
79
|
+
attachments: @existing_attachments,
|
80
|
+
charset: @msg_charset
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def reset_message_body!
|
85
|
+
message.body = nil
|
86
|
+
message.body.instance_variable_set("@parts", Mail::PartsList.new)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class NotificationMailer < ActionMailer::Base
|
2
|
+
layout "notification_mailer"
|
3
|
+
|
4
|
+
default from: "Johnny Quids<quidlicker@example.com>"
|
5
|
+
|
6
|
+
def welcome_email
|
7
|
+
mail(to: "archie@example.com", :subject => "We need dry ice")
|
8
|
+
end
|
9
|
+
|
10
|
+
def email_with_html_only
|
11
|
+
mail(to: "archie@example.com", :subject => "We need dry ice")
|
12
|
+
end
|
13
|
+
|
14
|
+
def welcome_html_email
|
15
|
+
mail(to: "archie@example.com", :subject => "We need dry ice")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class NotificationMailerNoStyle < ActionMailer::Base
|
2
|
+
layout "notification_mailer_without_style"
|
3
|
+
|
4
|
+
default from: "Johnny Quids<quidlicker@example.com>"
|
5
|
+
|
6
|
+
def email_with_no_style
|
7
|
+
mail(to: "archie@example.com", :subject => "We need dry ice")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
Welcome this is a TEXT email
|
@@ -0,0 +1 @@
|
|
1
|
+
*.log
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ActionMailer::InStyle do
|
4
|
+
describe "CSS" do
|
5
|
+
it "Should return a CSS String" do
|
6
|
+
Rails.application.assets.find_asset('notification_mailer.css.scss').body.should match /font-family: 'Helvetica Neue', Helvetica, Ariel, sans-serif/
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ActionMailer::InStyle::Processor do
|
4
|
+
|
5
|
+
before do
|
6
|
+
ActionMailer::InStyle.stub(:delivering_email).and_return(message)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:message) { NotificationMailer.welcome_html_email.deliver }
|
10
|
+
let(:processor) { ActionMailer::InStyle::Processor.new(message) }
|
11
|
+
|
12
|
+
describe :message do
|
13
|
+
it "should have a html part" do
|
14
|
+
message.html_part.should_not be_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should initialize with a message object" do
|
19
|
+
processor.message.should == message
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should reset message body so we can replace it with the processed body" do
|
23
|
+
processor.message.should_receive(:body=).with(nil).once
|
24
|
+
processor.reset_message_body!
|
25
|
+
end
|
26
|
+
|
27
|
+
it "captures original html part" do
|
28
|
+
processor.original_message_parts[:html_part].should be_a Mail::Part
|
29
|
+
end
|
30
|
+
|
31
|
+
it "captures original text part" do
|
32
|
+
processor.original_message_parts[:text_part].should be_a String
|
33
|
+
end
|
34
|
+
|
35
|
+
it "captures original attachments" do
|
36
|
+
processor.original_message_parts[:attachments].should be_empty
|
37
|
+
end
|
38
|
+
|
39
|
+
it "captures message charset" do
|
40
|
+
processor.original_message_parts[:charset].should == 'UTF-8'
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'message' do
|
44
|
+
it 'should have two parts' do
|
45
|
+
message.parts.size.should == 2
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'html part' do
|
50
|
+
def parse_html_to_doc(html)
|
51
|
+
Nokogiri::HTML(html)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should have a html part' do
|
55
|
+
processor.html_part.should be_a Mail::Part
|
56
|
+
processor.html_part.body.should_not be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should include asset path for stylesheet in header' do
|
60
|
+
processor.html_part.body.should match /\<link(.+)href\=\"\/assets\/notification_mailer\.css\"(.+)\>/
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should have inlined css version without stylesheet links' do
|
64
|
+
processor.premailer.to_inline_css.should_not match /\<link(.+)href\=\"\/assets\/notification_mailer\.css\"(.+)\>/
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'replaces html body with inlined css version' do
|
68
|
+
processor.inline!
|
69
|
+
processor.html_part.body.should_not be_nil
|
70
|
+
parse_html_to_doc(processor.premailer.to_inline_css).css('body')[0].attributes['style'].to_s.should == "font-family: 'Helvetica Neue', Helvetica, Ariel, sans-serif; font-size: 13px; color: #4d4d4d;"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ActionMailer::InStyle do
|
4
|
+
it "is included in Mail interceptors" do
|
5
|
+
Mail.class_variable_get("@@delivery_interceptors").should include ActionMailer::InStyle
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:original_message) { NotificationMailer.welcome_html_email.deliver }
|
9
|
+
let(:message) { ActionMailer::InStyle.delivering_email(original_message) }
|
10
|
+
|
11
|
+
it "should keep text version of email if present" do
|
12
|
+
original_message.text_part.body.to_s.should == message.text_part.body.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have two body parts" do
|
16
|
+
message.parts.size.should == 2
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not have a style tag in original email" do
|
20
|
+
ActionMailer::InStyle.should_receive(:delivering_email).once
|
21
|
+
original_message = NotificationMailer.welcome_html_email.deliver
|
22
|
+
Nokogiri::HTML(original_message.html_part.body.to_s).css('body').first.attributes['style'].should be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should replace html version with premailer processed inline version" do
|
26
|
+
# If it has a style attribue then we have processed it
|
27
|
+
Nokogiri::HTML(message.html_part.body.to_s).css('body').first.attributes['style'].should_not be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should find stylesheet assets" do
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not do anything if no stylesheets are present" do
|
35
|
+
message_with_no_css = ActionMailer::InStyle.delivering_email(NotificationMailerNoStyle.email_with_no_style.deliver)
|
36
|
+
Nokogiri::HTML(message_with_no_css.html_part.body.to_s).css('body').first.attributes['style'].should be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should inline stylesheets and replace IDs and Classes" do
|
40
|
+
# According to the email template the first table usually has a 'striped' class
|
41
|
+
Nokogiri::HTML(message.html_part.body.to_s).css('table').first.attributes['class'].should be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should create a text part from the html part if not present" do
|
45
|
+
message = ActionMailer::InStyle.delivering_email(NotificationMailer.email_with_html_only.deliver)
|
46
|
+
message.text_part.body.to_s.should == "Welcome, this is a HTML email\n\nAnother line"
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
Bundler.require
|
5
|
+
|
6
|
+
require "rails"
|
7
|
+
require "combustion"
|
8
|
+
|
9
|
+
Combustion.initialize!
|
10
|
+
|
11
|
+
require 'rspec/rails'
|
12
|
+
|
13
|
+
require 'nokogiri'
|
14
|
+
require "combustion"
|
15
|
+
|
16
|
+
require 'action_mailer/in_style'
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.mock_with :rspec
|
20
|
+
|
21
|
+
config.before do
|
22
|
+
ActionMailer::Base.delivery_method = :test
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionmailer-instyle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ivan Vanderbyl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: premailer
|
16
|
+
requirement: &70322805055240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.7'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70322805055240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rails
|
27
|
+
requirement: &70322805054720 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.1'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70322805054720
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec-rails
|
38
|
+
requirement: &70322805054260 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.8.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70322805054260
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: guard-rspec
|
49
|
+
requirement: &70322805053880 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70322805053880
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: sass
|
60
|
+
requirement: &70322805053340 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '3.1'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70322805053340
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: &70322805052840 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - =
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.3.5
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70322805052840
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: mail
|
82
|
+
requirement: &70322805052460 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70322805052460
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: nokogiri
|
93
|
+
requirement: &70322805052000 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70322805052000
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: combustion
|
104
|
+
requirement: &70322938609240 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.3.1
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *70322938609240
|
113
|
+
description: Easily create HTML emails in Rails ~>3.1
|
114
|
+
email:
|
115
|
+
- ivanvanderbyl@me.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- .gitignore
|
121
|
+
- .rspec
|
122
|
+
- Gemfile
|
123
|
+
- Guardfile
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- actionmailer-instyle.gemspec
|
128
|
+
- config.ru
|
129
|
+
- lib/action_mailer/in_style.rb
|
130
|
+
- lib/action_mailer/in_style/premailer.rb
|
131
|
+
- lib/action_mailer/in_style/processor.rb
|
132
|
+
- lib/action_mailer/in_style/version.rb
|
133
|
+
- spec/internal/app/assets/stylesheets/notification_mailer.css.scss
|
134
|
+
- spec/internal/app/mailers/notification_mailer.rb
|
135
|
+
- spec/internal/app/mailers/notification_mailer_no_layout.rb
|
136
|
+
- spec/internal/app/views/layouts/notification_mailer.html.erb
|
137
|
+
- spec/internal/app/views/layouts/notification_mailer_without_style.html.erb
|
138
|
+
- spec/internal/app/views/notification_mailer/email_with_html_only.html.erb
|
139
|
+
- spec/internal/app/views/notification_mailer/welcome_html_email.html.erb
|
140
|
+
- spec/internal/app/views/notification_mailer/welcome_html_email.text.erb
|
141
|
+
- spec/internal/app/views/notification_mailer_no_style/email_with_no_style.html.erb
|
142
|
+
- spec/internal/config/database.yml
|
143
|
+
- spec/internal/config/routes.rb
|
144
|
+
- spec/internal/db/schema.rb
|
145
|
+
- spec/internal/log/.gitignore
|
146
|
+
- spec/internal/public/favicon.ico
|
147
|
+
- spec/lib/action_mailer/inline/css_helper_spec.rb
|
148
|
+
- spec/lib/action_mailer/inline/processor_spec.rb
|
149
|
+
- spec/lib/action_mailer/inline_spec.rb
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
homepage: http://github.com/testpilot/actionmailer-instyle
|
152
|
+
licenses: []
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 1.8.15
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: This gem brings you the power of the premailer gem to Rails 3 without any
|
175
|
+
configuration needs. Create HTML emails, include a CSS file as you do in a normal
|
176
|
+
HTML document and premailer will inline the included CSS.
|
177
|
+
test_files:
|
178
|
+
- spec/internal/app/assets/stylesheets/notification_mailer.css.scss
|
179
|
+
- spec/internal/app/mailers/notification_mailer.rb
|
180
|
+
- spec/internal/app/mailers/notification_mailer_no_layout.rb
|
181
|
+
- spec/internal/app/views/layouts/notification_mailer.html.erb
|
182
|
+
- spec/internal/app/views/layouts/notification_mailer_without_style.html.erb
|
183
|
+
- spec/internal/app/views/notification_mailer/email_with_html_only.html.erb
|
184
|
+
- spec/internal/app/views/notification_mailer/welcome_html_email.html.erb
|
185
|
+
- spec/internal/app/views/notification_mailer/welcome_html_email.text.erb
|
186
|
+
- spec/internal/app/views/notification_mailer_no_style/email_with_no_style.html.erb
|
187
|
+
- spec/internal/config/database.yml
|
188
|
+
- spec/internal/config/routes.rb
|
189
|
+
- spec/internal/db/schema.rb
|
190
|
+
- spec/internal/log/.gitignore
|
191
|
+
- spec/internal/public/favicon.ico
|
192
|
+
- spec/lib/action_mailer/inline/css_helper_spec.rb
|
193
|
+
- spec/lib/action_mailer/inline/processor_spec.rb
|
194
|
+
- spec/lib/action_mailer/inline_spec.rb
|
195
|
+
- spec/spec_helper.rb
|