module Compass::Core::SassExtensions::Functions::Urls

Public Class Methods

has?(base, instance_method) click to toggle source
# File lib/compass/core/sass_extensions/functions/urls.rb, line 4
def self.has?(base, instance_method)
  Sass::Util.has?(:instance_method, base, instance_method)
end
included(base) click to toggle source
# File lib/compass/core/sass_extensions/functions/urls.rb, line 8
def self.included(base)
  base.send(:include, StylesheetUrl) unless has?(base, :stylesheet_url)
  base.send(:include, FontUrl) unless has?(base, :font_url)
  base.send(:include, ImageUrl) unless has?(base, :image_url)
  base.send(:include, GeneratedImageUrl) unless has?(base, :generated_image_url)
end

Private Instance Methods

absolute_path?(path) click to toggle source
# File lib/compass/core/sass_extensions/functions/urls.rb, line 256
def absolute_path?(path)
  path[0..0] == "/" || path[0..3] == "http"
end
cache_busted_path(path, real_path) click to toggle source
# File lib/compass/core/sass_extensions/functions/urls.rb, line 268
def cache_busted_path(path, real_path)
  cache_buster = compute_cache_buster(path, real_path)
  if cache_buster.nil?
    return path
  elsif cache_buster.is_a?(String)
    cache_buster = {:query => cache_buster}
  else
    path = cache_buster[:path] if cache_buster[:path]
  end
  
  if cache_buster[:query]
    "#{path}#{path["?"] ? "&" : "?"}#{cache_buster[:query]}"
  else
    path
  end
end
clean_path(url) click to toggle source

Emits a path, taking off any leading “./”

# File lib/compass/core/sass_extensions/functions/urls.rb, line 242
def clean_path(url)
  url = url.to_s
  url = url[0..1] == "./" ? url[2..-1] : url
end
clean_url(url) click to toggle source

Emits a url, taking off any leading “./”

# File lib/compass/core/sass_extensions/functions/urls.rb, line 248
def clean_url(url)
  unquoted_string("url('#{clean_path(url)}')")
end
compute_cache_buster(path, real_path) click to toggle source
# File lib/compass/core/sass_extensions/functions/urls.rb, line 285
def compute_cache_buster(path, real_path)
  file = nil
  if Compass.configuration.asset_cache_buster
    args = [path]
    if Compass.configuration.asset_cache_buster.arity > 1
      begin
        file = File.new(real_path) if real_path
      rescue Errno::ENOENT
        # pass
      end
      args << file
    end
    Compass.configuration.asset_cache_buster.call(*args)
  elsif real_path
    default_cache_buster(path, real_path)
  end
ensure
  file.close if file
end
compute_relative_path(path) click to toggle source
# File lib/compass/core/sass_extensions/functions/urls.rb, line 260
def compute_relative_path(path)
  if (target_css_file = options[:css_filename])
    target_path = Pathname.new(File.expand_path(path))
    source_path = Pathname.new(File.dirname(File.expand_path(target_css_file)))
    target_path.relative_path_from(source_path).to_s
  end
end
default_cache_buster(path, real_path) click to toggle source
# File lib/compass/core/sass_extensions/functions/urls.rb, line 305
def default_cache_buster(path, real_path)
  if File.readable?(real_path)
    File.mtime(real_path).to_i.to_s
  else
    $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
  end
end
relative?() click to toggle source
# File lib/compass/core/sass_extensions/functions/urls.rb, line 252
def relative?
  Compass.configuration.relative_assets?
end