You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
620 B
24 lines
620 B
7 years ago
|
# frozen_string_literal: true
|
||
|
|
||
|
module PremailerWebpackStrategy
|
||
|
def load(url)
|
||
7 years ago
|
asset_host = ENV['CDN_HOST'] || ENV['WEB_DOMAIN'] || ENV['LOCAL_DOMAIN']
|
||
7 years ago
|
|
||
7 years ago
|
if Webpacker.dev_server.running?
|
||
7 years ago
|
asset_host = "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}"
|
||
|
url = File.join(asset_host, url)
|
||
7 years ago
|
end
|
||
7 years ago
|
|
||
|
css = if url.start_with?('http')
|
||
|
HTTP.get(url).to_s
|
||
|
else
|
||
1 year ago
|
url = url[1..] if url.start_with?('/')
|
||
2 years ago
|
Rails.public_path.join(url).read
|
||
7 years ago
|
end
|
||
|
|
||
1 year ago
|
css.gsub(%r{url\(/}, "url(#{asset_host}/")
|
||
7 years ago
|
end
|
||
|
|
||
|
module_function :load
|
||
|
end
|