class Sass::Importers::HTTP
Public Class Methods
new(root)
click to toggle source
# File lib/sassmagic/remote.rb, line 19 def initialize root @root = URI.parse root unless scheme_allowed? @root raise ArgumentError, "Absolute HTTP URIs only" end end
Public Instance Methods
find(uri, options)
click to toggle source
# File lib/sassmagic/remote.rb, line 30 def find uri, options _find @root + uri, options end
find_relative(uri, base, options)
click to toggle source
# File lib/sassmagic/remote.rb, line 27 def find_relative uri, base, options _find @root + base + uri, options end
key(uri, options)
click to toggle source
# File lib/sassmagic/remote.rb, line 51 def key(uri, options) [self.class.name, uri] end
mtime(uri, options)
click to toggle source
# File lib/sassmagic/remote.rb, line 34 def mtime uri, options uri = URI.parse uri return unless scheme_allowed? uri Net::HTTP.start(uri.host, uri.port) do |http| response = http.head uri.request_uri if response.is_a?(Net::HTTPOK) && response['Last-Modified'] Time.parse response['Last-Modified'] elsif response.is_a? Net::HTTPOK # we must assume that it just changed Time.now else nil end end end
to_s()
click to toggle source
# File lib/sassmagic/remote.rb, line 55 def to_s @root.to_s end
Protected Instance Methods
extensions()
click to toggle source
# File lib/sassmagic/remote.rb, line 61 def extensions {'.sass' => :sass, '.scss' => :scss} end
Private Instance Methods
_find(uri, options)
click to toggle source
# File lib/sassmagic/remote.rb, line 95 def _find uri, options raise ArgumentError, "Absolute HTTP URIs only" unless scheme_allowed? uri syntax = get_syntax uri # fetch the content Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| # debugger response = http.get uri.request_uri response.value options[:importer] = self options[:filename] = uri.to_s options[:syntax] = syntax Sass::Engine.new response.body, options end # rescue # nil end
exists?(uri)
click to toggle source
# File lib/sassmagic/remote.rb, line 71 def exists? uri Net::HTTP.start(uri.host, uri.port) do |http| http.head(uri.request_uri).is_a? Net::HTTPOK end end
get_syntax(uri)
click to toggle source
# File lib/sassmagic/remote.rb, line 77 def get_syntax uri # determine the syntax being used ext = File.extname uri.path syntax = extensions[ext] # this must not be the full path: try another if syntax.nil? ext, syntax = extensions.find do |possible_ext, possible_syntax| new_uri = uri.dup new_uri.path += possible_ext exists? new_uri end return if syntax.nil? uri.path += ext end syntax end
scheme_allowed?(uri)
click to toggle source
# File lib/sassmagic/remote.rb, line 67 def scheme_allowed? uri uri.absolute? && (uri.scheme == 'http' || uri.scheme == 'https') end