[Compass Core] The image_url() sass function now adds timestamp invalidation to images to prevent them from being cached after changing.
This commit is contained in:
parent
9f46524bde
commit
f1832d07ab
@ -18,30 +18,46 @@ module Sass::Script::Functions
|
|||||||
end
|
end
|
||||||
|
|
||||||
def image_url(path)
|
def image_url(path)
|
||||||
if absolute_path?(path.value)
|
path = path.value # get to the string value of the literal.
|
||||||
|
if absolute_path?(path)
|
||||||
return Sass::Script::String.new("url(#{path})")
|
return Sass::Script::String.new("url(#{path})")
|
||||||
end
|
end
|
||||||
http_images_path = if Compass.configuration.http_images_path == :relative
|
http_images_path = if Compass.configuration.http_images_path == :relative
|
||||||
if (target_css_file = options[:css_filename])
|
compute_relative_path
|
||||||
images_path = File.join(Compass.configuration.project_path, Compass.configuration.images_dir)
|
|
||||||
Pathname.new(images_path).relative_path_from(Pathname.new(File.dirname(target_css_file))).to_s
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
Compass.configuration.http_images_path
|
Compass.configuration.http_images_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
real_path = if Compass.configuration.images_dir
|
||||||
|
File.join(Compass.configuration.project_path, Compass.configuration.images_dir, path)
|
||||||
|
end
|
||||||
|
|
||||||
if http_images_path
|
if http_images_path
|
||||||
http_images_path = "#{http_images_path}/" unless http_images_path[-1..-1] == "/"
|
http_images_path = "#{http_images_path}/" unless http_images_path[-1..-1] == "/"
|
||||||
path = "#{http_images_path}#{path}"
|
path = "#{http_images_path}#{path}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if real_path && File.exists?(real_path)
|
||||||
|
path += "?#{File.mtime(real_path).strftime("%s")}"
|
||||||
|
elsif real_path
|
||||||
|
$stderr.puts "WARNING: '#{File.basename(path)}' was not found in #{File.dirname(real_path)}"
|
||||||
|
end
|
||||||
|
|
||||||
Sass::Script::String.new("url(#{path})")
|
Sass::Script::String.new("url(#{path})")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def absolute_path?(path)
|
def absolute_path?(path)
|
||||||
path[0..0] == "/" || path[0..3] == "http"
|
path[0..0] == "/" || path[0..3] == "http"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def compute_relative_path
|
||||||
|
if (target_css_file = options[:css_filename])
|
||||||
|
images_path = File.join(Compass.configuration.project_path, Compass.configuration.images_dir)
|
||||||
|
Pathname.new(images_path).relative_path_from(Pathname.new(File.dirname(target_css_file))).to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# XXX: We can remove this check and monkeypatch once Sass 2.2 is released.
|
# XXX: We can remove this check and monkeypatch once Sass 2.2 is released.
|
||||||
|
Loading…
Reference in New Issue
Block a user