roadie 1.1.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -4
- data/Changelog.md +10 -1
- data/Gemfile.lock +23 -22
- data/README.md +24 -8
- data/lib/roadie.rb +13 -17
- data/lib/roadie/action_mailer_extensions.rb +1 -5
- data/lib/roadie/inliner.rb +11 -7
- data/lib/roadie/version.rb +1 -1
- data/roadie.gemspec +2 -1
- data/spec/fixtures/{public → app/assets}/stylesheets/bar.css +0 -0
- data/spec/fixtures/{public → app/assets}/stylesheets/foo.css +0 -0
- data/spec/fixtures/{public → app/assets}/stylesheets/green_paragraphs.css +0 -0
- data/spec/fixtures/{public → app/assets}/stylesheets/integration.css +0 -0
- data/spec/fixtures/{public → app/assets}/stylesheets/large_purple_paragraphs.css +0 -0
- data/spec/fixtures/app/assets/stylesheets/subdirectory/findme.css +1 -0
- data/spec/fixtures/app/assets/stylesheets/subdirectory/red_paragraphs.css +1 -0
- data/spec/integration_spec.rb +5 -8
- data/spec/lib/roadie/action_mailer_extensions_spec.rb +5 -5
- data/spec/lib/roadie/inliner_spec.rb +26 -17
- data/spec/lib/roadie_spec.rb +18 -8
- data/spec/spec_helper.rb +17 -10
- metadata +30 -17
- data/gemfiles/rails-3.0.x.Gemfile +0 -7
- data/gemfiles/rails-3.1.x.Gemfile +0 -7
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](https://github.com/Mange/roadie/compare/
|
3
|
+
[full changelog](https://github.com/Mange/roadie/compare/v2.0.0...master)
|
4
4
|
|
5
5
|
* Nothing yet
|
6
6
|
|
7
|
+
### 2.0.0
|
8
|
+
|
9
|
+
[full changelog](https://github.com/Mange/roadie/compare/v1.1.3...v2.0.0)
|
10
|
+
|
11
|
+
* Enhancements:
|
12
|
+
* Support the Asset pipeline - [Arttu Tervo (arttu)](https://github.com/arttu)
|
13
|
+
* Dependencies:
|
14
|
+
* Requires Rails 3.1 to work. You can keep on using the 1.x series in Rails 3.0
|
15
|
+
|
7
16
|
### 1.1.3
|
8
17
|
|
9
18
|
[full changelog](https://github.com/Mange/roadie/compare/v1.1.2...v1.1.3)
|
data/Gemfile.lock
CHANGED
@@ -1,37 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
roadie (
|
5
|
-
actionmailer (~> 3.0)
|
4
|
+
roadie (2.0.0)
|
5
|
+
actionmailer (~> 3.1.0)
|
6
6
|
css_parser
|
7
7
|
nokogiri (>= 1.4.4)
|
8
|
+
sprockets
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: http://rubygems.org/
|
11
12
|
specs:
|
12
|
-
actionmailer (3.1.
|
13
|
-
actionpack (= 3.1.
|
13
|
+
actionmailer (3.1.1)
|
14
|
+
actionpack (= 3.1.1)
|
14
15
|
mail (~> 2.3.0)
|
15
|
-
actionpack (3.1.
|
16
|
-
activemodel (= 3.1.
|
17
|
-
activesupport (= 3.1.
|
16
|
+
actionpack (3.1.1)
|
17
|
+
activemodel (= 3.1.1)
|
18
|
+
activesupport (= 3.1.1)
|
18
19
|
builder (~> 3.0.0)
|
19
20
|
erubis (~> 2.7.0)
|
20
21
|
i18n (~> 0.6)
|
21
22
|
rack (~> 1.3.2)
|
22
|
-
rack-cache (~> 1.
|
23
|
+
rack-cache (~> 1.1)
|
23
24
|
rack-mount (~> 0.8.2)
|
24
25
|
rack-test (~> 0.6.1)
|
25
|
-
sprockets (~> 2.0.
|
26
|
-
activemodel (3.1.
|
27
|
-
activesupport (= 3.1.
|
28
|
-
bcrypt-ruby (~> 3.0.0)
|
26
|
+
sprockets (~> 2.0.2)
|
27
|
+
activemodel (3.1.1)
|
28
|
+
activesupport (= 3.1.1)
|
29
29
|
builder (~> 3.0.0)
|
30
30
|
i18n (~> 0.6)
|
31
|
-
activesupport (3.1.
|
31
|
+
activesupport (3.1.1)
|
32
32
|
multi_json (~> 1.0)
|
33
33
|
addressable (2.2.6)
|
34
|
-
bcrypt-ruby (3.0.0)
|
35
34
|
builder (3.0.0)
|
36
35
|
css_parser (1.2.5)
|
37
36
|
addressable
|
@@ -39,6 +38,7 @@ GEM
|
|
39
38
|
erubis (2.7.0)
|
40
39
|
hike (1.2.1)
|
41
40
|
i18n (0.6.0)
|
41
|
+
json (1.6.1)
|
42
42
|
mail (2.3.0)
|
43
43
|
i18n (>= 0.4.0)
|
44
44
|
mime-types (~> 1.16)
|
@@ -47,8 +47,8 @@ GEM
|
|
47
47
|
multi_json (1.0.3)
|
48
48
|
nokogiri (1.5.0)
|
49
49
|
polyglot (0.3.2)
|
50
|
-
rack (1.3.
|
51
|
-
rack-cache (1.
|
50
|
+
rack (1.3.4)
|
51
|
+
rack-cache (1.1)
|
52
52
|
rack (>= 0.4)
|
53
53
|
rack-mount (0.8.3)
|
54
54
|
rack (>= 1.0.0)
|
@@ -56,15 +56,16 @@ GEM
|
|
56
56
|
rack
|
57
57
|
rack-test (0.6.1)
|
58
58
|
rack (>= 1.0)
|
59
|
-
railties (3.1.
|
60
|
-
actionpack (= 3.1.
|
61
|
-
activesupport (= 3.1.
|
59
|
+
railties (3.1.1)
|
60
|
+
actionpack (= 3.1.1)
|
61
|
+
activesupport (= 3.1.1)
|
62
62
|
rack-ssl (~> 1.3.2)
|
63
63
|
rake (>= 0.8.7)
|
64
64
|
rdoc (~> 3.4)
|
65
65
|
thor (~> 0.14.6)
|
66
66
|
rake (0.9.2)
|
67
|
-
rdoc (3.
|
67
|
+
rdoc (3.10)
|
68
|
+
json (~> 1.4)
|
68
69
|
rspec (2.6.0)
|
69
70
|
rspec-core (~> 2.6.0)
|
70
71
|
rspec-expectations (~> 2.6.0)
|
@@ -78,10 +79,10 @@ GEM
|
|
78
79
|
activesupport (~> 3.0)
|
79
80
|
railties (~> 3.0)
|
80
81
|
rspec (~> 2.6.0)
|
81
|
-
sprockets (2.0.
|
82
|
+
sprockets (2.0.2)
|
82
83
|
hike (~> 1.2)
|
83
84
|
rack (~> 1.0)
|
84
|
-
tilt (
|
85
|
+
tilt (~> 1.1, != 1.3.0)
|
85
86
|
thor (0.14.6)
|
86
87
|
tilt (1.3.3)
|
87
88
|
treetop (1.4.10)
|
data/README.md
CHANGED
@@ -5,6 +5,8 @@ Roadie
|
|
5
5
|
|
6
6
|
Roadie tries to make sending HTML emails a little less painful in Rails 3 by inlining stylesheets and rewrite relative URLs for you.
|
7
7
|
|
8
|
+
You are currently looking at the README for version 2.0 and later which requires Rails 3.1. This gem can be used with Rails 3.0 by staying with the 1.x series.
|
9
|
+
|
8
10
|
If you want to have this in Rails 2, please see [MailStyle](https://www.github.com/purify/mail_style).
|
9
11
|
|
10
12
|
How does it work?
|
@@ -25,13 +27,21 @@ Build Status
|
|
25
27
|
|
26
28
|
Tested with [Travis CI](http://travis-ci.org) using the [following combinations](http://travis-ci.org/#!/Mange/roadie):
|
27
29
|
|
28
|
-
* Ruby 1.8.7 with Rails 3.0.x
|
29
|
-
* Ruby 1.9.2 with Rails 3.0.x
|
30
30
|
* Ruby 1.8.7 with Rails 3.1.x
|
31
31
|
* Ruby 1.9.2 with Rails 3.1.x
|
32
32
|
|
33
33
|
Let me know if you want any other combination supported officially
|
34
34
|
|
35
|
+
### Versioning ###
|
36
|
+
|
37
|
+
This project follows [Semtantic Versioning](http://semver.org/) and has been since version 1.0.0.
|
38
|
+
|
39
|
+
Two branches are currently in place:
|
40
|
+
* 2.x - Rails 3.1
|
41
|
+
* 1.x - Rails 3.0
|
42
|
+
|
43
|
+
The 1.x branch will continue to be supported until it is deemed unnecessary by the author, but properly made pull requests will be accepted indefinitely.
|
44
|
+
|
35
45
|
Features
|
36
46
|
--------
|
37
47
|
|
@@ -48,7 +58,7 @@ Features
|
|
48
58
|
|
49
59
|
### What about Sass / Less? ###
|
50
60
|
|
51
|
-
Sass is supported "by accident" as long as the stylesheets are generated and stored in the
|
61
|
+
Sass is supported "by accident" as long as the stylesheets are generated and stored in the asset directories. You are recommended to add a deploy task that generates the stylesheets to make sure that they are present at all times on the machine generating the emails.
|
52
62
|
|
53
63
|
Install
|
54
64
|
-------
|
@@ -78,7 +88,7 @@ class Notifier < ActionMailer::Base
|
|
78
88
|
end
|
79
89
|
```
|
80
90
|
|
81
|
-
This will look for a css file called `email.css` in your
|
91
|
+
This will look for a css file called `email.css` in your assets. The `css` method can take either a string, a symbol or an array of both. The ".css" extension will be added automatically.
|
82
92
|
|
83
93
|
### Image URL rewriting ###
|
84
94
|
|
@@ -110,9 +120,9 @@ If the `link` tag uses an absolute URL to the stylesheet, it will not be inlined
|
|
110
120
|
|
111
121
|
```html
|
112
122
|
<head>
|
113
|
-
<link rel="stylesheet" type="text/css" href="/
|
123
|
+
<link rel="stylesheet" type="text/css" href="/assets/emails/rock.css"> <!-- Will be inlined -->
|
114
124
|
<link rel="stylesheet" type="text/css" href="http://www.metal.org/metal.css"> <!-- Will NOT be inlined -->
|
115
|
-
<link rel="stylesheet" type="text/css" href="/
|
125
|
+
<link rel="stylesheet" type="text/css" href="/assets/jazz.css" media="print"> <!-- Will NOT be inlined -->
|
116
126
|
<link rel="stylesheet" type="text/css" href="/ambient.css" data-immutable> <!-- Will NOT be inlined -->
|
117
127
|
</head>
|
118
128
|
```
|
@@ -134,14 +144,20 @@ Note that on my Mac OS X boxes, I don't have to do it as complex as they do it i
|
|
134
144
|
Documentation
|
135
145
|
-------------
|
136
146
|
|
137
|
-
* [Online documentation for
|
138
|
-
* [Online documentation for 1.
|
147
|
+
* [Online documentation for 2.0.0](http://rubydoc.info/gems/roadie/2.0.0/frames)
|
148
|
+
* [Online documentation for 1.1.3](http://rubydoc.info/gems/roadie/1.1.3/frames)
|
139
149
|
* [Online documentation for master](http://rubydoc.info/github/Mange/roadie/master/frames)
|
140
150
|
* [Changelog](https://github.com/Mange/roadie/blob/master/Changelog.md)
|
141
151
|
|
142
152
|
History and contributors
|
143
153
|
------------------------
|
144
154
|
|
155
|
+
Major contributors to Roadie:
|
156
|
+
|
157
|
+
* [Arttu Tervo (arttu)](https://github.com/arttu) - Asset pipeline support
|
158
|
+
|
159
|
+
You can [see all contributors](https://github.com/Mange/roadie/contributors) on GitHub.
|
160
|
+
|
145
161
|
This gem was originally developed for Rails 2 use on [Purify](http://purifyapp.com) under the name [MailStyle](https://www.github.com/purify/mail_style). However, the author stopped maintaining it and a fork took place to make it Rails 3 compatible.
|
146
162
|
|
147
163
|
The following people have contributed to the orignal gem:
|
data/lib/roadie.rb
CHANGED
@@ -5,29 +5,25 @@ module Roadie
|
|
5
5
|
Roadie::Inliner.new(*args).execute
|
6
6
|
end
|
7
7
|
|
8
|
-
#
|
8
|
+
# Shortcut to Rails.application.assets
|
9
|
+
def self.assets
|
10
|
+
Rails.application.assets
|
11
|
+
end
|
12
|
+
|
13
|
+
# Tries to load the CSS "names" specified in the +targets+ parameter using the Rails asset pipeline.
|
9
14
|
#
|
10
15
|
# @example
|
11
|
-
# Roadie.load_css(
|
16
|
+
# Roadie.load_css(%w[application newsletter])
|
12
17
|
#
|
13
|
-
# @param [
|
14
|
-
# @param [Array<String, Symbol>] targets Stylesheet names - <b>without extensions</b>
|
18
|
+
# @param [Array<String|Symbol>] targets Stylesheet names
|
15
19
|
# @return [String] The combined contents of the CSS files
|
16
|
-
# @raise [CSSFileNotFound] When a target cannot be found
|
17
|
-
def self.load_css(
|
18
|
-
|
19
|
-
raise CSSFileNotFound, file unless file
|
20
|
-
file.
|
20
|
+
# @raise [CSSFileNotFound] When a target cannot be found from Rails assets
|
21
|
+
def self.load_css(targets)
|
22
|
+
targets.map do |file|
|
23
|
+
raise CSSFileNotFound, file unless assets[file]
|
24
|
+
assets[file].to_s.strip
|
21
25
|
end.join("\n")
|
22
26
|
end
|
23
|
-
|
24
|
-
private
|
25
|
-
def self.css_files_from_targets(root, targets)
|
26
|
-
targets.map do |target|
|
27
|
-
target = "#{target}.css" unless target.to_s.end_with? '.css'
|
28
|
-
root.join(target)
|
29
|
-
end
|
30
|
-
end
|
31
27
|
end
|
32
28
|
|
33
29
|
require 'roadie/version'
|
@@ -32,10 +32,6 @@ module Roadie
|
|
32
32
|
Rails.application.config.action_mailer.default_url_options
|
33
33
|
end
|
34
34
|
|
35
|
-
def stylesheet_root
|
36
|
-
Rails.root.join('public', 'stylesheets')
|
37
|
-
end
|
38
|
-
|
39
35
|
def inline_style_response(response)
|
40
36
|
if response[:content_type] == 'text/html'
|
41
37
|
response.merge :body => Roadie.inline_css(css_rules, response[:body], url_options)
|
@@ -50,7 +46,7 @@ module Roadie
|
|
50
46
|
end
|
51
47
|
|
52
48
|
def css_rules
|
53
|
-
@css_rules ||= Roadie.load_css(
|
49
|
+
@css_rules ||= Roadie.load_css(css_targets) if css_targets.present?
|
54
50
|
end
|
55
51
|
end
|
56
52
|
end
|
data/lib/roadie/inliner.rb
CHANGED
@@ -25,12 +25,13 @@ module Roadie
|
|
25
25
|
#
|
26
26
|
# @param [String] css
|
27
27
|
# @param [String] html
|
28
|
-
# @param [Hash] url_options Supported keys: +:host+, +:port+ and +:
|
28
|
+
# @param [Hash] url_options Supported keys: +:host+, +:port+, +:protocol+ and +:asset_path_prefix:+
|
29
29
|
def initialize(css, html, url_options)
|
30
30
|
@css = css
|
31
31
|
@inline_css = []
|
32
32
|
@html = html
|
33
33
|
@url_options = url_options
|
34
|
+
@asset_path_prefix = (url_options && url_options[:asset_path_prefix] || "/assets/")
|
34
35
|
end
|
35
36
|
|
36
37
|
# Start the inlining and return the final HTML output
|
@@ -62,6 +63,13 @@ module Roadie
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
66
|
+
def find_asset_from_url(url)
|
67
|
+
asset_filename = url.path.sub(/^#{Regexp.quote(@asset_path_prefix)}/, '').gsub(%r{^/|//+}, '')
|
68
|
+
Roadie.assets[asset_filename].tap do |asset|
|
69
|
+
raise CSSFileNotFound.new(asset_filename, url) unless asset
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
65
73
|
def adjust_html
|
66
74
|
Nokogiri::HTML.parse(html).tap do |document|
|
67
75
|
yield document
|
@@ -91,12 +99,8 @@ module Roadie
|
|
91
99
|
|
92
100
|
def extract_link_elements
|
93
101
|
all_link_elements_to_be_inlined_with_url.each do |link, url|
|
94
|
-
|
95
|
-
|
96
|
-
url_path = url.path.sub(%r{^/}, '')
|
97
|
-
file_path = Rails.root.join('public', url_path)
|
98
|
-
raise CSSFileNotFound.new(file_path, link['href']) unless file_path.file?
|
99
|
-
@inline_css << file_path.read
|
102
|
+
asset = find_asset_from_url(url)
|
103
|
+
@inline_css << asset.to_s
|
100
104
|
link.remove
|
101
105
|
end
|
102
106
|
end
|
data/lib/roadie/version.rb
CHANGED
data/roadie.gemspec
CHANGED
@@ -16,7 +16,8 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_dependency 'nokogiri', '>= 1.4.4'
|
18
18
|
s.add_dependency 'css_parser'
|
19
|
-
s.add_dependency 'actionmailer', '~> 3.0'
|
19
|
+
s.add_dependency 'actionmailer', '~> 3.1.0'
|
20
|
+
s.add_dependency 'sprockets'
|
20
21
|
|
21
22
|
s.add_development_dependency 'rspec-rails', '>= 2.0.0'
|
22
23
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
can you really find me?
|
@@ -0,0 +1 @@
|
|
1
|
+
p { color: red; }
|
data/spec/integration_spec.rb
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "roadie integration" do
|
4
|
-
class TestApplication
|
5
|
-
def config
|
6
|
-
OpenStruct.new(:action_mailer => OpenStruct.new(:default_url_options => {:host => "example.app.org"}))
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
4
|
class IntegrationMailer < ActionMailer::Base
|
11
5
|
default :css => :integration, :from => 'john@example.com'
|
12
|
-
append_view_path
|
6
|
+
append_view_path FIXTURES_PATH.join('views')
|
13
7
|
|
14
8
|
def notification(to, reason)
|
15
9
|
@reason = reason
|
@@ -23,7 +17,10 @@ describe "roadie integration" do
|
|
23
17
|
end
|
24
18
|
|
25
19
|
before(:each) do
|
26
|
-
|
20
|
+
config = double(:action_mailer => double(:default_url_options => {:host => "example.app.org"}))
|
21
|
+
Rails.application.stub(:config => config)
|
22
|
+
|
23
|
+
Rails.stub(:root => FIXTURES_PATH)
|
27
24
|
IntegrationMailer.delivery_method = :test
|
28
25
|
end
|
29
26
|
|
@@ -79,18 +79,18 @@ describe Roadie::ActionMailerExtensions, "loading css files" do
|
|
79
79
|
Roadie.stub!(:inline_css => 'html')
|
80
80
|
end
|
81
81
|
|
82
|
-
it "loads css from
|
83
|
-
Roadie.should_receive(:load_css).with(
|
82
|
+
it "loads css from Roadie" do
|
83
|
+
Roadie.should_receive(:load_css).with(anything).and_return('')
|
84
84
|
CssLoadingMailer.use_default
|
85
85
|
end
|
86
86
|
|
87
87
|
it "loads the css specified in the default mailer settings" do
|
88
|
-
Roadie.should_receive(:load_css).with(
|
88
|
+
Roadie.should_receive(:load_css).with(['default_value']).and_return('')
|
89
89
|
CssLoadingMailer.use_default
|
90
90
|
end
|
91
91
|
|
92
92
|
it "loads the css specified in the specific mailer action instead of the default choice" do
|
93
|
-
Roadie.should_receive(:load_css).with(
|
93
|
+
Roadie.should_receive(:load_css).with(['specific']).and_return('')
|
94
94
|
CssLoadingMailer.override(:specific)
|
95
95
|
end
|
96
96
|
|
@@ -100,7 +100,7 @@ describe Roadie::ActionMailerExtensions, "loading css files" do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
it "loads multiple css files when given an array" do
|
103
|
-
Roadie.should_receive(:load_css).with(
|
103
|
+
Roadie.should_receive(:load_css).with(['specific', 'other']).and_return('')
|
104
104
|
CssLoadingMailer.override([:specific, :other])
|
105
105
|
end
|
106
106
|
end
|
@@ -149,15 +149,24 @@ describe Roadie::Inliner do
|
|
149
149
|
end
|
150
150
|
|
151
151
|
describe "linked stylesheets" do
|
152
|
-
before(:each) do
|
153
|
-
Rails.stub(:root => FixturesPath)
|
154
|
-
end
|
155
|
-
|
156
152
|
it "inlines styles from the linked stylesheet" do
|
157
153
|
rendering(<<-HTML).should have_styling('color' => 'green').at_selector('p')
|
158
154
|
<html>
|
159
155
|
<head>
|
160
|
-
<link rel="stylesheet" href="/
|
156
|
+
<link rel="stylesheet" href="/assets/green_paragraphs.css">
|
157
|
+
</head>
|
158
|
+
<body>
|
159
|
+
<p></p>
|
160
|
+
</body>
|
161
|
+
</html>
|
162
|
+
HTML
|
163
|
+
end
|
164
|
+
|
165
|
+
it "inlines styles from the linked stylesheet in subdirectory" do
|
166
|
+
rendering(<<-HTML).should have_styling('color' => 'red').at_selector('p')
|
167
|
+
<html>
|
168
|
+
<head>
|
169
|
+
<link rel="stylesheet" href="/assets/subdirectory/red_paragraphs.css">
|
161
170
|
</head>
|
162
171
|
<body>
|
163
172
|
<p></p>
|
@@ -170,8 +179,8 @@ describe Roadie::Inliner do
|
|
170
179
|
html = <<-HTML
|
171
180
|
<html>
|
172
181
|
<head>
|
173
|
-
<link rel="stylesheet" href="/
|
174
|
-
<link rel="stylesheet" href="/
|
182
|
+
<link rel="stylesheet" href="/assets/green_paragraphs.css">
|
183
|
+
<link rel="stylesheet" href="/assets/large_purple_paragraphs.css">
|
175
184
|
</head>
|
176
185
|
<body>
|
177
186
|
<p></p>
|
@@ -189,8 +198,8 @@ describe Roadie::Inliner do
|
|
189
198
|
rendering(<<-HTML).should_not have_selector('link')
|
190
199
|
<html>
|
191
200
|
<head>
|
192
|
-
<link rel="stylesheet" href="/
|
193
|
-
<link rel="stylesheet" href="/
|
201
|
+
<link rel="stylesheet" href="/assets/green_paragraphs.css">
|
202
|
+
<link rel="stylesheet" href="/assets/large_purple_paragraphs.css">
|
194
203
|
</head>
|
195
204
|
<body>
|
196
205
|
</body>
|
@@ -203,7 +212,7 @@ describe Roadie::Inliner do
|
|
203
212
|
rendering(<<-HTML).should_not have_styling('color' => 'green').at_selector('p')
|
204
213
|
<html>
|
205
214
|
<head>
|
206
|
-
<link rel="stylesheet" href="/
|
215
|
+
<link rel="stylesheet" href="/assets/green_paragraphs.css" media="print">
|
207
216
|
</head>
|
208
217
|
<body>
|
209
218
|
<p></p>
|
@@ -216,7 +225,7 @@ describe Roadie::Inliner do
|
|
216
225
|
rendering(<<-HTML).should have_selector('link')
|
217
226
|
<html>
|
218
227
|
<head>
|
219
|
-
<link rel="stylesheet" href="/
|
228
|
+
<link rel="stylesheet" href="/assets/green_paragraphs.css" media="print">
|
220
229
|
</head>
|
221
230
|
<body>
|
222
231
|
</body>
|
@@ -230,7 +239,7 @@ describe Roadie::Inliner do
|
|
230
239
|
rendering(<<-HTML).should_not have_styling('color' => 'green').at_selector('p')
|
231
240
|
<html>
|
232
241
|
<head>
|
233
|
-
<link rel="stylesheet" href="/
|
242
|
+
<link rel="stylesheet" href="/assets/green_paragraphs.css" data-immutable="true">
|
234
243
|
</head>
|
235
244
|
<body>
|
236
245
|
<p></p>
|
@@ -243,7 +252,7 @@ describe Roadie::Inliner do
|
|
243
252
|
rendering(<<-HTML).should have_selector('link')
|
244
253
|
<html>
|
245
254
|
<head>
|
246
|
-
<link rel="stylesheet" href="/
|
255
|
+
<link rel="stylesheet" href="/assets/green_paragraphs.css" data-immutable="true">
|
247
256
|
</head>
|
248
257
|
<body>
|
249
258
|
</body>
|
@@ -284,7 +293,7 @@ describe Roadie::Inliner do
|
|
284
293
|
html = <<-HTML
|
285
294
|
<html>
|
286
295
|
<head>
|
287
|
-
<link rel="stylesheet" href="/
|
296
|
+
<link rel="stylesheet" href="/assets/not_found.css">
|
288
297
|
</head>
|
289
298
|
<body>
|
290
299
|
</body>
|
@@ -293,8 +302,8 @@ describe Roadie::Inliner do
|
|
293
302
|
|
294
303
|
expect { rendering(html) }.to raise_error do |error|
|
295
304
|
error.should be_a(Roadie::CSSFileNotFound)
|
296
|
-
error.filename.should ==
|
297
|
-
error.guess.should == '/
|
305
|
+
error.filename.should == Roadie.assets['not_found.css']
|
306
|
+
error.guess.should == '/assets/not_found.css'
|
298
307
|
end
|
299
308
|
end
|
300
309
|
end
|
@@ -304,7 +313,7 @@ describe Roadie::Inliner do
|
|
304
313
|
html = <<-HTML
|
305
314
|
<html>
|
306
315
|
<head>
|
307
|
-
<link rel="not_stylesheet" href="/
|
316
|
+
<link rel="not_stylesheet" href="/assets/green_paragraphs.css">
|
308
317
|
</head>
|
309
318
|
<body>
|
310
319
|
<p></p>
|
data/spec/lib/roadie_spec.rb
CHANGED
@@ -8,21 +8,31 @@ describe Roadie do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe ".
|
12
|
-
|
11
|
+
describe ".assets" do
|
12
|
+
it "delegates to Rails.application.assets" do
|
13
|
+
Rails.stub(:application => double(:assets => 'assets'))
|
14
|
+
Roadie.assets.should == 'assets'
|
15
|
+
end
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
Roadie.load_css(
|
18
|
+
describe ".load_css(targets)" do
|
19
|
+
it "loads files matching the target names in Rails assets" do
|
20
|
+
Roadie.load_css(['foo']).should == 'contents of foo'
|
21
|
+
Roadie.load_css(['foo.css']).should == 'contents of foo'
|
17
22
|
end
|
18
23
|
|
19
24
|
it "loads files in order and join them with a newline" do
|
20
|
-
Roadie.load_css(
|
21
|
-
Roadie.load_css(
|
25
|
+
Roadie.load_css(%w[foo bar]).should == "contents of foo\ncontents of bar"
|
26
|
+
Roadie.load_css(%w[bar foo]).should == "contents of bar\ncontents of foo"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "loads files also from asset subdirectories" do
|
30
|
+
Roadie.load_css(%w[foo subdirectory/findme.css]).should == "contents of foo\ncan you really find me?"
|
31
|
+
Roadie.load_css(%w[bar foo]).should == "contents of bar\ncontents of foo"
|
22
32
|
end
|
23
33
|
|
24
34
|
it "raises a Roadie::CSSFileNotFound error when a css file could not be found" do
|
25
|
-
expect { Roadie.load_css(
|
35
|
+
expect { Roadie.load_css(['not_here']) }.to raise_error(Roadie::CSSFileNotFound, /not_here/)
|
26
36
|
end
|
27
37
|
end
|
28
38
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,25 +14,32 @@ end
|
|
14
14
|
|
15
15
|
require 'rspec'
|
16
16
|
|
17
|
-
Dir['./spec/support/**/*'].each { |file| require file }
|
18
|
-
|
19
17
|
require 'action_mailer'
|
18
|
+
require 'sprockets'
|
20
19
|
require 'roadie'
|
21
20
|
|
21
|
+
FIXTURES_PATH = Pathname.new(File.dirname(__FILE__)).join('fixtures')
|
22
|
+
|
22
23
|
class TestApplication
|
23
24
|
def config
|
24
25
|
OpenStruct.new(:action_mailer => OpenStruct.new(:default_url_options => {:host => "example.com"}))
|
25
26
|
end
|
26
|
-
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def self.root; Pathname.new('/path/to'); end
|
33
|
-
def self.application; TestApplication.new; end
|
28
|
+
def assets
|
29
|
+
env = Sprockets::Environment.new
|
30
|
+
env.append_path FIXTURES_PATH.join('app','assets','stylesheets')
|
31
|
+
env
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
37
|
-
|
35
|
+
unless defined?(Rails)
|
36
|
+
class Rails; end
|
37
|
+
end
|
38
38
|
|
39
|
+
RSpec.configure do |c|
|
40
|
+
c.before(:each) do
|
41
|
+
Rails.stub(:application => TestApplication.new)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Dir['./spec/support/**/*'].each { |file| require file }
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: roadie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version:
|
5
|
+
version: 2.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Magnus Bergmark
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-10-13 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -43,20 +43,31 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 3.1.0
|
47
47
|
type: :runtime
|
48
48
|
version_requirements: *id003
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
50
|
+
name: sprockets
|
51
51
|
prerelease: false
|
52
52
|
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rspec-rails
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
53
64
|
none: false
|
54
65
|
requirements:
|
55
66
|
- - ">="
|
56
67
|
- !ruby/object:Gem::Version
|
57
68
|
version: 2.0.0
|
58
69
|
type: :development
|
59
|
-
version_requirements: *
|
70
|
+
version_requirements: *id005
|
60
71
|
description: Roadie tries to make sending HTML emails a little less painful in Rails 3 by inlining stylesheets and rewrite relative URLs for you.
|
61
72
|
email:
|
62
73
|
- magnus.bergmark@gmail.com
|
@@ -79,8 +90,6 @@ files:
|
|
79
90
|
- README.md
|
80
91
|
- Rakefile
|
81
92
|
- autotest/discover.rb
|
82
|
-
- gemfiles/rails-3.0.x.Gemfile
|
83
|
-
- gemfiles/rails-3.1.x.Gemfile
|
84
93
|
- lib/roadie.rb
|
85
94
|
- lib/roadie/action_mailer_extensions.rb
|
86
95
|
- lib/roadie/css_file_not_found.rb
|
@@ -88,11 +97,13 @@ files:
|
|
88
97
|
- lib/roadie/style_declaration.rb
|
89
98
|
- lib/roadie/version.rb
|
90
99
|
- roadie.gemspec
|
91
|
-
- spec/fixtures/
|
92
|
-
- spec/fixtures/
|
93
|
-
- spec/fixtures/
|
94
|
-
- spec/fixtures/
|
95
|
-
- spec/fixtures/
|
100
|
+
- spec/fixtures/app/assets/stylesheets/bar.css
|
101
|
+
- spec/fixtures/app/assets/stylesheets/foo.css
|
102
|
+
- spec/fixtures/app/assets/stylesheets/green_paragraphs.css
|
103
|
+
- spec/fixtures/app/assets/stylesheets/integration.css
|
104
|
+
- spec/fixtures/app/assets/stylesheets/large_purple_paragraphs.css
|
105
|
+
- spec/fixtures/app/assets/stylesheets/subdirectory/findme.css
|
106
|
+
- spec/fixtures/app/assets/stylesheets/subdirectory/red_paragraphs.css
|
96
107
|
- spec/fixtures/views/integration_mailer/marketing.html.erb
|
97
108
|
- spec/fixtures/views/integration_mailer/notification.html.erb
|
98
109
|
- spec/fixtures/views/integration_mailer/notification.text.erb
|
@@ -136,11 +147,13 @@ signing_key:
|
|
136
147
|
specification_version: 3
|
137
148
|
summary: Making HTML emails comfortable for the Rails rockstars
|
138
149
|
test_files:
|
139
|
-
- spec/fixtures/
|
140
|
-
- spec/fixtures/
|
141
|
-
- spec/fixtures/
|
142
|
-
- spec/fixtures/
|
143
|
-
- spec/fixtures/
|
150
|
+
- spec/fixtures/app/assets/stylesheets/bar.css
|
151
|
+
- spec/fixtures/app/assets/stylesheets/foo.css
|
152
|
+
- spec/fixtures/app/assets/stylesheets/green_paragraphs.css
|
153
|
+
- spec/fixtures/app/assets/stylesheets/integration.css
|
154
|
+
- spec/fixtures/app/assets/stylesheets/large_purple_paragraphs.css
|
155
|
+
- spec/fixtures/app/assets/stylesheets/subdirectory/findme.css
|
156
|
+
- spec/fixtures/app/assets/stylesheets/subdirectory/red_paragraphs.css
|
144
157
|
- spec/fixtures/views/integration_mailer/marketing.html.erb
|
145
158
|
- spec/fixtures/views/integration_mailer/notification.html.erb
|
146
159
|
- spec/fixtures/views/integration_mailer/notification.text.erb
|