premailer-rails 1.9.5 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +64 -0
  3. data/.gitignore +4 -0
  4. data/CHANGELOG.md +40 -0
  5. data/Gemfile +15 -11
  6. data/README.md +32 -37
  7. data/VERSION +1 -1
  8. data/examples/rails5/Gemfile +4 -0
  9. data/{example → examples/rails5}/Rakefile +1 -1
  10. data/{example → examples/rails5}/bin/rails +1 -1
  11. data/{example → examples/rails5}/config/application.rb +4 -1
  12. data/examples/rails5/config/boot.rb +3 -0
  13. data/{example → examples/rails5}/config/environment.rb +1 -1
  14. data/{example → examples/rails5}/config.ru +2 -1
  15. data/examples/rails6/.gitignore +16 -0
  16. data/examples/rails6/Gemfile +5 -0
  17. data/examples/rails6/README.md +10 -0
  18. data/examples/rails6/Rakefile +6 -0
  19. data/examples/rails6/app/assets/config/manifest.js +1 -0
  20. data/examples/rails6/app/assets/stylesheets/email.css +32 -0
  21. data/examples/rails6/app/mailers/example_mailer.rb +7 -0
  22. data/examples/rails6/app/views/example_mailer/test_message.html.erb +18 -0
  23. data/examples/rails6/bin/rails +4 -0
  24. data/examples/rails6/config/application.rb +15 -0
  25. data/examples/rails6/config/boot.rb +3 -0
  26. data/examples/rails6/config/environment.rb +5 -0
  27. data/examples/rails6/config/environments/development.rb +9 -0
  28. data/examples/rails6/config/environments/production.rb +9 -0
  29. data/examples/rails6/config/routes.rb +3 -0
  30. data/examples/rails6/config.ru +6 -0
  31. data/examples/rails6/test/mailers/previews/example_mailer_preview.rb +5 -0
  32. data/examples/rails7-propshaft/.gitignore +16 -0
  33. data/examples/rails7-propshaft/Gemfile +6 -0
  34. data/examples/rails7-propshaft/README.md +10 -0
  35. data/examples/rails7-propshaft/Rakefile +6 -0
  36. data/examples/rails7-propshaft/app/assets/stylesheets/email.css +32 -0
  37. data/examples/rails7-propshaft/app/mailers/example_mailer.rb +7 -0
  38. data/examples/rails7-propshaft/app/views/example_mailer/test_message.html.erb +18 -0
  39. data/examples/rails7-propshaft/bin/rails +4 -0
  40. data/examples/rails7-propshaft/config/application.rb +14 -0
  41. data/examples/rails7-propshaft/config/boot.rb +3 -0
  42. data/examples/rails7-propshaft/config/environment.rb +5 -0
  43. data/examples/rails7-propshaft/config/environments/development.rb +9 -0
  44. data/examples/rails7-propshaft/config/environments/production.rb +9 -0
  45. data/examples/rails7-propshaft/config/routes.rb +3 -0
  46. data/examples/rails7-propshaft/config.ru +6 -0
  47. data/examples/rails7-propshaft/test/mailers/previews/example_mailer_preview.rb +5 -0
  48. data/examples/rails7-sprockets/.gitignore +16 -0
  49. data/examples/rails7-sprockets/Gemfile +6 -0
  50. data/examples/rails7-sprockets/README.md +10 -0
  51. data/examples/rails7-sprockets/Rakefile +6 -0
  52. data/examples/rails7-sprockets/app/assets/config/manifest.js +1 -0
  53. data/examples/rails7-sprockets/app/assets/stylesheets/email.css +32 -0
  54. data/examples/rails7-sprockets/app/mailers/example_mailer.rb +7 -0
  55. data/examples/rails7-sprockets/app/views/example_mailer/test_message.html.erb +18 -0
  56. data/examples/rails7-sprockets/bin/rails +4 -0
  57. data/examples/rails7-sprockets/config/application.rb +14 -0
  58. data/examples/rails7-sprockets/config/boot.rb +3 -0
  59. data/examples/rails7-sprockets/config/environment.rb +5 -0
  60. data/examples/rails7-sprockets/config/environments/development.rb +9 -0
  61. data/examples/rails7-sprockets/config/environments/production.rb +9 -0
  62. data/examples/rails7-sprockets/config/routes.rb +3 -0
  63. data/examples/rails7-sprockets/config.ru +6 -0
  64. data/examples/rails7-sprockets/test/mailers/previews/example_mailer_preview.rb +5 -0
  65. data/lib/premailer/rails/css_helper.rb +32 -11
  66. data/lib/premailer/rails/css_loaders/asset_pipeline_loader.rb +16 -15
  67. data/lib/premailer/rails/css_loaders/file_system_loader.rb +24 -2
  68. data/lib/premailer/rails/css_loaders/network_loader.rb +2 -2
  69. data/lib/premailer/rails/css_loaders/propshaft_loader.rb +38 -0
  70. data/lib/premailer/rails/css_loaders.rb +1 -1
  71. data/lib/premailer/rails/customized_premailer.rb +4 -4
  72. data/lib/premailer/rails/hook.rb +2 -6
  73. data/lib/premailer/rails/railtie.rb +1 -1
  74. data/lib/premailer/rails.rb +2 -1
  75. data/premailer-rails.gemspec +4 -3
  76. data/spec/integration/css_helper_spec.rb +262 -129
  77. data/spec/integration/delivery_spec.rb +13 -0
  78. data/spec/integration/hook_spec.rb +36 -11
  79. data/spec/rails_app/app/assets/config/manifest.js +3 -0
  80. data/spec/rails_app/app/assets/stylesheets/application.css +3 -0
  81. data/spec/rails_app/app/mailers/application_mailer.rb +4 -0
  82. data/spec/rails_app/app/mailers/welcome_mailer.rb +6 -0
  83. data/spec/rails_app/app/views/layouts/mailer.html.erb +11 -0
  84. data/spec/rails_app/app/views/welcome_mailer/welcome_email.html.erb +1 -0
  85. data/spec/rails_app/config/application.rb +19 -0
  86. data/spec/rails_app/config/boot.rb +5 -0
  87. data/spec/rails_app/config/environment.rb +2 -0
  88. data/spec/rails_app/config/environments/test.rb +10 -0
  89. data/spec/rails_app/config/initializers/assets.rb +1 -0
  90. data/spec/rails_app/config/routes.rb +3 -0
  91. data/spec/rails_app/config.ru +5 -0
  92. data/spec/rails_app/log/.keep +0 -0
  93. data/spec/rails_app/tmp/.keep +0 -0
  94. data/spec/spec_helper.rb +3 -17
  95. data/spec/support/fixtures/message.rb +40 -0
  96. data/spec/unit/css_loaders/asset_pipeline_loader_spec.rb +44 -32
  97. data/spec/unit/css_loaders/file_system_loader_spec.rb +37 -0
  98. data/spec/unit/css_loaders/network_loader_spec.rb +1 -1
  99. data/spec/unit/css_loaders/propshaft_loader_spec.rb +57 -0
  100. data/spec/unit/customized_premailer_spec.rb +32 -40
  101. metadata +121 -81
  102. data/.coveralls.yml +0 -1
  103. data/.travis.yml +0 -22
  104. data/example/Gemfile +0 -10
  105. data/example/config/boot.rb +0 -3
  106. data/example/config/secrets.yml +0 -2
  107. data/lib/premailer/rails/css_loaders/cache_loader.rb +0 -29
  108. data/spec/integration/hook_registration_spec.rb +0 -11
  109. data/spec/support/stubs/action_mailer.rb +0 -5
  110. data/spec/support/stubs/rails.rb +0 -51
  111. /data/{example → examples/rails5}/.gitignore +0 -0
  112. /data/{example → examples/rails5}/README.md +0 -0
  113. /data/{example → examples/rails5}/app/assets/stylesheets/email.css +0 -0
  114. /data/{example → examples/rails5}/app/mailers/example_mailer.rb +0 -0
  115. /data/{example → examples/rails5}/app/views/example_mailer/test_message.html.erb +0 -0
  116. /data/{example → examples/rails5}/config/environments/development.rb +0 -0
  117. /data/{example → examples/rails5}/config/environments/production.rb +0 -0
  118. /data/{example → examples/rails5}/config/initializers/assets.rb +0 -0
  119. /data/{example → examples/rails5}/config/routes.rb +0 -0
  120. /data/{example → examples/rails5}/test/mailers/previews/example_mailer_preview.rb +0 -0
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <%= stylesheet_link_tag :email %>
6
+ </head>
7
+ <body>
8
+ <div class='wrap'>
9
+ <p class='greeting'>Hi, John Doe</p>
10
+ <p>
11
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
12
+ </p>
13
+ <div class='footer'>
14
+ To unsubscribe, <a href='http://www.google.com/'>click here</a>.
15
+ </div>
16
+ </div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path("../config/application", __dir__)
3
+ require_relative "../config/boot"
4
+ require "rails/commands"
@@ -0,0 +1,14 @@
1
+ require_relative 'boot'
2
+
3
+ require 'action_controller/railtie'
4
+ require 'action_mailer/railtie'
5
+
6
+ # Require the gems listed in Gemfile, including any gems
7
+ # you've limited to :test, :development, or :production.
8
+ Bundler.require(*Rails.groups)
9
+
10
+ module Example
11
+ class Application < Rails::Application
12
+ config.load_defaults 7.0
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,9 @@
1
+ Rails.application.configure do
2
+ config.cache_classes = false
3
+ config.eager_load = false
4
+ config.consider_all_requests_local = true
5
+ config.action_controller.perform_caching = false
6
+ config.assets.debug = true
7
+ config.assets.digest = true
8
+ config.assets.raise_runtime_errors = true
9
+ end
@@ -0,0 +1,9 @@
1
+ Rails.application.configure do
2
+ config.cache_classes = true
3
+ config.eager_load = true
4
+ config.consider_all_requests_local = false
5
+ config.action_controller.perform_caching = true
6
+ config.assets.compile = false
7
+ config.assets.digest = true
8
+ config.log_level = :info
9
+ end
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ root to: redirect('rails/mailers/example_mailer/test_message')
3
+ end
@@ -0,0 +1,6 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
6
+ Rails.application.load_server
@@ -0,0 +1,5 @@
1
+ class ExampleMailerPreview < ActionMailer::Preview
2
+ def test_message
3
+ ExampleMailer.test_message
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*.log
16
+ /tmp
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 7.0.4'
4
+ gem 'sprockets-rails'
5
+ gem 'webrick' if RUBY_VERSION >= '3'
6
+ gem 'premailer-rails', path: '../..'
@@ -0,0 +1,10 @@
1
+ # Example Rails App
2
+
3
+ To run this app, run:
4
+
5
+ ```shell
6
+ bundle
7
+ bundle exec rails s
8
+ ```
9
+
10
+ Then point your browser at [http://localhost:3000/](http://localhost:3000/).
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1 @@
1
+ //= link email.css
@@ -0,0 +1,32 @@
1
+ body {
2
+ background: #efefef;
3
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
4
+ }
5
+
6
+ p {
7
+ line-height: 1.4;
8
+ }
9
+
10
+ .wrap {
11
+ max-width: 40em;
12
+ margin: 0 auto;
13
+ padding: 1em;
14
+ background: white;
15
+ }
16
+
17
+ .greeting {
18
+ text-align: center;
19
+ font-weight: bold;
20
+ font-size: 110%;
21
+ }
22
+
23
+ .footer {
24
+ font-size: 90%;
25
+ color: #666;
26
+ }
27
+
28
+ a {
29
+ color: green;
30
+ text-decoration: none;
31
+ border-bottom: 2px solid green;
32
+ }
@@ -0,0 +1,7 @@
1
+ class ExampleMailer < ActionMailer::Base
2
+ default from: "from@example.com"
3
+
4
+ def test_message
5
+ mail to: 'to@example.org', subject: 'Test Message'
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <%= stylesheet_link_tag :email %>
6
+ </head>
7
+ <body>
8
+ <div class='wrap'>
9
+ <p class='greeting'>Hi, John Doe</p>
10
+ <p>
11
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
12
+ </p>
13
+ <div class='footer'>
14
+ To unsubscribe, <a href='http://www.google.com/'>click here</a>.
15
+ </div>
16
+ </div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path("../config/application", __dir__)
3
+ require_relative "../config/boot"
4
+ require "rails/commands"
@@ -0,0 +1,14 @@
1
+ require_relative 'boot'
2
+
3
+ require 'action_controller/railtie'
4
+ require 'action_mailer/railtie'
5
+
6
+ # Require the gems listed in Gemfile, including any gems
7
+ # you've limited to :test, :development, or :production.
8
+ Bundler.require(*Rails.groups)
9
+
10
+ module Example
11
+ class Application < Rails::Application
12
+ config.load_defaults 7.0
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,9 @@
1
+ Rails.application.configure do
2
+ config.cache_classes = false
3
+ config.eager_load = false
4
+ config.consider_all_requests_local = true
5
+ config.action_controller.perform_caching = false
6
+ config.assets.debug = true
7
+ config.assets.digest = true
8
+ config.assets.raise_runtime_errors = true
9
+ end
@@ -0,0 +1,9 @@
1
+ Rails.application.configure do
2
+ config.cache_classes = true
3
+ config.eager_load = true
4
+ config.consider_all_requests_local = false
5
+ config.action_controller.perform_caching = true
6
+ config.assets.compile = false
7
+ config.assets.digest = true
8
+ config.log_level = :info
9
+ end
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ root to: redirect('rails/mailers/example_mailer/test_message')
3
+ end
@@ -0,0 +1,6 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
6
+ Rails.application.load_server
@@ -0,0 +1,5 @@
1
+ class ExampleMailerPreview < ActionMailer::Preview
2
+ def test_message
3
+ ExampleMailer.test_message
4
+ end
5
+ end
@@ -5,12 +5,8 @@ class Premailer
5
5
 
6
6
  FileNotFound = Class.new(StandardError)
7
7
 
8
- STRATEGIES = [
9
- CSSLoaders::CacheLoader,
10
- CSSLoaders::FileSystemLoader,
11
- CSSLoaders::AssetPipelineLoader,
12
- CSSLoaders::NetworkLoader
13
- ]
8
+ attr_accessor :cache
9
+ self.cache = {}
14
10
 
15
11
  # Returns all linked CSS files concatenated as string.
16
12
  def css_for_doc(doc)
@@ -18,8 +14,10 @@ class Premailer
18
14
  end
19
15
 
20
16
  def css_for_url(url)
21
- load_css(url).tap do |content|
22
- CSSLoaders::CacheLoader.store(url, content)
17
+ if cache_enabled?
18
+ load_css_with_cache(url)
19
+ else
20
+ load_css(url)
23
21
  end
24
22
  end
25
23
 
@@ -36,14 +34,37 @@ class Premailer
36
34
  end
37
35
  end
38
36
 
37
+ def load_css_with_cache(url)
38
+ self.cache[url] ||= load_css(url)
39
+ end
40
+
41
+ def cache_enabled?
42
+ defined?(::Rails.env) && ::Rails.env.production?
43
+ end
44
+
39
45
  def load_css(url)
40
- STRATEGIES.each do |strategy|
41
- css = strategy.load(url)
42
- return css.force_encoding('UTF-8') if css
46
+ Premailer::Rails.config.fetch(:strategies).each do |strategy|
47
+ css = find_strategy(strategy).load(url)
48
+ return css if css
43
49
  end
44
50
 
45
51
  raise FileNotFound, %{File with URL "#{url}" could not be loaded by any strategy.}
46
52
  end
53
+
54
+ def find_strategy(key)
55
+ case key
56
+ when :filesystem
57
+ CSSLoaders::FileSystemLoader
58
+ when :asset_pipeline
59
+ CSSLoaders::AssetPipelineLoader
60
+ when :propshaft
61
+ CSSLoaders::PropshaftLoader
62
+ when :network
63
+ CSSLoaders::NetworkLoader
64
+ else
65
+ key
66
+ end
67
+ end
47
68
  end
48
69
  end
49
70
  end
@@ -5,30 +5,31 @@ class Premailer
5
5
  extend self
6
6
 
7
7
  def load(url)
8
- if asset_pipeline_present?
9
- file = file_name(url)
10
- asset = ::Rails.application.assets.find_asset(file)
11
- asset.to_s if asset
12
- end
13
- end
8
+ return unless asset_pipeline_present?
14
9
 
15
- def asset_pipeline_present?
16
- defined?(::Rails) &&
17
- ::Rails.respond_to?(:application) &&
18
- ::Rails.application.respond_to?(:assets) &&
19
- ::Rails.application.assets
10
+ file = file_name(url)
11
+ ::Rails.application.assets_manifest.find_sources(file).first
12
+ rescue Errno::ENOENT, TypeError => _error
20
13
  end
21
14
 
22
15
  def file_name(url)
23
- prefix = [
24
- ::Rails.configuration.relative_url_root,
25
- ::Rails.configuration.assets.prefix,
16
+ prefix = File.join(
17
+ ::Rails.configuration.relative_url_root.to_s,
18
+ ::Rails.configuration.assets.prefix.to_s,
26
19
  '/'
27
- ].join
20
+ )
28
21
  URI(url).path
29
22
  .sub(/\A#{prefix}/, '')
30
23
  .sub(/-(\h{32}|\h{64})\.css\z/, '.css')
31
24
  end
25
+
26
+ def asset_pipeline_present?
27
+ defined?(::Rails) &&
28
+ ::Rails.respond_to?(:application) &&
29
+ ::Rails.application &&
30
+ ::Rails.application.respond_to?(:assets_manifest) &&
31
+ ::Rails.application.assets_manifest
32
+ end
32
33
  end
33
34
  end
34
35
  end
@@ -5,9 +5,31 @@ class Premailer
5
5
  extend self
6
6
 
7
7
  def load(url)
8
+ file = file_name(url)
9
+ File.read(file) if File.file?(file)
10
+ end
11
+
12
+ def file_name(url)
8
13
  path = URI(url).path
9
- file_path = "public#{path}"
10
- File.read(file_path) if File.file?(file_path)
14
+ if relative_url_root
15
+ path = path.sub(/\A#{relative_url_root.chomp('/')}/, '')
16
+ end
17
+ asset_filename(path)
18
+ end
19
+
20
+ def asset_filename(filename)
21
+ if defined?(::Rails) && ::Rails.respond_to?(:root)
22
+ File.join(::Rails.root, 'public', filename)
23
+ else
24
+ File.join('public', filename)
25
+ end
26
+ end
27
+
28
+ def relative_url_root
29
+ defined?(::Rails) &&
30
+ ::Rails.respond_to?(:configuration) &&
31
+ ::Rails.configuration.respond_to?(:relative_url_root) &&
32
+ ::Rails.configuration.relative_url_root
11
33
  end
12
34
  end
13
35
  end
@@ -6,7 +6,7 @@ class Premailer
6
6
 
7
7
  def load(url)
8
8
  uri = uri_for_url(url)
9
- Net::HTTP.get(uri) if uri
9
+ Net::HTTP.get(uri, { 'Accept' => 'text/css' }) if uri
10
10
  end
11
11
 
12
12
  def uri_for_url(url)
@@ -14,7 +14,7 @@ class Premailer
14
14
 
15
15
  if uri.host.present?
16
16
  return uri if uri.scheme.present?
17
- URI("http://#{uri.to_s}")
17
+ URI("http:#{uri}")
18
18
  elsif asset_host_present?
19
19
  scheme, host = asset_host(url).split(%r{:?//})
20
20
  scheme, host = host, scheme if host.nil?
@@ -0,0 +1,38 @@
1
+ class Premailer
2
+ module Rails
3
+ module CSSLoaders
4
+ module PropshaftLoader
5
+ extend self
6
+
7
+ def load(url)
8
+ return unless propshaft_present?
9
+
10
+ file = file_name(url)
11
+ asset = ::Rails.application.assets.load_path.find(file)
12
+
13
+ ::Rails.application.assets.compilers.compile(asset) if asset
14
+ end
15
+
16
+ def file_name(url)
17
+ prefix = File.join(
18
+ ::Rails.configuration.relative_url_root.to_s,
19
+ ::Rails.configuration.assets.prefix.to_s,
20
+ '/'
21
+ )
22
+
23
+ # Path extraction logic from Propshaft.
24
+ # See https://github.com/rails/propshaft/blob/390381548b125e8721c8aef1b9d894b7cc8bd868/lib/propshaft/server.rb#L35-L41
25
+ full_path = URI(url).path.sub(/\A#{prefix}/, '')
26
+ digest = full_path[/-([0-9a-zA-Z]{7,128}(?:\.digested)?)\.[^.]+\z/, 1]
27
+ path = digest ? full_path.sub("-#{digest}", "") : full_path
28
+
29
+ path
30
+ end
31
+
32
+ def propshaft_present?
33
+ defined?(::Propshaft) && defined?(::Rails)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,6 +1,6 @@
1
1
  require 'uri'
2
2
 
3
- require 'premailer/rails/css_loaders/cache_loader'
4
3
  require 'premailer/rails/css_loaders/file_system_loader'
5
4
  require 'premailer/rails/css_loaders/asset_pipeline_loader'
5
+ require 'premailer/rails/css_loaders/propshaft_loader'
6
6
  require 'premailer/rails/css_loaders/network_loader'
@@ -4,10 +4,10 @@ class Premailer
4
4
  def initialize(html)
5
5
  # In order to pass the CSS as string to super it is necessary to access
6
6
  # the parsed HTML beforehand. To do so, the adapter needs to be
7
- # initialized. The ::Premailer::Adaptor handles the discovery of a
8
- # suitable adaptor (Nokogiri or Hpricot). To make load_html work, an
9
- # adaptor needs to be included and @options[:with_html_string] needs to
10
- # be set. For further information, refer to ::Premailer#initialize.
7
+ # initialized. The ::Premailer::Adapter handles the discovery of
8
+ # a suitable adapter. To make load_html work, an adapter needs to be
9
+ # included and @options[:with_html_string] needs to be set. For further
10
+ # information, refer to ::Premailer#initialize.
11
11
  @options = Rails.config.merge(with_html_string: true)
12
12
  Premailer.send(:include, Adapter.find(Adapter.use))
13
13
  doc = load_html(html)
@@ -73,10 +73,8 @@ class Premailer
73
73
  part = html_part
74
74
  html = premailer.to_inline_css
75
75
  Mail::Part.new do
76
- content_transfer_encoding part.content_transfer_encoding
77
- content_type "text/html; charset=#{part.charset}"
76
+ content_type "text/html; charset=#{html.encoding}"
78
77
  body html
79
- body_encoding part.body.encoding
80
78
  end
81
79
  end
82
80
 
@@ -85,10 +83,8 @@ class Premailer
85
83
  part = html_part
86
84
  text = premailer.to_plain_text
87
85
  Mail::Part.new do
88
- content_transfer_encoding part.content_transfer_encoding
89
- content_type "text/plain; charset=#{part.charset}"
86
+ content_type "text/plain; charset=#{text.encoding}"
90
87
  body text
91
- body_encoding part.body.encoding
92
88
  end
93
89
  end
94
90
  end
@@ -1,7 +1,7 @@
1
1
  class Premailer
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
- config.after_initialize do
4
+ ActiveSupport.on_load(:action_mailer) do
5
5
  ::Premailer::Rails.register_interceptors
6
6
  end
7
7
  end
@@ -11,7 +11,8 @@ class Premailer
11
11
  module Rails
12
12
  @config = {
13
13
  input_encoding: 'UTF-8',
14
- generate_text_part: true
14
+ generate_text_part: true,
15
+ strategies: [:filesystem, :asset_pipeline, :propshaft, :network]
15
16
  }
16
17
  class << self
17
18
  attr_accessor :config
@@ -16,16 +16,17 @@ Gem::Specification.new do |s|
16
16
  include a CSS file as you do in a normal HTML document and
17
17
  premailer will inline the included CSS.}
18
18
 
19
+ s.metadata["changelog_uri"] = "https://github.com/fphilipe/premailer-rails/blob/v#{Premailer::Rails::VERSION}/CHANGELOG.md"
20
+
19
21
  s.files = `git ls-files`.split("\n")
20
22
  s.test_files = `git ls-files -- {example,spec}/*`.split("\n")
21
23
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
24
  s.require_paths = ["lib"]
23
25
 
24
26
  s.add_dependency 'premailer', '~> 1.7', '>= 1.7.9'
25
- s.add_dependency 'actionmailer', '>= 3', '< 6'
27
+ s.add_dependency 'actionmailer', '>= 3'
28
+ s.add_dependency 'net-smtp' if RUBY_VERSION >= '3'
26
29
 
27
30
  s.add_development_dependency 'rspec', '~> 3.3'
28
31
  s.add_development_dependency 'nokogiri'
29
- s.add_development_dependency 'hpricot' unless RUBY_PLATFORM == 'java'
30
- s.add_development_dependency 'coveralls' if RUBY_ENGINE == 'ruby'
31
32
  end