diff --git a/doc-src/content/CHANGELOG.markdown b/doc-src/content/CHANGELOG.markdown index 0fc5e21d..2bc0bf5c 100644 --- a/doc-src/content/CHANGELOG.markdown +++ b/doc-src/content/CHANGELOG.markdown @@ -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: `gem install sass --pre`. Note: you must also upgrade your haml gem if you 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) ------------------------- diff --git a/doc-src/content/reference/compass/helpers/urls.haml b/doc-src/content/reference/compass/helpers/urls.haml index d0ffed70..038efe66 100644 --- a/doc-src/content/reference/compass/helpers/urls.haml +++ b/doc-src/content/reference/compass/helpers/urls.haml @@ -43,11 +43,15 @@ classnames: #image-url.helper %h3 %a(href="#image-url") - image-url($path, $only-path: false) + image-url($path, $only-path: false, $cache-buster: true) .details %p 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 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. diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index adc18765..127adc57 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -288,7 +288,9 @@ module Compass::SassExtensions::Functions::Sprites missing_sprite!("sprite-url") end 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 Sass::Script::Functions.declare :sprite_url, [:map] diff --git a/lib/compass/sass_extensions/functions/urls.rb b/lib/compass/sass_extensions/functions/urls.rb index 1ced4340..d140c8a5 100644 --- a/lib/compass/sass_extensions/functions/urls.rb +++ b/lib/compass/sass_extensions/functions/urls.rb @@ -18,6 +18,8 @@ module Compass::SassExtensions::Functions::Urls clean_url(path) 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)) path = path.value # get to the string value of the literal. @@ -43,8 +45,10 @@ module Compass::SassExtensions::Functions::Urls clean_url(path) 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. if path =~ %r{^#{Regexp.escape(Compass.configuration.http_images_path)}/(.*)} @@ -83,8 +87,14 @@ module Compass::SassExtensions::Functions::Urls end # Compute and append the cache buster if there is one. - if buster = compute_cache_buster(path, real_path) - path += "?#{buster}" + if cache_buster.to_bool + 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 # prepend the asset host if there is one. @@ -96,6 +106,9 @@ module Compass::SassExtensions::Functions::Urls clean_url(path) 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 diff --git a/test/fixtures/stylesheets/image_urls/css/screen.css b/test/fixtures/stylesheets/image_urls/css/screen.css index 9609ab2c..0c01a391 100644 --- a/test/fixtures/stylesheets/image_urls/css/screen.css +++ b/test/fixtures/stylesheets/image_urls/css/screen.css @@ -1,3 +1,5 @@ .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=='); } + +.no-buster { background-image: url('http://assets0.example.com/images/grid.png'); } diff --git a/test/fixtures/stylesheets/image_urls/sass/screen.sass b/test/fixtures/stylesheets/image_urls/sass/screen.sass index 68a27f74..e16697bc 100644 --- a/test/fixtures/stylesheets/image_urls/sass/screen.sass +++ b/test/fixtures/stylesheets/image_urls/sass/screen.sass @@ -3,3 +3,6 @@ .inlinegrid background-image: inline-image(unquote("grid.png")) + +.no-buster + background-image: image-url("grid.png", $only-path: false, $cache-buster: false)