premailer-rails 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41073202cdcfc614302e4ebd78983e637bca0509
4
- data.tar.gz: e6cffc67a632087c4403ae5ae3bc315f6949bcee
3
+ metadata.gz: faaccc100fbcc92e0c79ee426a2a3b4b2ae16ecd
4
+ data.tar.gz: 4e183a0856f2bcd01e5955efc1d7bd750e19edf4
5
5
  SHA512:
6
- metadata.gz: af6af666d40e0d924d3a8982fd240d407d9b5f01e8295d03c7aaa411285876ef23c03dc54aad10e0c4e0e28caa0c5132f7d0230c74edf0828e79664e1b30bf37
7
- data.tar.gz: e1b3fa698a622be4fe6fd1bd18d9407dbac7823417fc0bf251adda5af9f096dec35fdbbca0f055dc5754fe7de763db3e541cfd84edbf0180d44a8d81012ffcbd
6
+ metadata.gz: 83535e5fd7f0b6540c8d9e18769a6b3e0dd0112559f56fa33dd279bbd399e281aee0ecbf3f885aea3bad3e529f2eca0026ef8c1092c6b70844c214caec7ddb6d
7
+ data.tar.gz: e195868f2495abe7d4a8b188f389d0a84ce9870d1b66e48793b62b8c72722ed86d3bf73d2fce29d8869c63f692677b035423732e2befe2ea1e98570c95dad282
@@ -3,8 +3,6 @@ script: "bundle exec rspec"
3
3
  rvm:
4
4
  - 2.0.0
5
5
  - 1.9.3
6
- - 1.8.7
7
- - jruby-18mode # JRuby in 1.8 mode
8
- - jruby-19mode # JRuby in 1.9 mode
9
- - rbx-18mode
6
+ - jruby-19mode
10
7
  - rbx-19mode
8
+ env: "JRUBY_OPTS=--debug"
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.5.0
4
+
5
+ - No longer support ruby 1.8
6
+
7
+ - Find linked stylesheets by `rel='stylesheet'` attribute instead of
8
+ `type='text/css'`
9
+
10
+ - Don't test hpricot on JRuby due to incompatibility
11
+
12
+ ## v1.4.0
13
+
14
+ - Fix attachments
15
+
16
+ ## v1.3.2
17
+
18
+ - Rename gem to premailer-rails (drop the 3)
19
+
20
+ - Add support for rails 4
21
+
22
+ - Refactor code
23
+
24
+ - Add support for precompiled assets
25
+
26
+ - No longer include default `email.css`
27
+
3
28
  ## v1.1.0
4
29
 
5
30
  - Fixed several bugs
data/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/premailer-rails.png)](http://badge.fury.io/rb/premailer-rails)
5
5
  [![Dependency Status](https://gemnasium.com/fphilipe/premailer-rails.png)](https://gemnasium.com/fphilipe/premailer-rails)
6
6
  [![Code Climate](https://codeclimate.com/github/fphilipe/premailer-rails.png)](https://codeclimate.com/github/fphilipe/premailer-rails)
7
- [![Coverage Status](https://coveralls.io/repos/fphilipe/premailer-rails/badge.png?branch=master)](https://coveralls.io/r/fphilipe/premailer-rails)
8
7
 
9
8
  This gem is a no config solution for the wonderful [Premailer gem](https://github.com/alexdunae/premailer) to be used with Rails.
10
9
  It uses interceptors which were introduced in Rails 3 and tweaks all mails which are `deliver`ed and adds a plain text part to them and inlines all CSS rules into the HTML part.
@@ -12,7 +11,7 @@ It uses interceptors which were introduced in Rails 3 and tweaks all mails which
12
11
  By default it inlines all inline `<style>` declarations and all the CSS files that are linked to in the HTML:
13
12
 
14
13
  ```html
15
- <link type='text/css' ... />
14
+ <link rel="stylesheet" ... />
16
15
  ```
17
16
 
18
17
  Don't worry about the host in the CSS URL since this will be ignored.
@@ -50,8 +49,8 @@ pass these options on to the underlying premailer instance, specify them in an
50
49
  initializer:
51
50
 
52
51
  ```ruby
53
- Premailer::Rails.config.merge!(:preserve_styles => true,
54
- :remove_ids => true)
52
+ Premailer::Rails.config.merge!(preserve_styles: true,
53
+ remove_ids: true)
55
54
  ```
56
55
 
57
56
  For a list of options, refer to the [Premailer documentation](http://rubydoc.info/gems/premailer/1.7.3/Premailer:initialize)
@@ -60,9 +59,9 @@ The default configs are:
60
59
 
61
60
  ```ruby
62
61
  {
63
- :input_encoding => 'UTF-8',
64
- :inputencoding => 'UTF-8',
65
- :generate_text_part => true
62
+ input_encoding: 'UTF-8',
63
+ inputencoding: 'UTF-8',
64
+ generate_text_part: true
66
65
  }
67
66
  ```
68
67
 
@@ -73,3 +72,7 @@ If you want to use another encoding make sure to specify the right one or both.
73
72
  If you don't want to automatically generate a text part from the html part, set the config `:generate_text_part` to false.
74
73
 
75
74
  Note that the options `:with_html_string` and `:css_string` are used internally and thus will be overridden.
75
+
76
+
77
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/fphilipe/premailer-rails/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
78
+
data/Rakefile CHANGED
@@ -4,4 +4,4 @@ Bundler::GemHelper.install_tasks
4
4
  require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
7
- task :default => :spec
7
+ task default: :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.5.0
@@ -11,9 +11,9 @@ require 'premailer/rails/nokogiri_fix'
11
11
  class Premailer
12
12
  module Rails
13
13
  @config = {
14
- :input_encoding => 'UTF-8',
15
- :inputencoding => 'UTF-8',
16
- :generate_text_part => true
14
+ input_encoding: 'UTF-8',
15
+ inputencoding: 'UTF-8',
16
+ generate_text_part: true
17
17
  }
18
18
  class << self
19
19
  attr_accessor :config
@@ -24,7 +24,7 @@ class Premailer
24
24
  private
25
25
 
26
26
  def css_urls_in_doc(doc)
27
- doc.search('link[@type="text/css"]').map do |link|
27
+ doc.search('link[@rel="stylesheet"]').map do |link|
28
28
  link.attributes['href'].to_s
29
29
  end
30
30
  end
@@ -32,8 +32,9 @@ class Premailer
32
32
  end
33
33
 
34
34
  def file_name(path)
35
- path.sub("#{::Rails.configuration.assets.prefix}/", '') \
36
- .sub(/-.*\.css$/, '.css')
35
+ path
36
+ .sub("#{::Rails.configuration.assets.prefix}/", '')
37
+ .sub(/-\h{32}\.css$/, '.css')
37
38
  end
38
39
 
39
40
  def request_and_unzip(file)
@@ -8,11 +8,11 @@ class Premailer
8
8
  # suitable adaptor (Nokogiri or Hpricot). To make load_html work, an
9
9
  # adaptor needs to be included and @options[:with_html_string] needs to
10
10
  # be set. For further information, refer to ::Premailer#initialize.
11
- @options = Rails.config.merge(:with_html_string => true)
11
+ @options = Rails.config.merge(with_html_string: true)
12
12
  Premailer.send(:include, Adapter.find(Adapter.use))
13
13
  doc = load_html(html)
14
14
 
15
- options = @options.merge(:css_string => CSSHelper.css_for_doc(doc))
15
+ options = @options.merge(css_string: CSSHelper.css_for_doc(doc))
16
16
  super(html, options)
17
17
  end
18
18
  end
@@ -44,7 +44,7 @@ class Premailer
44
44
  end
45
45
 
46
46
  def generate_alternative_part
47
- part = Mail::Part.new(:content_type => 'multipart/alternative')
47
+ part = Mail::Part.new(content_type: 'multipart/alternative')
48
48
  part.add_part(generate_html_part)
49
49
  part.add_part(generate_text_part)
50
50
 
@@ -57,18 +57,18 @@ class Premailer
57
57
  generate_text_part if generate_text_part?
58
58
 
59
59
  Mail::Part.new(
60
- :content_type => "text/html; charset=#{html_part.charset}",
61
- :body => premailer.to_inline_css)
60
+ content_type: "text/html; charset=#{html_part.charset}",
61
+ body: premailer.to_inline_css)
62
62
  end
63
63
 
64
64
  def generate_text_part
65
65
  @text_part ||= Mail::Part.new(
66
- :content_type => "text/plain; charset=#{html_part.charset}",
67
- :body => premailer.to_plain_text)
66
+ content_type: "text/plain; charset=#{html_part.charset}",
67
+ body: premailer.to_plain_text)
68
68
  end
69
69
 
70
70
  def premailer
71
- @premailer ||= CustomizedPremailer.new(html_part.body.to_s)
71
+ @premailer ||= CustomizedPremailer.new(html_part.decoded)
72
72
  end
73
73
 
74
74
  def html_part
@@ -91,7 +91,7 @@ class Premailer
91
91
  # are used for the message. If the new part is
92
92
  def replace_in_pure_html_message(new_part)
93
93
  if new_part.content_type.include?('text/html')
94
- message.body = new_part.body.to_s
94
+ message.body = new_part.decoded
95
95
  message.content_type = new_part.content_type
96
96
  else
97
97
  message.body = nil
@@ -20,14 +20,13 @@ Gem::Specification.new do |s|
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_dependency("premailer", ["~> 1.7"])
24
- s.add_dependency("rails", [">= 3"])
23
+ s.add_dependency 'premailer', '~> 1.7'
24
+ s.add_dependency 'rails', '>= 3'
25
25
 
26
26
  s.add_development_dependency 'rspec-core'
27
27
  s.add_development_dependency 'rspec-expectations'
28
28
  s.add_development_dependency 'mocha'
29
29
  s.add_development_dependency 'mail'
30
30
  s.add_development_dependency 'nokogiri'
31
- s.add_development_dependency 'hpricot'
32
- s.add_development_dependency 'coveralls'
31
+ s.add_development_dependency 'hpricot' unless RUBY_PLATFORM == 'java'
33
32
  end
@@ -19,7 +19,7 @@ module Fixtures
19
19
  HTML
20
20
 
21
21
  LINK = <<-LINK
22
- <link rel='stylesheet' type='text/css' href='%s' />
22
+ <link rel='stylesheet' href='%s' />
23
23
  LINK
24
24
 
25
25
  def with_css_links(*files)
@@ -52,7 +52,7 @@ nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
52
52
  content_part = message
53
53
 
54
54
  if part_types.include?(:html) and part_types.include?(:text)
55
- content_part = Mail::Part.new(:content_type => 'multipart/alternative')
55
+ content_part = Mail::Part.new(content_type: 'multipart/alternative')
56
56
  message.add_part(content_part)
57
57
  end
58
58
 
@@ -73,7 +73,7 @@ nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
73
73
  end
74
74
 
75
75
  if part_types.include? :attachment
76
- message.add_file(:filename => 'foo.png', :content => 'foobar')
76
+ message.add_file(filename: 'foo.png', content: 'foobar')
77
77
  end
78
78
 
79
79
  message.ready_to_send!
@@ -14,19 +14,19 @@ describe Premailer::Rails::CSSHelper do
14
14
 
15
15
  describe '#css_for_doc' do
16
16
  let(:html) { Fixtures::HTML.with_css_links(*files) }
17
- let(:doc) { Hpricot(html) }
17
+ let(:doc) { Nokogiri(html) }
18
18
 
19
19
  context 'when HTML contains linked CSS files' do
20
20
  let(:files) { %w[ stylesheets/base.css stylesheets/font.css ] }
21
21
 
22
22
  it 'should return the content of both files concatenated' do
23
- Premailer::Rails::CSSHelper \
24
- .expects(:load_css) \
25
- .with('http://example.com/stylesheets/base.css') \
23
+ Premailer::Rails::CSSHelper
24
+ .expects(:load_css)
25
+ .with('http://example.com/stylesheets/base.css')
26
26
  .returns('content of base.css')
27
- Premailer::Rails::CSSHelper \
28
- .expects(:load_css) \
29
- .with('http://example.com/stylesheets/font.css') \
27
+ Premailer::Rails::CSSHelper
28
+ .expects(:load_css)
29
+ .with('http://example.com/stylesheets/font.css')
30
30
  .returns('content of font.css')
31
31
 
32
32
  css_for_doc(doc).should == "content of base.css\ncontent of font.css"
@@ -57,7 +57,7 @@ describe Premailer::Rails::CSSHelper do
57
57
  Premailer::Rails::CSSHelper.send(:instance_variable_get, '@cache')
58
58
  cache['/stylesheets/base.css'] = 'content of base.css'
59
59
 
60
- load_css('http://example.com/stylesheets/base.css') \
60
+ load_css('http://example.com/stylesheets/base.css')
61
61
  .should == 'content of base.css'
62
62
  end
63
63
  end
@@ -67,12 +67,12 @@ describe Premailer::Rails::CSSHelper do
67
67
  cache =
68
68
  Premailer::Rails::CSSHelper.send(:instance_variable_get, '@cache')
69
69
  cache['/stylesheets/base.css'] = 'cached content of base.css'
70
- File.expects(:read) \
71
- .with('RAILS_ROOT/public/stylesheets/base.css') \
70
+ File.expects(:read)
71
+ .with('RAILS_ROOT/public/stylesheets/base.css')
72
72
  .returns('new content of base.css')
73
73
  Rails.env.stubs(:development?).returns(true)
74
74
 
75
- load_css('http://example.com/stylesheets/base.css') \
75
+ load_css('http://example.com/stylesheets/base.css')
76
76
  .should == 'new content of base.css'
77
77
  end
78
78
  end
@@ -81,26 +81,27 @@ describe Premailer::Rails::CSSHelper do
81
81
  before {
82
82
  Rails.configuration.stubs(:assets).returns(
83
83
  stub(
84
- :enabled => true,
85
- :prefix => '/assets'
84
+ enabled: true,
85
+ prefix: '/assets'
86
86
  )
87
87
  )
88
88
  }
89
89
 
90
90
  it 'should return the content of the file compiled by Rails' do
91
- Rails.application.assets.expects(:find_asset) \
92
- .with('base.css') \
93
- .returns(mock(:to_s => 'content of base.css'))
91
+ Rails.application.assets
92
+ .expects(:find_asset)
93
+ .with('base.css')
94
+ .returns(mock(to_s: 'content of base.css'))
94
95
 
95
- load_css('http://example.com/assets/base.css') \
96
+ load_css('http://example.com/assets/base.css')
96
97
  .should == 'content of base.css'
97
98
  end
98
99
 
99
100
  it 'should return same file when path contains file fingerprint' do
100
- Rails.application.assets \
101
- .expects(:find_asset) \
102
- .with('base.css') \
103
- .returns(mock(:to_s => 'content of base.css'))
101
+ Rails.application.assets
102
+ .expects(:find_asset)
103
+ .with('base.css')
104
+ .returns(mock(to_s: 'content of base.css'))
104
105
 
105
106
  load_css(
106
107
  'http://example.com/assets/base-089e35bd5d84297b8d31ad552e433275.css'
@@ -111,13 +112,13 @@ describe Premailer::Rails::CSSHelper do
111
112
  before {
112
113
  Rails.application.assets.stubs(:find_asset).returns(nil)
113
114
  Rails.configuration.stubs(:action_controller).returns(
114
- stub(:asset_host => 'http://example.com')
115
+ stub(asset_host: 'http://example.com')
115
116
  )
116
117
  Rails.configuration.stubs(:assets).returns(
117
118
  stub(
118
- :enabled => true,
119
- :prefix => '/assets',
120
- :digests => {
119
+ enabled: true,
120
+ prefix: '/assets',
121
+ digests: {
121
122
  'base.css' => 'base-089e35bd5d84297b8d31ad552e433275.css'
122
123
  }
123
124
  )
@@ -148,11 +149,11 @@ describe Premailer::Rails::CSSHelper do
148
149
 
149
150
  context 'when static stylesheets are used' do
150
151
  it 'should return the content of the static file' do
151
- File.expects(:read) \
152
- .with('RAILS_ROOT/public/stylesheets/base.css') \
152
+ File.expects(:read)
153
+ .with('RAILS_ROOT/public/stylesheets/base.css')
153
154
  .returns('content of base.css')
154
155
 
155
- load_css('http://example.com/stylesheets/base.css') \
156
+ load_css('http://example.com/stylesheets/base.css')
156
157
  .should == 'content of base.css'
157
158
  end
158
159
  end
@@ -4,15 +4,17 @@ require 'spec_helper'
4
4
 
5
5
  describe Premailer::Rails::CustomizedPremailer do
6
6
  [ :nokogiri, :hpricot ].each do |adapter|
7
+ next if adapter == :hpricot and RUBY_PLATFORM == 'java'
8
+
7
9
  context "when adapter is #{adapter}" do
8
10
  before { Premailer::Adapter.stubs(:use).returns(adapter) }
9
11
 
10
12
  describe '#to_plain_text' do
11
13
  it 'should include the text from the HTML part' do
12
14
  premailer =
13
- Premailer::Rails::CustomizedPremailer \
15
+ Premailer::Rails::CustomizedPremailer
14
16
  .new(Fixtures::Message::HTML_PART)
15
- premailer.to_plain_text.gsub(/\s/, ' ').strip \
17
+ premailer.to_plain_text.gsub(/\s/, ' ').strip
16
18
  .should == Fixtures::Message::TEXT_PART.gsub(/\s/, ' ').strip
17
19
  end
18
20
  end
@@ -20,12 +22,12 @@ describe Premailer::Rails::CustomizedPremailer do
20
22
  describe '#to_inline_css' do
21
23
  context 'when inline CSS block present' do
22
24
  it 'should return the HTML with the CSS inlined' do
23
- Premailer::Rails::CSSHelper \
24
- .stubs(:css_for_doc) \
25
+ Premailer::Rails::CSSHelper
26
+ .stubs(:css_for_doc)
25
27
  .returns('p { color: red; }')
26
28
  html = Fixtures::Message::HTML_PART
27
29
  premailer = Premailer::Rails::CustomizedPremailer.new(html)
28
- premailer.to_inline_css.should include '<p style="color: red;">'
30
+ premailer.to_inline_css.should =~ /<p style=("|')color: ?red;?\1>/
29
31
  end
30
32
  end
31
33
 
@@ -33,7 +35,7 @@ describe Premailer::Rails::CustomizedPremailer do
33
35
  it 'should return the HTML with the CSS inlined' do
34
36
  html = Fixtures::Message::HTML_PART_WITH_CSS
35
37
  premailer = Premailer::Rails::CustomizedPremailer.new(html)
36
- premailer.to_inline_css.should include '<p style="color: red;">'
38
+ premailer.to_inline_css.should =~ /<p style=("|')color: ?red;?\1>/
37
39
  end
38
40
  end
39
41
  end
@@ -47,13 +49,13 @@ describe Premailer::Rails::CustomizedPremailer do
47
49
  end
48
50
 
49
51
  it 'should pass on the configs' do
50
- Premailer::Rails.config = { :foo => :bar }
52
+ Premailer::Rails.config = { foo: :bar }
51
53
  premailer = Premailer::Rails::CustomizedPremailer.new('some html')
52
54
  premailer.instance_variable_get(:'@options')[:foo].should == :bar
53
55
  end
54
56
 
55
57
  it 'should not allow to override with_html_string' do
56
- Premailer::Rails.config = { :with_html_string => false }
58
+ Premailer::Rails.config = { with_html_string: false }
57
59
  premailer = Premailer::Rails::CustomizedPremailer.new('some html')
58
60
  options = premailer.instance_variable_get(:'@options')
59
61
  options[:with_html_string].should == true
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe 'ActionMailer::Base.register_interceptor' do
4
4
  it 'should register interceptor Premailer::Rails::Hook' do
5
- ActionMailer::Base \
6
- .expects(:register_interceptor) \
5
+ ActionMailer::Base
6
+ .expects(:register_interceptor)
7
7
  .with(Premailer::Rails::Hook)
8
8
  load 'premailer/rails.rb'
9
9
  end
@@ -4,8 +4,8 @@ describe Premailer::Rails do
4
4
  describe '#config' do
5
5
  subject { Premailer::Rails.config }
6
6
  context 'when set' do
7
- before { Premailer::Rails.config = { :foo => :bar } }
8
- it { should == { :foo => :bar } }
7
+ before { Premailer::Rails.config = { foo: :bar } }
8
+ it { should == { foo: :bar } }
9
9
  end
10
10
  end
11
11
  end
@@ -1,10 +1,3 @@
1
- if RUBY_VERSION >= '1.9'
2
- require 'coveralls'
3
- Coveralls.wear! do
4
- add_filter 'spec/'
5
- end
6
- end
7
-
8
1
  require 'premailer/rails'
9
2
 
10
3
  require 'stubs/action_mailer'
@@ -12,7 +5,7 @@ require 'stubs/rails'
12
5
  require 'fixtures/message'
13
6
  require 'fixtures/html'
14
7
 
15
- require 'hpricot'
8
+ require 'hpricot' unless RUBY_PLATFORM == 'java'
16
9
  require 'nokogiri'
17
10
 
18
11
  RSpec.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: premailer-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipe Fatio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-04 00:00:00.000000000 Z
11
+ date: 2013-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: premailer
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: coveralls
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '>='
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '>='
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
125
  description: |-
140
126
  This gem brings you the power of the premailer gem to Rails
141
127
  without any configuration needs. Create HTML emails,
@@ -195,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
181
  version: '0'
196
182
  requirements: []
197
183
  rubyforge_project:
198
- rubygems_version: 2.0.0
184
+ rubygems_version: 2.0.2
199
185
  signing_key:
200
186
  specification_version: 4
201
187
  summary: Easily create styled HTML emails in Rails.