This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2018-01-15 18:29:11 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module PremailerWebpackStrategy
|
|
|
|
def load(url)
|
2018-01-28 16:06:39 -08:00
|
|
|
asset_host = ENV['CDN_HOST'] || ENV['WEB_DOMAIN'] || ENV['LOCAL_DOMAIN']
|
2018-01-19 16:32:21 -08:00
|
|
|
|
2018-01-15 18:29:11 -08:00
|
|
|
if Webpacker.dev_server.running?
|
2018-01-23 17:57:14 -08:00
|
|
|
asset_host = "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}"
|
|
|
|
url = File.join(asset_host, url)
|
2018-01-15 18:29:11 -08:00
|
|
|
end
|
2018-01-23 17:57:14 -08:00
|
|
|
|
|
|
|
css = if url.start_with?('http')
|
|
|
|
HTTP.get(url).to_s
|
|
|
|
else
|
|
|
|
url = url[1..-1] if url.start_with?('/')
|
|
|
|
File.read(Rails.root.join('public', url))
|
|
|
|
end
|
|
|
|
|
|
|
|
css.gsub(/url\(\//, "url(#{asset_host}/")
|
2018-01-15 18:29:11 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
module_function :load
|
|
|
|
end
|