inline_styles_mailer 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/README.md +18 -13
- data/lib/inline_styles_mailer.rb +8 -9
- data/lib/inline_styles_mailer/version.rb +1 -1
- data/spec/fixtures/assets/stylesheets/{_foo_mailer.css → _override.css} +1 -1
- data/spec/fixtures/assets/stylesheets/{_foo_mailer.css.sass → _override.css.sass} +1 -1
- data/spec/fixtures/assets/stylesheets/_override.css.scss +6 -0
- data/spec/inline_styles_mailer/inline_styles_mailer_spec.rb +15 -9
- metadata +17 -15
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -29,28 +29,33 @@ class FooMailer < ActionMailer::Base
|
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
-
If you have a CSS file <code>app/assets/stylesheets/_foo_mailer.css.scss
|
32
|
+
If you have a CSS file <code>app/assets/stylesheets/_foo_mailer*</code> (where * can be .css, .css.scss or .css.sass) then it will get automatically applied to the mail using the inline_styles gem. That name (<code>_foo_mailer</code>) is based on your mailer class name, e.g. FooMailer. If you have more than one file matching that pattern then it will use them all.
|
33
33
|
|
34
|
-
|
34
|
+
It will use one of three preprocessing methods based on the filename:
|
35
|
+
|
36
|
+
* [.scss](http://sass-lang.com/)
|
37
|
+
* [.sass](http://sass-lang.com/)
|
38
|
+
* anything else (e.g. .css) no preprocessing at all
|
39
|
+
|
40
|
+
Want to use a different css file? Declare <code>use_stylesheet</code>:
|
35
41
|
|
36
42
|
```ruby
|
37
43
|
class FooMailer < ActionMailer::Base
|
38
44
|
include InlineStylesMailer
|
39
|
-
use_stylesheet '_bar'
|
40
|
-
|
41
|
-
|
42
|
-
def foo(email)
|
43
|
-
mail(:to => email, :subject => "Foo foo!")
|
44
|
-
end
|
45
|
-
|
45
|
+
use_stylesheet '_bar.css.sass'
|
46
|
+
...
|
46
47
|
end
|
47
48
|
```
|
48
49
|
|
49
|
-
|
50
|
+
You can use an array of stylesheets if you like. Don't keep your stylesheets in <code>app/assets/stylesheets</code>? Declare <code>stylesheet_path</code>:
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
```ruby
|
53
|
+
class FooMailer < ActionMailer::Base
|
54
|
+
include InlineStylesMailer
|
55
|
+
stylesheet_path 'public/stylesheets'
|
56
|
+
...
|
57
|
+
end
|
58
|
+
```
|
54
59
|
|
55
60
|
## Development
|
56
61
|
|
data/lib/inline_styles_mailer.rb
CHANGED
@@ -14,8 +14,8 @@ module InlineStylesMailer
|
|
14
14
|
@stylesheets = Array(stylesheets)
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
17
|
+
def stylesheet_path(path)
|
18
|
+
@stylesheet_path = path
|
19
19
|
end
|
20
20
|
|
21
21
|
def locate_template(name)
|
@@ -23,10 +23,10 @@ module InlineStylesMailer
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def css_content
|
26
|
-
@stylesheets ||= ["_#{self.name.underscore}"]
|
26
|
+
@stylesheets ||= ["_#{self.name.underscore}*"]
|
27
|
+
@stylesheet_path ||= File.join("app", "assets", "stylesheets")
|
27
28
|
@css_content ||= @stylesheets.map {|stylesheet|
|
28
|
-
|
29
|
-
if File.exist?(file)
|
29
|
+
Dir[Rails.root.join(@stylesheet_path, "#{stylesheet}")].map {|file|
|
30
30
|
case file
|
31
31
|
when /\.scss$/
|
32
32
|
Sass::Engine.new(File.read(file), syntax: :scss).render
|
@@ -36,10 +36,9 @@ module InlineStylesMailer
|
|
36
36
|
# Plain old CSS? Let's assume it is.
|
37
37
|
File.read(file)
|
38
38
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
}.compact.join
|
39
|
+
}.join("\n")
|
40
|
+
}.compact.join("\n")
|
41
|
+
@css_content
|
43
42
|
end
|
44
43
|
|
45
44
|
def locate_layout
|
@@ -6,40 +6,46 @@ describe InlineStylesMailer do
|
|
6
6
|
before(:each) do
|
7
7
|
FooMailer.reset
|
8
8
|
Rails.should_receive(:root).any_number_of_times.and_return(Pathname.new(File.join("spec", "fixtures")))
|
9
|
+
FooMailer.stylesheet_path "assets/stylesheets"
|
10
|
+
end
|
11
|
+
|
12
|
+
context "Default CSS file" do
|
13
|
+
it "should inline the CSS" do
|
14
|
+
mail = FooMailer.foo
|
15
|
+
mail.body.should =~ /<p style="color: red;">Testing foo\.<\/p>/
|
16
|
+
mail.body.should =~ /<body style="background: yellow;">/
|
17
|
+
end
|
9
18
|
end
|
10
19
|
|
11
20
|
context "SCSS preprocessing" do
|
12
21
|
before(:each) do
|
13
|
-
|
14
|
-
FooMailer.should_receive(:locate_css_file).and_return(file)
|
22
|
+
FooMailer.use_stylesheet("_override.css.scss")
|
15
23
|
end
|
16
24
|
it "should inline the CSS" do
|
17
25
|
mail = FooMailer.foo
|
18
|
-
mail.body.should =~ /<p style="color:
|
26
|
+
mail.body.should =~ /<p style="color: orange;">Testing foo\.<\/p>/
|
19
27
|
mail.body.should =~ /<body style="background: yellow;">/
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
23
31
|
context "SASS preprocessing" do
|
24
32
|
before(:each) do
|
25
|
-
|
26
|
-
FooMailer.should_receive(:locate_css_file).and_return(file)
|
33
|
+
FooMailer.use_stylesheet("_override.css.sass")
|
27
34
|
end
|
28
35
|
it "should inline the CSS" do
|
29
36
|
mail = FooMailer.foo
|
30
|
-
mail.body.should =~ /<p style="color:
|
37
|
+
mail.body.should =~ /<p style="color: green;">Testing foo\.<\/p>/
|
31
38
|
mail.body.should =~ /<body style="background: yellow;">/
|
32
39
|
end
|
33
40
|
end
|
34
41
|
|
35
42
|
context "No preprocessing (plain old CSS)" do
|
36
43
|
before(:each) do
|
37
|
-
|
38
|
-
FooMailer.should_receive(:locate_css_file).and_return(file)
|
44
|
+
FooMailer.use_stylesheet("_override.css")
|
39
45
|
end
|
40
46
|
it "should inline the CSS" do
|
41
47
|
mail = FooMailer.foo
|
42
|
-
mail.body.should =~ /<p style="color:
|
48
|
+
mail.body.should =~ /<p style="color: blue;">Testing foo\.<\/p>/
|
43
49
|
mail.body.should =~ /<body style="background: yellow;">/
|
44
50
|
end
|
45
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inline_styles_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-06 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70249576618260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70249576618260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: inline_styles
|
27
|
-
requirement: &
|
27
|
+
requirement: &70249576617160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70249576617160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &70249576615600 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.1'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70249576615600
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sass-rails
|
49
|
-
requirement: &
|
49
|
+
requirement: &70249576614380 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70249576614380
|
58
58
|
description: Convenient use of inline_styles gem with Rails 3.1
|
59
59
|
email:
|
60
60
|
- bill@logicalcobwebs.com
|
@@ -73,9 +73,10 @@ files:
|
|
73
73
|
- inline_styles_mailer.gemspec
|
74
74
|
- lib/inline_styles_mailer.rb
|
75
75
|
- lib/inline_styles_mailer/version.rb
|
76
|
-
- spec/fixtures/assets/stylesheets/_foo_mailer.css
|
77
|
-
- spec/fixtures/assets/stylesheets/_foo_mailer.css.sass
|
78
76
|
- spec/fixtures/assets/stylesheets/_foo_mailer.css.scss
|
77
|
+
- spec/fixtures/assets/stylesheets/_override.css
|
78
|
+
- spec/fixtures/assets/stylesheets/_override.css.sass
|
79
|
+
- spec/fixtures/assets/stylesheets/_override.css.scss
|
79
80
|
- spec/fixtures/layout.html.erb
|
80
81
|
- spec/fixtures/views/foo_mailer/foo.html
|
81
82
|
- spec/fixtures/views/layouts/mailer.html.erb
|
@@ -96,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
97
|
version: '0'
|
97
98
|
segments:
|
98
99
|
- 0
|
99
|
-
hash:
|
100
|
+
hash: 1023047105202860642
|
100
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
102
|
none: false
|
102
103
|
requirements:
|
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
106
|
version: '0'
|
106
107
|
segments:
|
107
108
|
- 0
|
108
|
-
hash:
|
109
|
+
hash: 1023047105202860642
|
109
110
|
requirements: []
|
110
111
|
rubyforge_project: inline_styles_mailer
|
111
112
|
rubygems_version: 1.8.10
|
@@ -113,9 +114,10 @@ signing_key:
|
|
113
114
|
specification_version: 3
|
114
115
|
summary: Convenient use of inline_styles gem with Rails 3.1
|
115
116
|
test_files:
|
116
|
-
- spec/fixtures/assets/stylesheets/_foo_mailer.css
|
117
|
-
- spec/fixtures/assets/stylesheets/_foo_mailer.css.sass
|
118
117
|
- spec/fixtures/assets/stylesheets/_foo_mailer.css.scss
|
118
|
+
- spec/fixtures/assets/stylesheets/_override.css
|
119
|
+
- spec/fixtures/assets/stylesheets/_override.css.sass
|
120
|
+
- spec/fixtures/assets/stylesheets/_override.css.scss
|
119
121
|
- spec/fixtures/layout.html.erb
|
120
122
|
- spec/fixtures/views/foo_mailer/foo.html
|
121
123
|
- spec/fixtures/views/layouts/mailer.html.erb
|