2018-01-16 02:29:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-04-15 10:16:59 +01:00
|
|
|
module PremailerBundledAssetStrategy
|
2018-01-16 02:29:11 +00:00
|
|
|
def load(url)
|
2024-04-15 10:16:59 +01:00
|
|
|
asset_host = ENV['CDN_HOST'] || ENV['WEB_DOMAIN'] || ENV.fetch('LOCAL_DOMAIN', nil)
|
2018-01-20 00:32:21 +00:00
|
|
|
|
2018-01-16 02:29:11 +00:00
|
|
|
if Webpacker.dev_server.running?
|
2018-01-24 01:57:14 +00:00
|
|
|
asset_host = "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}"
|
|
|
|
url = File.join(asset_host, url)
|
2018-01-16 02:29:11 +00:00
|
|
|
end
|
2018-01-24 01:57:14 +00:00
|
|
|
|
|
|
|
css = if url.start_with?('http')
|
|
|
|
HTTP.get(url).to_s
|
|
|
|
else
|
2023-07-12 09:03:06 +01:00
|
|
|
url = url[1..] if url.start_with?('/')
|
2023-02-22 00:57:15 +00:00
|
|
|
Rails.public_path.join(url).read
|
2018-01-24 01:57:14 +00:00
|
|
|
end
|
|
|
|
|
2023-06-06 13:50:51 +01:00
|
|
|
css.gsub(%r{url\(/}, "url(#{asset_host}/")
|
2018-01-16 02:29:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module_function :load
|
|
|
|
end
|