inline_styles_mailer 0.0.6 → 0.0.7

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.
@@ -1,3 +1,3 @@
1
1
  module InlineStylesMailer
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -63,17 +63,25 @@ module InlineStylesMailer
63
63
  prefixes = options[:template_path] || self.class.name.underscore
64
64
  prefixes = [prefixes] unless Rails.version =~ /^3\.0/
65
65
  templates = lookup_context.find_all(options[:template_name] || action_name, prefixes)
66
- templates.each do |template|
67
- template_path = template.inspect.split("/").slice(-2, 2).join("/")
68
- template.formats.each do |f|
69
- format.send(f) do
70
- case f.to_s
71
- when "html"
72
- html = render_to_string :file => template_path, :layout => layout_to_use, :formats => [:html]
73
- render :text => self.class.page.with_html(html).apply, :formats => [:html]
74
- else
75
- render :formats => [f]
76
- end
66
+ options.reverse_merge!(:mime_version => "1.0", :charset => "UTF-8", :content_type => "text/plain", :parts_order => [ "text/plain", "text/enriched", "text/html"])
67
+ templates.sort_by {|t|
68
+ i = options[:parts_order].index(t.mime_type)
69
+ i > -1 ? i : 99
70
+ }.each do |template|
71
+ # templates.each do |template|
72
+ # e.g. template = app/views/user_mailer/welcome.html.erb
73
+ template_path = template.inspect.split("/").slice(-2, 2).join("/") # e.g. user_mailer/welcome.html.erb
74
+ parts = template_path.split('.')
75
+ handler = parts.pop.to_sym # e.g. erb
76
+ extension = parts.pop.to_sym # e.g. html
77
+ file = parts.join('.') # e.g. user_mailer/welcome (you get a deprecation warning if you don't strip off the format and handler)
78
+ format.send(extension) do
79
+ case extension
80
+ when :html
81
+ html = render_to_string :file => file, :layout => layout_to_use, handlers: [handler]
82
+ render :text => self.class.page.with_html(html).apply
83
+ else
84
+ render
77
85
  end
78
86
  end
79
87
  end
@@ -0,0 +1 @@
1
+ <p>Backwards text/html.</p>
@@ -0,0 +1 @@
1
+ Backwards text/plain.
@@ -1 +1 @@
1
- <p>Testing foo.</p>
1
+ <p>Testing foo text/html.</p>
@@ -0,0 +1 @@
1
+ Testing foo text/plain.
data/spec/foo_mailer.rb CHANGED
@@ -7,4 +7,8 @@ class FooMailer < ActionMailer::Base
7
7
  mail(:to => "test@localhost", :subject => "Test")
8
8
  end
9
9
 
10
+ def backwards
11
+ mail(:to => "test@localhost", :subject => "Test", :parts_order => [ "text/html", "text/plain"])
12
+ end
13
+
10
14
  end
@@ -6,48 +6,80 @@ 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
9
  end
11
10
 
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;">/
11
+ describe "Inlining CSS" do
12
+ before do
13
+ FooMailer.stylesheet_path "assets/stylesheets"
17
14
  end
18
- end
19
15
 
20
- context "SCSS preprocessing" do
21
- before(:each) do
22
- FooMailer.use_stylesheet("_override.css.scss")
16
+ context "Default CSS file" do
17
+ it "should inline the CSS" do
18
+ mail = FooMailer.foo
19
+ mail.body.parts.length.should eq(2)
20
+ mail.body.parts[1].body.should =~ /<p style="color: red;">Testing foo text\/html\.<\/p>/
21
+ mail.body.parts[1].body.should =~ /<body style="background: yellow;">/
22
+ end
23
23
  end
24
- it "should inline the CSS" do
25
- mail = FooMailer.foo
26
- mail.body.should =~ /<p style="color: orange;">Testing foo\.<\/p>/
27
- mail.body.should =~ /<body style="background: yellow;">/
24
+
25
+ context "SCSS preprocessing" do
26
+ before(:each) do
27
+ FooMailer.use_stylesheet("_override.css.scss")
28
+ end
29
+ it "should inline the CSS" do
30
+ mail = FooMailer.foo
31
+ mail.body.parts.length.should eq(2)
32
+ mail.body.parts[1].body.should =~ /<p style="color: orange;">Testing foo text\/html\.<\/p>/
33
+ mail.body.parts[1].body.should =~ /<body style="background: yellow;">/
34
+ end
28
35
  end
29
- end
30
36
 
31
- context "SASS preprocessing" do
32
- before(:each) do
33
- FooMailer.use_stylesheet("_override.css.sass")
37
+ context "SASS preprocessing" do
38
+ before(:each) do
39
+ FooMailer.use_stylesheet("_override.css.sass")
40
+ end
41
+ it "should inline the CSS" do
42
+ mail = FooMailer.foo
43
+ mail.body.parts.length.should eq(2)
44
+ mail.body.parts[1].body.should =~ /<p style="color: green;">Testing foo text\/html\.<\/p>/
45
+ mail.body.parts[1].body.should =~ /<body style="background: yellow;">/
46
+ end
34
47
  end
35
- it "should inline the CSS" do
36
- mail = FooMailer.foo
37
- mail.body.should =~ /<p style="color: green;">Testing foo\.<\/p>/
38
- mail.body.should =~ /<body style="background: yellow;">/
48
+
49
+ context "No preprocessing (plain old CSS)" do
50
+ before(:each) do
51
+ FooMailer.use_stylesheet("_override.css")
52
+ end
53
+ it "should inline the CSS" do
54
+ mail = FooMailer.foo
55
+ mail.body.parts.length.should eq(2)
56
+ mail.body.parts[1].body.should =~ /<p style="color: blue;">Testing foo text\/html\.<\/p>/
57
+ mail.body.parts[1].body.should =~ /<body style="background: yellow;">/
58
+ end
39
59
  end
60
+
40
61
  end
41
62
 
42
- context "No preprocessing (plain old CSS)" do
43
- before(:each) do
44
- FooMailer.use_stylesheet("_override.css")
63
+ describe "Switch parts order" do
64
+
65
+ context "text/plain first (default)" do
66
+ it "should inline the CSS" do
67
+ mail = FooMailer.foo
68
+ mail.body.parts.length.should eq(2)
69
+ mail.body.parts[0].content_type.should =~ /^text\/plain/
70
+ mail.body.parts[1].content_type.should =~ /^text\/html/
71
+ end
45
72
  end
46
- it "should inline the CSS" do
47
- mail = FooMailer.foo
48
- mail.body.should =~ /<p style="color: blue;">Testing foo\.<\/p>/
49
- mail.body.should =~ /<body style="background: yellow;">/
73
+
74
+ context "text/html first" do
75
+ it "should inline the CSS" do
76
+ mail = FooMailer.backwards
77
+ mail.body.parts.length.should eq(2)
78
+ mail.body.parts[0].content_type.should =~ /^text\/html/
79
+ mail.body.parts[1].content_type.should =~ /^text\/plain/
80
+ end
50
81
  end
82
+
51
83
  end
52
84
 
53
- end
85
+ 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.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-12 00:00:00.000000000 Z
12
+ date: 2012-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -99,7 +99,10 @@ files:
99
99
  - spec/fixtures/assets/stylesheets/_override.css.sass
100
100
  - spec/fixtures/assets/stylesheets/_override.css.scss
101
101
  - spec/fixtures/layout.html.erb
102
+ - spec/fixtures/views/foo_mailer/backwards.html.erb
103
+ - spec/fixtures/views/foo_mailer/backwards.text.erb
102
104
  - spec/fixtures/views/foo_mailer/foo.html.erb
105
+ - spec/fixtures/views/foo_mailer/foo.text.erb
103
106
  - spec/fixtures/views/layouts/foo_mailer.html.erb
104
107
  - spec/foo_mailer.rb
105
108
  - spec/inline_styles_mailer/inline_styles_mailer_spec.rb
@@ -134,7 +137,10 @@ test_files:
134
137
  - spec/fixtures/assets/stylesheets/_override.css.sass
135
138
  - spec/fixtures/assets/stylesheets/_override.css.scss
136
139
  - spec/fixtures/layout.html.erb
140
+ - spec/fixtures/views/foo_mailer/backwards.html.erb
141
+ - spec/fixtures/views/foo_mailer/backwards.text.erb
137
142
  - spec/fixtures/views/foo_mailer/foo.html.erb
143
+ - spec/fixtures/views/foo_mailer/foo.text.erb
138
144
  - spec/fixtures/views/layouts/foo_mailer.html.erb
139
145
  - spec/foo_mailer.rb
140
146
  - spec/inline_styles_mailer/inline_styles_mailer_spec.rb