premailer-rails3 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (C) 2011-2012 Philipe Fatio (fphilipe)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of
9
+ the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -54,13 +54,23 @@ pass these options on to the underlying premailer instance, specify them in an
54
54
  initializer:
55
55
 
56
56
  ```ruby
57
- PremailerRails.config = {
58
- :preserve_styles => true,
59
- :remove_ids => true
60
- }
57
+ PremailerRails.config.merge(:preserve_styles => true,
58
+ :remove_ids => true)
61
59
  ```
62
60
 
63
61
  For a list of options, refer to the [Premailer documentation](http://rubydoc.info/gems/premailer/1.7.3/Premailer:initialize)
64
62
 
65
- Note that the options `with_html_string` and `css_string` are used to make this
66
- gem work and will thus be overridden.
63
+ The default configs are:
64
+
65
+ ```ruby
66
+ {
67
+ :input_encoding => 'UTF-8',
68
+ :generate_text_part => true
69
+ }
70
+ ```
71
+
72
+ If you don't want to generate a text part from the html part, set the config
73
+ `:generate_text_part` to false.
74
+
75
+ Note that the options `:with_html_string` and `:css_string` are used to make
76
+ this gem work and will thus be overridden.
@@ -4,7 +4,10 @@ require 'premailer-rails3/premailer'
4
4
  require 'premailer-rails3/hook'
5
5
 
6
6
  module PremailerRails
7
- @config = {}
7
+ @config = {
8
+ :input_encoding => 'UTF-8',
9
+ :generate_text_part => true
10
+ }
8
11
  class << self
9
12
  attr_accessor :config
10
13
  end
@@ -51,9 +51,9 @@ module PremailerRails
51
51
  end
52
52
 
53
53
  @@css_cache[path]
54
- rescue => ex
55
- # Print an error and return empty css:
56
- puts ex.message
54
+ rescue NoMethodError => ex
55
+ # Log an error and return empty css:
56
+ Rails.logger.try(:warn, ex.message)
57
57
  ''
58
58
  end
59
59
 
@@ -5,27 +5,37 @@ module PremailerRails
5
5
  # case, if the mail content type is text/html, the body part will be the
6
6
  # html body.
7
7
  if message.html_part
8
- html_body = message.html_part.body.to_s
8
+ html_body = message.html_part.body.to_s
9
+ needs_multipart = true
10
+ message.parts.delete(message.html_part)
9
11
  elsif message.content_type =~ /text\/html/
10
- html_body = message.body.to_s
11
- message.body = nil
12
+ html_body = message.body.to_s
13
+ message.body = nil
14
+ needs_multipart = PremailerRails.config[:generate_text_part]
12
15
  end
13
16
 
14
17
  if html_body
15
18
  premailer = Premailer.new(html_body)
16
19
  charset = message.charset
17
20
 
18
- # IMPRTANT: Plain text part must be generated before CSS is inlined.
19
- # Not doing so results in CSS declarations visible in the plain text
20
- # part.
21
- message.text_part do
22
- content_type "text/plain; charset=#{charset}"
23
- body premailer.to_plain_text
24
- end unless message.text_part
21
+ if needs_multipart
22
+ # IMPORTANT: Plain text part must be generated before CSS is inlined.
23
+ # Not doing so results in CSS declarations visible in the plain text
24
+ # part.
25
+ if PremailerRails.config[:generate_text_part] \
26
+ and not message.text_part
27
+ message.text_part do
28
+ content_type "text/plain; charset=#{charset}"
29
+ body premailer.to_plain_text
30
+ end
31
+ end
25
32
 
26
- message.html_part do
27
- content_type "text/html; charset=#{charset}"
28
- body premailer.to_inline_css
33
+ message.html_part do
34
+ content_type "text/html; charset=#{charset}"
35
+ body premailer.to_inline_css
36
+ end
37
+ else
38
+ message.body = premailer.to_inline_css
29
39
  end
30
40
  end
31
41
  end
@@ -7,14 +7,11 @@ module PremailerRails
7
7
  # suitable adaptor (Nokogiri or Hpricot). To make load_html work, an
8
8
  # adaptor needs to be included and @options[:with_html_string] needs to be
9
9
  # set. For further information, refer to ::Premailer#initialize.
10
- @options = { :with_html_string => true }
10
+ @options = PremailerRails.config.merge(:with_html_string => true)
11
11
  ::Premailer.send(:include, Adapter.find(Adapter.use))
12
12
  doc = load_html(html)
13
13
 
14
- options = PremailerRails.config.merge(
15
- :with_html_string => true,
16
- :css_string => CSSHelper.css_for_doc(doc)
17
- )
14
+ options = @options.merge(:css_string => CSSHelper.css_for_doc(doc))
18
15
  super(html, options)
19
16
  end
20
17
  end
@@ -1,3 +1,3 @@
1
1
  module PremailerRails
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -20,6 +20,20 @@ describe PremailerRails::Hook do
20
20
  PremailerRails::Premailer.any_instance.expects(:to_inline_css)
21
21
  run_hook(message)
22
22
  end
23
+
24
+ it 'should not create a text part if disabled' do
25
+ PremailerRails::Premailer.any_instance.expects(:to_plain_text).never
26
+ PremailerRails.config[:generate_text_part] = false
27
+ run_hook(message)
28
+ PremailerRails.config[:generate_text_part] = true
29
+ message.text_part.should be_nil
30
+ message.html_part.should be_a Mail::Part
31
+ end
32
+
33
+ it 'should not create an additional html part' do
34
+ run_hook(message)
35
+ message.parts.count { |i| i.content_type =~ /text\/html/ }.should == 1
36
+ end
23
37
  end
24
38
 
25
39
  context 'when message contains text part' do
@@ -59,6 +73,16 @@ describe PremailerRails::Hook do
59
73
  run_hook(message)
60
74
  message.html_part.should be_a Mail::Part
61
75
  end
76
+
77
+ it 'should not create a text part if disabled' do
78
+ PremailerRails::Premailer.any_instance.expects(:to_plain_text).never
79
+ PremailerRails.config[:generate_text_part] = false
80
+ run_hook(message)
81
+ PremailerRails.config[:generate_text_part] = true
82
+ message.text_part.should be_nil
83
+ message.html_part.should be_nil
84
+ message.body.should_not be_empty
85
+ end
62
86
  end
63
87
 
64
88
  context 'when message contains text body' do
@@ -3,8 +3,6 @@ require 'spec_helper'
3
3
  describe PremailerRails do
4
4
  describe '#config' do
5
5
  subject { PremailerRails.config }
6
- it { should == {} }
7
-
8
6
  context 'when set' do
9
7
  before { PremailerRails.config = { :foo => :bar } }
10
8
  it { should == { :foo => :bar } }
@@ -37,5 +37,12 @@ describe PremailerRails::Premailer do
37
37
  premailer = PremailerRails::Premailer.new('some html')
38
38
  premailer.instance_variable_get(:'@options')[:foo].should == :bar
39
39
  end
40
+
41
+ it 'should not allow to override with_html_string' do
42
+ PremailerRails.config = { :with_html_string => false }
43
+ premailer = PremailerRails::Premailer.new('some html')
44
+ options = premailer.instance_variable_get(:'@options')
45
+ options[:with_html_string].should == true
46
+ end
40
47
  end
41
48
  end
@@ -1,5 +1,11 @@
1
1
  require 'stubs/dummy'
2
2
 
3
+ module Logger
4
+ extend self
5
+
6
+ def try(*args); end
7
+ end
8
+
3
9
  module Rails
4
10
  extend self
5
11
 
@@ -30,7 +36,13 @@ module Rails
30
36
  module Application
31
37
  extend self
32
38
 
33
- def assets; end
39
+ module Assets
40
+ extend self
41
+ end
42
+
43
+ def assets
44
+ Assets
45
+ end
34
46
  end
35
47
 
36
48
  def env
@@ -41,6 +53,10 @@ module Rails
41
53
  Configuration
42
54
  end
43
55
 
56
+ def logger
57
+ Logger
58
+ end
59
+
44
60
  def root
45
61
  'RAILS_ROOT'
46
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: premailer-rails3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.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-02-28 00:00:00.000000000Z
12
+ date: 2012-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: premailer
16
- requirement: &2151950140 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2151950140
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.7'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rails
27
- requirement: &2151949620 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '3'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2151949620
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec-core
38
- requirement: &2151949240 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2151949240
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec-expectations
49
- requirement: &2151948780 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *2151948780
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: mocha
60
- requirement: &2151948360 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *2151948360
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: mail
71
- requirement: &2151947940 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *2151947940
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: nokogiri
82
- requirement: &2151947520 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *2151947520
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: hpricot
93
- requirement: &2151947100 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,7 +133,12 @@ dependencies:
98
133
  version: '0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *2151947100
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  description: ! "This gem brings you the power of the premailer gem to Rails 3\n without
103
143
  any configuration needs. Create HTML emails, include a\n CSS
104
144
  file as you do in a normal HTML document and premailer will\n inline
@@ -113,6 +153,7 @@ files:
113
153
  - .rspec
114
154
  - CHANGELOG.md
115
155
  - Gemfile
156
+ - LICENSE
116
157
  - README.md
117
158
  - Rakefile
118
159
  - lib/premailer-rails3.rb
@@ -153,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
194
  version: '0'
154
195
  requirements: []
155
196
  rubyforge_project: premailer-rails3
156
- rubygems_version: 1.8.8
197
+ rubygems_version: 1.8.23
157
198
  signing_key:
158
199
  specification_version: 3
159
200
  summary: Easily create HTML emails in Rails 3.