Allow the cache buster in image-url() to be disabled on a per-call basis.

This commit is contained in:
Chris Eppstein 2010-12-05 20:16:40 -08:00
parent a89d61ce21
commit 93040322b3
6 changed files with 33 additions and 6 deletions

View File

@ -22,6 +22,9 @@ The Documentation for the [latest preview release](http://beta.compass-style.org
* Compass now depends on Sass 3.1. You can install the preview release: * Compass now depends on Sass 3.1. You can install the preview release:
`gem install sass --pre`. Note: you must also upgrade your haml gem if you `gem install sass --pre`. Note: you must also upgrade your haml gem if you
use both in the same application. use both in the same application.
* A third argument is now available on the `image-url()` helper. When `true` or
`false`, it will enable/disable the cache buster for a single image url. Or when
a string, it will be the cache buster used.
0.11.alpha.1 (11/22/2010) 0.11.alpha.1 (11/22/2010)
------------------------- -------------------------

View File

@ -43,11 +43,15 @@ classnames:
#image-url.helper #image-url.helper
%h3 %h3
%a(href="#image-url") %a(href="#image-url")
image-url($path, $only-path: false) image-url($path, $only-path: false, $cache-buster: true)
.details .details
%p %p
Generates a path to an asset found relative to the project's images directory. Generates a path to an asset found relative to the project's images directory.
%br %p
Passing a true value as the second argument will cause the only the path to be returned Passing a true value as the second argument will cause the only the path to be returned
instead of a `url()` function instead of a `url()` function
%p
The third argument is used to control the cache buster on a per-use basis.
When set to `false` no cache buster will be used. When a string, that
value will be used as the cache buster.

View File

@ -288,7 +288,9 @@ module Compass::SassExtensions::Functions::Sprites
missing_sprite!("sprite-url") missing_sprite!("sprite-url")
end end
map.generate map.generate
image_url(Sass::Script::String.new("#{map.path}-#{map.uniqueness_hash}.png")) image_url(Sass::Script::String.new("#{map.path}-#{map.uniqueness_hash}.png"),
Sass::Script::Bool.new(false),
Sass::Script::Bool.new(false))
end end
Sass::Script::Functions.declare :sprite_url, [:map] Sass::Script::Functions.declare :sprite_url, [:map]

View File

@ -18,6 +18,8 @@ module Compass::SassExtensions::Functions::Urls
clean_url(path) clean_url(path)
end end
end end
Sass::Script::Functions.declare :stylesheet_url, [:path]
Sass::Script::Functions.declare :stylesheet_url, [:path, :only_path]
def font_url(path, only_path = Sass::Script::Bool.new(false)) def font_url(path, only_path = Sass::Script::Bool.new(false))
path = path.value # get to the string value of the literal. path = path.value # get to the string value of the literal.
@ -43,8 +45,10 @@ module Compass::SassExtensions::Functions::Urls
clean_url(path) clean_url(path)
end end
end end
Sass::Script::Functions.declare :font_url, [:path]
Sass::Script::Functions.declare :font_url, [:path, :only_path]
def image_url(path, only_path = Sass::Script::Bool.new(false)) def image_url(path, only_path = Sass::Script::Bool.new(false), cache_buster = Sass::Script::Bool.new(true))
path = path.value # get to the string value of the literal. path = path.value # get to the string value of the literal.
if path =~ %r{^#{Regexp.escape(Compass.configuration.http_images_path)}/(.*)} if path =~ %r{^#{Regexp.escape(Compass.configuration.http_images_path)}/(.*)}
@ -83,8 +87,14 @@ module Compass::SassExtensions::Functions::Urls
end end
# Compute and append the cache buster if there is one. # Compute and append the cache buster if there is one.
if buster = compute_cache_buster(path, real_path) if cache_buster.to_bool
path += "?#{buster}" if cache_buster.is_a?(Sass::Script::String)
path += "?#{cache_buster.value}"
else
if buster = compute_cache_buster(path, real_path)
path += "?#{buster}"
end
end
end end
# prepend the asset host if there is one. # prepend the asset host if there is one.
@ -96,6 +106,9 @@ module Compass::SassExtensions::Functions::Urls
clean_url(path) clean_url(path)
end end
end end
Sass::Script::Functions.declare :image_url, [:path]
Sass::Script::Functions.declare :image_url, [:path, :only_path]
Sass::Script::Functions.declare :image_url, [:path, :only_path, :cache_buster]
private private

View File

@ -1,3 +1,5 @@
.showgrid { background-image: url('http://assets0.example.com/images/grid.png?busted=true'); } .showgrid { background-image: url('http://assets0.example.com/images/grid.png?busted=true'); }
.inlinegrid { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAUEAYAAACv1qP4AAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAZ0lEQVRYw+3QwQ2AIBAFUTEUwI3+uzN7gDscsIgxEuO8An52J11X73OudfxMraXkzHfO3Y98nQEhA0IGhAwIGRAyIGRAyICQASEDQgaEDAgZEDIgZEDIgJABoZzSGK3tPuN9ERFP7Nw4fg+c5g8V1wAAAABJRU5ErkJggg=='); } .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'); }

View File

@ -3,3 +3,6 @@
.inlinegrid .inlinegrid
background-image: inline-image(unquote("grid.png")) background-image: inline-image(unquote("grid.png"))
.no-buster
background-image: image-url("grid.png", $only-path: false, $cache-buster: false)