2018-01-16 04:29:11 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module PremailerWebpackStrategy
|
|
|
|
def load(url)
|
2018-01-29 02:06:39 +02:00
|
|
|
asset_host = ENV['CDN_HOST'] || ENV['WEB_DOMAIN'] || ENV['LOCAL_DOMAIN']
|
2018-01-20 02:32:21 +02:00
|
|
|
|
2018-01-16 04:29:11 +02:00
|
|
|
if Webpacker.dev_server.running?
|
2018-01-24 03:57:14 +02:00
|
|
|
asset_host = "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}"
|
|
|
|
url = File.join(asset_host, url)
|
2018-01-16 04:29:11 +02:00
|
|
|
end
|
2018-01-24 03:57:14 +02:00
|
|
|
|
|
|
|
css = if url.start_with?('http')
|
|
|
|
HTTP.get(url).to_s
|
|
|
|
else
|
|
|
|
url = url[1..-1] if url.start_with?('/')
|
2023-02-08 11:38:07 +02:00
|
|
|
File.read(Rails.public_path.join(url))
|
2018-01-24 03:57:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
css.gsub(/url\(\//, "url(#{asset_host}/")
|
2018-01-16 04:29:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
module_function :load
|
|
|
|
end
|