Sha256: da7cd4ceccfdc0400c4126ff57d14b94c391088cededca055357d9af0ff841ab

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

class Premailer
  module Rails
    module CSSLoaders
      module NetworkLoader
        extend self

        def load(url)
          uri = uri_for_url(url)
          Net::HTTP.get(uri) if uri
        end

        def uri_for_url(url)
          uri = URI(url)

          if not valid_uri?(uri) and defined?(::Rails)
            scheme, host =
              asset_host.split(%r{:?//})
            scheme = 'http' if scheme.blank?
            uri.scheme ||= scheme
            uri.host ||= host
          end

          uri if valid_uri?(uri)
        end

        def valid_uri?(uri)
          uri.host.present? && uri.scheme.present?
        end

        def asset_host
          host = ::Rails.configuration.action_controller.asset_host

          if host.respond_to?(:call)
            host.call
          else
            host
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
premailer-rails-1.8.1 lib/premailer/rails/css_loaders/network_loader.rb