module Premailer::Rails::CSSLoaders::NetworkLoader

Public Instance Methods

asset_host() click to toggle source
# File lib/premailer/rails/css_loaders/network_loader.rb, line 31
def asset_host
  config = ::Rails.configuration.action_controller.asset_host
  config.respond_to?(:call) ? config.call : config
end
asset_host_present?() click to toggle source
# File lib/premailer/rails/css_loaders/network_loader.rb, line 27
def asset_host_present?
  ::Rails.configuration.action_controller.asset_host.present?
end
load(url) click to toggle source
# File lib/premailer/rails/css_loaders/network_loader.rb, line 7
def load(url)
  uri = uri_for_url(url)
  Net::HTTP.get(uri) if uri
end
uri_for_url(url) click to toggle source
# File lib/premailer/rails/css_loaders/network_loader.rb, line 12
def uri_for_url(url)
  uri = URI(url)

  if uri.host.present?
    return uri if uri.scheme.present?
    URI("http://#{uri.to_s}")
  elsif asset_host_present?
    scheme, host = asset_host.split(%r{:?//})
    scheme, host = host, scheme if host.nil?
    scheme = 'http' if scheme.blank?
    path = url
    URI(File.join("#{scheme}://#{host}", path))
  end
end