Sha256: d8b892afd11e6c84c23bb22a537a41e2a4f9925f833098c64bb265058110d4d0

Contents?: true

Size: 712 Bytes

Versions: 4

Compression:

Stored size: 712 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 =
              ::Rails.configuration.action_controller.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
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
premailer-rails-1.8.0 lib/premailer/rails/css_loaders/network_loader.rb
premailer-rails-1.7.0 lib/premailer/rails/css_loaders/network_loader.rb
premailer-rails-1.6.1 lib/premailer/rails/css_loaders/network_loader.rb
premailer-rails-1.6.0 lib/premailer/rails/css_loaders/network_loader.rb