Extend cache busting to allow for path manipulation
This commit is contained in:
parent
9b5d5b72a1
commit
21928907e4
@ -71,8 +71,10 @@ module Compass
|
||||
end
|
||||
|
||||
# When called with a block, defines the cache buster strategy to be used.
|
||||
# The block must return nil or a string that can be appended to a url as a query parameter.
|
||||
# The returned string must not include the starting '?'.
|
||||
# If the block returns nil or a string, then it is appended to the url as a query parameter.
|
||||
# In this case, the returned string must not include the starting '?'.
|
||||
# The block may also return a full path (i.e. /images/grid-BUSTED.png) and it
|
||||
# will replace the original path and query string with the busted path returned.
|
||||
# The block will be passed the root-relative url of the asset.
|
||||
# If the block accepts two arguments, it will also be passed a File object
|
||||
# that points to the asset on disk -- which may or may not exist.
|
||||
|
@ -91,9 +91,7 @@ module Compass::SassExtensions::Functions::Urls
|
||||
if cache_buster.is_a?(Sass::Script::String)
|
||||
path += "?#{cache_buster.value}"
|
||||
else
|
||||
if buster = compute_cache_buster(path, real_path)
|
||||
path += "?#{buster}"
|
||||
end
|
||||
path = cache_busted_path(path, real_path)
|
||||
end
|
||||
end
|
||||
|
||||
@ -137,6 +135,17 @@ module Compass::SassExtensions::Functions::Urls
|
||||
end
|
||||
end
|
||||
|
||||
def cache_busted_path(path, real_path)
|
||||
cache_buster = compute_cache_buster(path, real_path)
|
||||
if cache_buster.nil?
|
||||
path
|
||||
elsif cache_buster =~ %r{/}
|
||||
cache_buster
|
||||
else
|
||||
"%s?%s" % [path, cache_buster]
|
||||
end
|
||||
end
|
||||
|
||||
def compute_cache_buster(path, real_path)
|
||||
if Compass.configuration.asset_cache_buster
|
||||
args = [path]
|
||||
|
@ -71,6 +71,17 @@ class CompassTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_busted_image_urls
|
||||
within_project('busted_image_urls') do |proj|
|
||||
each_css_file(proj.css_path) do |css_file|
|
||||
assert_no_errors css_file, 'busted_image_urls'
|
||||
end
|
||||
each_sass_file do |sass_file|
|
||||
assert_renders_correctly sass_file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_image_urls
|
||||
within_project('image_urls') do |proj|
|
||||
each_css_file(proj.css_path) do |css_file|
|
||||
|
20
test/fixtures/stylesheets/busted_image_urls/config.rb
vendored
Normal file
20
test/fixtures/stylesheets/busted_image_urls/config.rb
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
# Require any additional compass plugins here.
|
||||
project_type = :stand_alone
|
||||
css_dir = "tmp"
|
||||
sass_dir = "sass"
|
||||
images_dir = "images"
|
||||
output_style = :compact
|
||||
# To enable relative image paths using the images_url() function:
|
||||
# http_images_path = :relative
|
||||
http_images_path = "/images"
|
||||
line_comments = false
|
||||
|
||||
asset_cache_buster do |path, file|
|
||||
pathname = Pathname.new(path)
|
||||
"%s/%s-BUSTED%s" % [pathname.dirname, pathname.basename(pathname.extname), pathname.extname]
|
||||
end
|
||||
|
||||
|
||||
asset_host do |path|
|
||||
"http://assets%d.example.com" % (path.size % 4)
|
||||
end
|
5
test/fixtures/stylesheets/busted_image_urls/css/screen.css
vendored
Normal file
5
test/fixtures/stylesheets/busted_image_urls/css/screen.css
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.showgrid { background-image: url('http://assets0.example.com/images/grid-BUSTED.png'); }
|
||||
|
||||
.inlinegrid { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAUEAYAAACv1qP4AAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAZ0lEQVRYw+3QwQ2AIBAFUTEUwI3+uzN7gDscsIgxEuO8An52J11X73OudfxMraXkzHfO3Y98nQEhA0IGhAwIGRAyIGRAyICQASEDQgaEDAgZEDIgZEDIgJABoZzSGK3tPuN9ERFP7Nw4fg+c5g8V1wAAAABJRU5ErkJggg=='); }
|
||||
|
||||
.no-buster { background-image: url('http://assets0.example.com/images/grid.png'); }
|
BIN
test/fixtures/stylesheets/busted_image_urls/images/grid.png
vendored
Normal file
BIN
test/fixtures/stylesheets/busted_image_urls/images/grid.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 199 B |
8
test/fixtures/stylesheets/busted_image_urls/sass/screen.sass
vendored
Normal file
8
test/fixtures/stylesheets/busted_image_urls/sass/screen.sass
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
.showgrid
|
||||
background-image: image-url(unquote("grid.png"))
|
||||
|
||||
.inlinegrid
|
||||
background-image: inline-image(unquote("grid.png"))
|
||||
|
||||
.no-buster
|
||||
background-image: image-url("grid.png", $only-path: false, $cache-buster: false)
|
Loading…
Reference in New Issue
Block a user