From 2f3b757b46c96383c2321bb8f79c9029144f7d65 Mon Sep 17 00:00:00 2001 From: Mattias Pfeiffer Date: Wed, 4 May 2011 11:37:58 +0200 Subject: [PATCH] Make asset_cache_buster return a hash with path and query, while still maintaining support for cache busting via query string if a string is returned. --- lib/compass/sass_extensions/functions/urls.rb | 14 ++++++++++---- .../stylesheets/busted_image_urls/config.rb | 11 ++++++++++- .../stylesheets/busted_image_urls/css/screen.css | 4 ++++ .../stylesheets/busted_image_urls/images/feed.png | Bin 0 -> 691 bytes .../busted_image_urls/images/flags/dk.png | Bin 0 -> 808 bytes .../busted_image_urls/sass/screen.sass | 6 ++++++ 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/stylesheets/busted_image_urls/images/feed.png create mode 100644 test/fixtures/stylesheets/busted_image_urls/images/flags/dk.png diff --git a/lib/compass/sass_extensions/functions/urls.rb b/lib/compass/sass_extensions/functions/urls.rb index 5fce4b69..50ffab52 100644 --- a/lib/compass/sass_extensions/functions/urls.rb +++ b/lib/compass/sass_extensions/functions/urls.rb @@ -138,11 +138,17 @@ module Compass::SassExtensions::Functions::Urls 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 + return path + elsif cache_buster.is_a?(String) + cache_buster = {:query => cache_buster} else - "%s?%s" % [path, cache_buster] + path = cache_buster[:path] if cache_buster[:path] + end + + if cache_buster[:query] + "%s?%s" % [path, cache_buster[:query]] + else + path end end diff --git a/test/fixtures/stylesheets/busted_image_urls/config.rb b/test/fixtures/stylesheets/busted_image_urls/config.rb index 9961c9bd..13821b8e 100644 --- a/test/fixtures/stylesheets/busted_image_urls/config.rb +++ b/test/fixtures/stylesheets/busted_image_urls/config.rb @@ -11,7 +11,16 @@ 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] + + case pathname.basename(pathname.extname).to_s + when "grid" + new_path = "%s/%s-BUSTED%s" % [pathname.dirname, pathname.basename(pathname.extname), pathname.extname] + {:path => new_path, :query => nil} + when "feed" + "query_string" + when "dk" + {:query => "query_string"} + end end diff --git a/test/fixtures/stylesheets/busted_image_urls/css/screen.css b/test/fixtures/stylesheets/busted_image_urls/css/screen.css index 9935c20f..ab36dbc7 100644 --- a/test/fixtures/stylesheets/busted_image_urls/css/screen.css +++ b/test/fixtures/stylesheets/busted_image_urls/css/screen.css @@ -3,3 +3,7 @@ .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'); } + +.feed { background-image: url('http://assets0.example.com/images/feed.png?query_string'); } + +.dk { background-image: url('http://assets0.example.com/images/flags/dk.png?query_string'); } diff --git a/test/fixtures/stylesheets/busted_image_urls/images/feed.png b/test/fixtures/stylesheets/busted_image_urls/images/feed.png new file mode 100644 index 0000000000000000000000000000000000000000..315c4f4fa62cb720326ba3f54259666ba3999e42 GIT binary patch literal 691 zcmV;k0!;mhP)bpQb1=l6TxbDZwj&S={?7%qx-u`rsG(Zp`-rh=e^=%((1yvsuf5d=&62Zj)Y zH&JviNS_F4_Hj|T(1j4$p-!}kixP9&dB4uv^MveG?dGf%sUCoc2!IFxD6wHRA2^dX zXRVk!-qSfk(jcaUKn#RP48(whfPlJUpApdrA!TQi_4D+fVoM;3I0gZ8{=Xv~Po;geVA+Em9@0Wq2 zr>OTZEGR05L=gf1T;ucCxq6Q6EgJiH@@-lVaAlQyw`jIF^c=&IVnj|95hHbE_cnt| zTzZQ?F4Ne@(bH(~&3nM%m)I@ID{@jJ2qZPjr)jhpe9hViOwH5k&|T#EmmL3(vHeUQ zq^!t^Al6JD;=mHq^Bg?J-8-zG2Od7gZbknG;K9czYjPqG*xjPo0k(c4%lPXTpw(qq z@aGMnxtFS(np+2kC} z7P02O874ZkJH$v#nCUVx$({yDN`IX@o2wyvTD#e`qN`_w5<}$3F+_ra@ocD)4hISV`@ zi-EKU7`vU!wgU;46*#5?X|QgFuOHGP85kJVJzX3_G|uM+S^F^u^33^O#?8{@(mEwc zI`4qv1BERYo`z`_cf=?%IXbcgO=DS7k;8v9dV)hwOvJzHH%3gIoSbvqpOo#MeO~y7 zG9SYWVT(u|1_j}nOQ%@Po_qKH)8otUxE_jKa%XZ)q+T^c!>5;$f?X4qblk9clBgf# zb}?mIifmhs?1Wj1JQ*fUnx;ENEqPX_&Jtfv!J_HbFD8Yo{#GsFIC-YWj7E`}4xJrA zT`Hby_ZVHBa$jR>-|pCcd3lzFPhZ-LXd3^{y?!S|{tLu5oe`}`p2UfOqkzb!EKM(_kpK6I~L`iZ{YGO&MZVHfK zFfuT()HO8JH8cw`GO{u>ure{zH88g_Fj(fW`zcHVNTn4-7f^$tfvy2igJFn)nU$%b zm7xVh1K&H2ohTY|^HVa@DsgM5-@JhpsKE&2B%jRW)V$(UhK!Pu0xNy})I7cN%|Ed8}R@D literal 0 HcmV?d00001 diff --git a/test/fixtures/stylesheets/busted_image_urls/sass/screen.sass b/test/fixtures/stylesheets/busted_image_urls/sass/screen.sass index e16697bc..8f844f2a 100644 --- a/test/fixtures/stylesheets/busted_image_urls/sass/screen.sass +++ b/test/fixtures/stylesheets/busted_image_urls/sass/screen.sass @@ -6,3 +6,9 @@ .no-buster background-image: image-url("grid.png", $only-path: false, $cache-buster: false) + +.feed + background-image: image-url(unquote("feed.png")) + +.dk + background-image: image-url(unquote("flags/dk.png")) \ No newline at end of file