actionmailer_inline_css 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ActionMailer Inline CSS
1
+ # ActionMailer Inline CSS [![TravisCI](http://travis-ci.org/ndbroadbent/actionmailer_inline_css.png?branch=master)](http://travis-ci.org/ndbroadbent/actionmailer_inline_css)
2
2
 
3
3
  Seamlessly integrate [Alex Dunae's premailer](http://premailer.dialect.ca/) gem with ActionMailer.
4
4
 
@@ -1,10 +1,10 @@
1
+ #!/usr/bin/env rake
1
2
  $:.unshift File.expand_path('../lib', __FILE__)
2
3
 
3
4
  require 'rake'
4
5
  require 'rake/testtask'
5
- require 'rake/rdoctask'
6
6
  require 'rake/packagetask'
7
- require 'rake/gempackagetask'
7
+ require 'rubygems/package_task'
8
8
 
9
9
  def gemspec
10
10
  @gemspec ||= begin
@@ -13,7 +13,17 @@ def gemspec
13
13
  end
14
14
  end
15
15
 
16
- Rake::GemPackageTask.new(gemspec) do |pkg|
16
+ Gem::PackageTask.new(gemspec) do |pkg|
17
17
  pkg.need_tar = true
18
18
  end
19
19
 
20
+
21
+ desc "Default Task"
22
+ task :default => [ :test ]
23
+
24
+ # Run the unit tests
25
+ Rake::TestTask.new { |t|
26
+ t.libs << "test"
27
+ t.pattern = 'test/**/*_test.rb'
28
+ }
29
+
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "actionmailer_inline_css"
3
- s.version = "1.0.1"
3
+ s.version = "1.0.3"
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
  s.summary = "Always send HTML e-mails with inline CSS, using the 'premailer' gem"
6
6
  s.email = "nathan.f77@gmail.com"
@@ -15,5 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.add_dependency('actionmailer', '>= 3.0.0')
16
16
  s.add_dependency('premailer', '>= 1.7.1')
17
17
  s.add_dependency('nokogiri', '>= 1.4.4')
18
+ s.add_development_dependency('mocha', '>= 0.10.0')
18
19
  end
19
20
 
@@ -5,7 +5,7 @@ module ActionMailer
5
5
  class InlineCssHook
6
6
  def self.delivering_email(message)
7
7
  if html_part = (message.html_part || (message.content_type =~ /text\/html/ && message))
8
- premailer = Premailer.new(html_part.body.to_s, :with_html_string => true)
8
+ premailer = ::Premailer.new(html_part.body.to_s, :with_html_string => true)
9
9
  existing_text_part = message.text_part && message.text_part.body.to_s
10
10
  # Reset the body
11
11
  message.body = nil
@@ -0,0 +1,96 @@
1
+ # Pathname has a warning, so require it first while silencing
2
+ # warnings to shut it up.
3
+ #
4
+ # Also, in 1.9, Bundler creates warnings due to overriding
5
+ # Rubygems methods
6
+ begin
7
+ old, $VERBOSE = $VERBOSE, nil
8
+ require 'pathname'
9
+ require 'rubygems' unless defined? Gem
10
+ require 'bundler'
11
+ Bundler.setup
12
+ ensure
13
+ $VERBOSE = old
14
+ end
15
+
16
+ require 'active_support/core_ext/kernel/reporting'
17
+
18
+ require 'active_support/core_ext/string/encoding'
19
+ if "ruby".encoding_aware?
20
+ # These are the normal settings that will be set up by Railties
21
+ # TODO: Have these tests support other combinations of these values
22
+ silence_warnings do
23
+ Encoding.default_internal = "UTF-8"
24
+ Encoding.default_external = "UTF-8"
25
+ end
26
+ end
27
+
28
+ lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
29
+ $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
30
+
31
+ require 'test/unit'
32
+ require 'mocha'
33
+
34
+ require 'action_mailer'
35
+ require 'action_mailer/test_case'
36
+ require 'actionmailer_inline_css'
37
+
38
+ silence_warnings do
39
+ # These external dependencies have warnings :/
40
+ require 'mail'
41
+ end
42
+
43
+ # Show backtraces for deprecated behavior for quicker cleanup.
44
+ ActiveSupport::Deprecation.debug = true
45
+
46
+ # Bogus template processors
47
+ ActionView::Template.register_template_handler :haml, lambda { |template| "Look its HAML!".inspect }
48
+ ActionView::Template.register_template_handler :bak, lambda { |template| "Lame backup".inspect }
49
+
50
+ FIXTURE_LOAD_PATH = File.expand_path('fixtures', File.dirname(__FILE__))
51
+ ActionMailer::Base.view_paths = FIXTURE_LOAD_PATH
52
+
53
+ class MockSMTP
54
+ def self.deliveries
55
+ @@deliveries
56
+ end
57
+
58
+ def initialize
59
+ @@deliveries = []
60
+ end
61
+
62
+ def sendmail(mail, from, to)
63
+ @@deliveries << [mail, from, to]
64
+ end
65
+
66
+ def start(*args)
67
+ yield self
68
+ end
69
+ end
70
+
71
+ class Net::SMTP
72
+ def self.new(*args)
73
+ MockSMTP.new
74
+ end
75
+ end
76
+
77
+ # Simple Rails mock for paths
78
+ class Rails
79
+ class << self
80
+ def root; self; end
81
+ def join(*args); self; end
82
+ def to_s; "path"; end
83
+ end
84
+ end
85
+
86
+ def set_delivery_method(method)
87
+ @old_delivery_method = ActionMailer::Base.delivery_method
88
+ ActionMailer::Base.delivery_method = method
89
+ end
90
+
91
+ def restore_delivery_method
92
+ ActionMailer::Base.delivery_method = @old_delivery_method
93
+ end
94
+
95
+ ActiveSupport::Deprecation.silenced = true
96
+
@@ -0,0 +1,29 @@
1
+ require 'abstract_unit'
2
+
3
+ class HelperMailer < ActionMailer::Base
4
+ helper ActionMailer::InlineCssHelper
5
+
6
+ def use_embedded_style_tag
7
+ mail_with_defaults do |format|
8
+ format.html { render(:inline => "<%= embedded_style_tag %>") }
9
+ end
10
+ end
11
+
12
+ protected
13
+
14
+ def mail_with_defaults(&block)
15
+ mail(:to => "test@localhost", :from => "tester@example.com",
16
+ :subject => "using helpers", &block)
17
+ end
18
+ end
19
+
20
+ class InlineCssHelperTest < ActionMailer::TestCase
21
+ def test_embedded_style_tag
22
+ css = "body { display: none; }"
23
+ File.stubs(:exist?).returns(true)
24
+ File.stubs(:read).returns(css)
25
+ mail = HelperMailer.use_embedded_style_tag
26
+ assert_match "<style type=\"text/css\">#{css}</style>", mail.body.encoded
27
+ end
28
+ end
29
+
@@ -0,0 +1,38 @@
1
+ require 'abstract_unit'
2
+
3
+ class HelperMailer < ActionMailer::Base
4
+ helper ActionMailer::InlineCssHelper
5
+
6
+ def use_inline_css_hook
7
+ mail_with_defaults do |format|
8
+ format.html { render(:inline => %Q{
9
+ <html>
10
+ <head>
11
+ <style>
12
+ #test { color: #123456; }
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <div id="test">Test</div>
17
+ </body>
18
+ </html>
19
+ }) }
20
+ format.text { render(:inline => "Text Part") }
21
+ end
22
+ end
23
+
24
+ protected
25
+
26
+ def mail_with_defaults(&block)
27
+ mail(:to => "test@localhost", :from => "tester@example.com",
28
+ :subject => "using helpers", &block)
29
+ end
30
+ end
31
+
32
+ class InlineCssHookTest < ActionMailer::TestCase
33
+ def test_inline_css_hook
34
+ mail = HelperMailer.use_inline_css_hook.deliver
35
+ assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.body.encoded
36
+ end
37
+ end
38
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmailer_inline_css
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
16
- requirement: &23304640 !ruby/object:Gem::Requirement
16
+ requirement: &15951960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *23304640
24
+ version_requirements: *15951960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: premailer
27
- requirement: &23303720 !ruby/object:Gem::Requirement
27
+ requirement: &15951440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.7.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *23303720
35
+ version_requirements: *15951440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &23302940 !ruby/object:Gem::Requirement
38
+ requirement: &15818220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,18 @@ dependencies:
43
43
  version: 1.4.4
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *23302940
46
+ version_requirements: *15818220
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: &15817740 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *15817740
47
58
  description: Module for ActionMailer to improve the rendering of HTML emails by using
48
59
  the 'premailer' gem, which inlines CSS and makes relative links absolute.
49
60
  email: nathan.f77@gmail.com
@@ -54,11 +65,14 @@ files:
54
65
  - .gitignore
55
66
  - Gemfile
56
67
  - README.md
57
- - Rakefile.rb
68
+ - Rakefile
58
69
  - actionmailer_inline_css.gemspec
59
70
  - lib/action_mailer/inline_css_helper.rb
60
71
  - lib/action_mailer/inline_css_hook.rb
61
72
  - lib/actionmailer_inline_css.rb
73
+ - test/abstract_unit.rb
74
+ - test/inline_css_helper_test.rb
75
+ - test/inline_css_hook_test.rb
62
76
  homepage: http://premailer.dialect.ca/
63
77
  licenses: []
64
78
  post_install_message:
@@ -73,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
87
  version: '0'
74
88
  segments:
75
89
  - 0
76
- hash: 3717499583811940156
90
+ hash: -1512887497751665596
77
91
  required_rubygems_version: !ruby/object:Gem::Requirement
78
92
  none: false
79
93
  requirements:
@@ -82,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
96
  version: '0'
83
97
  segments:
84
98
  - 0
85
- hash: 3717499583811940156
99
+ hash: -1512887497751665596
86
100
  requirements: []
87
101
  rubyforge_project:
88
102
  rubygems_version: 1.8.8