From 21928907e4ae8f739cc9baf006d580ce7d2aaf07 Mon Sep 17 00:00:00 2001 From: Nathaniel Bibler Date: Sun, 27 Mar 2011 22:35:49 -0400 Subject: [PATCH 01/12] Extend cache busting to allow for path manipulation --- lib/compass/configuration/data.rb | 6 ++++-- lib/compass/sass_extensions/functions/urls.rb | 15 ++++++++++--- test/compass_test.rb | 11 ++++++++++ .../stylesheets/busted_image_urls/config.rb | 20 ++++++++++++++++++ .../busted_image_urls/css/screen.css | 5 +++++ .../busted_image_urls/images/grid.png | Bin 0 -> 199 bytes .../busted_image_urls/sass/screen.sass | 8 +++++++ 7 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/stylesheets/busted_image_urls/config.rb create mode 100644 test/fixtures/stylesheets/busted_image_urls/css/screen.css create mode 100644 test/fixtures/stylesheets/busted_image_urls/images/grid.png create mode 100644 test/fixtures/stylesheets/busted_image_urls/sass/screen.sass diff --git a/lib/compass/configuration/data.rb b/lib/compass/configuration/data.rb index 9cde724d..0173fa93 100644 --- a/lib/compass/configuration/data.rb +++ b/lib/compass/configuration/data.rb @@ -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. diff --git a/lib/compass/sass_extensions/functions/urls.rb b/lib/compass/sass_extensions/functions/urls.rb index d140c8a5..5fce4b69 100644 --- a/lib/compass/sass_extensions/functions/urls.rb +++ b/lib/compass/sass_extensions/functions/urls.rb @@ -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] diff --git a/test/compass_test.rb b/test/compass_test.rb index 26491328..69cea09c 100644 --- a/test/compass_test.rb +++ b/test/compass_test.rb @@ -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| diff --git a/test/fixtures/stylesheets/busted_image_urls/config.rb b/test/fixtures/stylesheets/busted_image_urls/config.rb new file mode 100644 index 00000000..9961c9bd --- /dev/null +++ b/test/fixtures/stylesheets/busted_image_urls/config.rb @@ -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 diff --git a/test/fixtures/stylesheets/busted_image_urls/css/screen.css b/test/fixtures/stylesheets/busted_image_urls/css/screen.css new file mode 100644 index 00000000..9935c20f --- /dev/null +++ b/test/fixtures/stylesheets/busted_image_urls/css/screen.css @@ -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'); } diff --git a/test/fixtures/stylesheets/busted_image_urls/images/grid.png b/test/fixtures/stylesheets/busted_image_urls/images/grid.png new file mode 100644 index 0000000000000000000000000000000000000000..76aaa851a17551b07c608797105bf6e4ba204148 GIT binary patch literal 199 zcmeAS@N?(olHy`uVBq!ia0vp^8bB-}zy>7OUt9bGNUZ}$lIVGz#3>Ma-jF$ZsY0(YncrlhC+|`Fx8c*$A-Tz zURV0ZXYJA_XUfmr?XQ{3sL1TZ*22RfDPW|K;&7s20;a&iIhQ2XzO{Q?D=6sy=8i=j W|D0$1qSt{|GI+ZBxvX Date: Wed, 4 May 2011 11:37:58 +0200 Subject: [PATCH 02/12] 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 From 8661c481cf21535729fcfc21af911865091d5d69 Mon Sep 17 00:00:00 2001 From: Mattias Pfeiffer Date: Wed, 4 May 2011 11:43:22 +0200 Subject: [PATCH 03/12] Fix comments for asset_cache_buster --- lib/compass/configuration/data.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compass/configuration/data.rb b/lib/compass/configuration/data.rb index 0173fa93..ddc2de3a 100644 --- a/lib/compass/configuration/data.rb +++ b/lib/compass/configuration/data.rb @@ -73,8 +73,8 @@ module Compass # When called with a block, defines the cache buster strategy to be used. # 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 may also return a hash with :path and/or :query values and it + # will replace the original path and query string with the busted values 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. From d4422d108e6259103a53cc95f7cdcfbb45758721 Mon Sep 17 00:00:00 2001 From: Mattias Pfeiffer Date: Thu, 5 May 2011 10:06:48 +0200 Subject: [PATCH 04/12] Adding changelog entry --- doc-src/content/CHANGELOG-v0-11-beta.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/doc-src/content/CHANGELOG-v0-11-beta.markdown b/doc-src/content/CHANGELOG-v0-11-beta.markdown index 127f0f24..17fc5769 100644 --- a/doc-src/content/CHANGELOG-v0-11-beta.markdown +++ b/doc-src/content/CHANGELOG-v0-11-beta.markdown @@ -10,6 +10,7 @@ layout: article * Created an official API to add configuration options to compass. [More information](/help/tutorials/extending/). +* Enhanced cache busting by allowing path manipulation 0.11.beta.7 (04/16/2011) ------------------------ From 6b3ca3901cec07776a6c21bedd4989d268267017 Mon Sep 17 00:00:00 2001 From: Mattias Pfeiffer Date: Thu, 5 May 2011 10:14:21 +0200 Subject: [PATCH 05/12] Adding note about path based asset cache busting in to documentation --- .../configuration-reference.markdown | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/doc-src/content/help/tutorials/configuration-reference.markdown b/doc-src/content/help/tutorials/configuration-reference.markdown index af6d6ea7..3a966856 100644 --- a/doc-src/content/help/tutorials/configuration-reference.markdown +++ b/doc-src/content/help/tutorials/configuration-reference.markdown @@ -308,9 +308,12 @@ the asset host configuration is ignored. --- **`asset_cache_buster`** – Pass this function a block of code that 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 `?`. The block will be passed the root-relative url of the asset. +cache buster strategy to be used. The block must return nil, a string or a hash. +If the returned value is a hash the values of :path and/or :query is used to generate +a cache busted path to the asset. If a string value is returned, it is added as a query string. +The returned values for query strings must not include the starting `?`. + +The block will be passed the root-relative url of the asset. If the block accepts two arguments, it will also be passed a path that points to the asset on disk — which may or may not exist. @@ -324,6 +327,18 @@ that points to the asset on disk — which may or may not exist. end end +Busting the cache via path: + + asset_cache_buster do |path, real_path| + if File.exists?(real_path) + pathname = Pathname.new(path) + modified_time = File.mtime(real_path).strftime("%s") + new_path = "%s/%s-%s%s" % [pathname.dirname, pathname.basename(pathname.extname), modified_time, pathname.extname] + + {:path => new_path, :query => nil} + end + end + To disable the asset cache buster: asset_cache_buster :none From 223258c2032d089100269fbff6281c971bad8aa1 Mon Sep 17 00:00:00 2001 From: Mattias Pfeiffer Date: Thu, 5 May 2011 10:19:19 +0200 Subject: [PATCH 06/12] Removing unneeded 'unquote' from tests --- .../stylesheets/busted_image_urls/sass/screen.sass | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/fixtures/stylesheets/busted_image_urls/sass/screen.sass b/test/fixtures/stylesheets/busted_image_urls/sass/screen.sass index 8f844f2a..b469b120 100644 --- a/test/fixtures/stylesheets/busted_image_urls/sass/screen.sass +++ b/test/fixtures/stylesheets/busted_image_urls/sass/screen.sass @@ -1,14 +1,14 @@ .showgrid - background-image: image-url(unquote("grid.png")) + background-image: image-url("grid.png") .inlinegrid - background-image: inline-image(unquote("grid.png")) + background-image: inline-image("grid.png") .no-buster background-image: image-url("grid.png", $only-path: false, $cache-buster: false) .feed - background-image: image-url(unquote("feed.png")) + background-image: image-url("feed.png") .dk - background-image: image-url(unquote("flags/dk.png")) \ No newline at end of file + background-image: image-url("flags/dk.png") \ No newline at end of file From 437842caa1c0f62a1758416cebf9728cc4bf0134 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 11 Jun 2011 19:39:33 -0700 Subject: [PATCH 07/12] Revert "Adding changelog entry" This reverts commit d4422d108e6259103a53cc95f7cdcfbb45758721. --- doc-src/content/CHANGELOG-v0-11-beta.markdown | 1 - 1 file changed, 1 deletion(-) diff --git a/doc-src/content/CHANGELOG-v0-11-beta.markdown b/doc-src/content/CHANGELOG-v0-11-beta.markdown index 17fc5769..127f0f24 100644 --- a/doc-src/content/CHANGELOG-v0-11-beta.markdown +++ b/doc-src/content/CHANGELOG-v0-11-beta.markdown @@ -10,7 +10,6 @@ layout: article * Created an official API to add configuration options to compass. [More information](/help/tutorials/extending/). -* Enhanced cache busting by allowing path manipulation 0.11.beta.7 (04/16/2011) ------------------------ From c069babe76e045f09b4662516f68fb5005eb15cf Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 11 Jun 2011 21:54:12 -0700 Subject: [PATCH 08/12] log removal actions in the compiler output. --- lib/compass/actions.rb | 5 ++++- lib/compass/commands/update_project.rb | 1 + lib/compass/compiler.rb | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/compass/actions.rb b/lib/compass/actions.rb index bc4a2b82..4e924f1b 100644 --- a/lib/compass/actions.rb +++ b/lib/compass/actions.rb @@ -65,7 +65,10 @@ module Compass end def remove(file_name) - if File.exists?(file_name) + if File.directory?(file_name) + FileUtils.rm_rf file_name + log_action :remove, basename(file_name)+"/", options + elsif File.exists?(file_name) File.unlink file_name log_action :remove, basename(file_name), options end diff --git a/lib/compass/commands/update_project.rb b/lib/compass/commands/update_project.rb index d570da2f..30e2654f 100644 --- a/lib/compass/commands/update_project.rb +++ b/lib/compass/commands/update_project.rb @@ -54,6 +54,7 @@ module Compass compiler_opts = {:sass => Compass.sass_engine_options} compiler_opts.merge!(options) compiler_opts[:sass_files] = explicit_sass_files + compiler_opts[:cache_location] = determine_cache_location compiler_opts end diff --git a/lib/compass/compiler.rb b/lib/compass/compiler.rb index 961a4624..606f9406 100644 --- a/lib/compass/compiler.rb +++ b/lib/compass/compiler.rb @@ -75,9 +75,9 @@ module Compass end def clean! - FileUtils.rm_rf options[:cache_location] + remove options[:cache_location] css_files.each do |css_file| - FileUtils.rm_f css_file + remove css_file end end From ab25ba0b40725172415cbc496e77ceae95002dea Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 11 Jun 2011 21:54:32 -0700 Subject: [PATCH 09/12] Code cleanup --- lib/compass/exec/sub_command_ui.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compass/exec/sub_command_ui.rb b/lib/compass/exec/sub_command_ui.rb index 972f82c8..43a5a308 100644 --- a/lib/compass/exec/sub_command_ui.rb +++ b/lib/compass/exec/sub_command_ui.rb @@ -13,6 +13,7 @@ module Compass::Exec def run! begin perform! + return 0 rescue Exception => e raise e if e.is_a? SystemExit if e.is_a?(::Compass::Error) || e.is_a?(OptionParser::ParseError) @@ -22,7 +23,6 @@ module Compass::Exec end return 1 end - return 0 end protected From 2be7567bb20d25e5ac74828856f0d982e6dc29b1 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 11 Jun 2011 21:54:56 -0700 Subject: [PATCH 10/12] Better error message when a sub command is missing. --- lib/compass/commands/registry.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/compass/commands/registry.rb b/lib/compass/commands/registry.rb index 64372079..3b5c0d16 100644 --- a/lib/compass/commands/registry.rb +++ b/lib/compass/commands/registry.rb @@ -16,8 +16,10 @@ module Compass::Commands matching.first elsif name =~ /^-/ nil - else + elsif matching.size > 1 raise Compass::Error, "Ambiguous abbreviation '#{name}'. Did you mean one of: #{matching.join(", ")}" + else + raise Compass::Error, "Command not found: #{name}" end end def abbreviation?(name) From 39df74c55af4f473c26dd8160e41deb47ff7559d Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 11 Jun 2011 21:56:08 -0700 Subject: [PATCH 11/12] Add a new command to clean up generated files --- features/command_line.feature | 23 +++++- .../step_definitions/command_line_steps.rb | 20 +++++ lib/compass/commands.rb | 2 +- lib/compass/commands/clean_project.rb | 79 +++++++++++++++++++ lib/compass/sprite_importer.rb | 9 ++- 5 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 lib/compass/commands/clean_project.rb diff --git a/features/command_line.feature b/features/command_line.feature index f0be79b1..06e0060c 100644 --- a/features/command_line.feature +++ b/features/command_line.feature @@ -145,6 +145,7 @@ Feature: Command Line Scenario: Basic help When I run: compass help Then I should see the following "primary" commands: + | clean | | compile | | create | | init | @@ -179,6 +180,27 @@ Feature: Command Line And I run: compass compile And a css file tmp/layout.css is reported overwritten + Scenario: Cleaning a project + Given I am using the existing project in test/fixtures/stylesheets/compass + When I run: compass compile + And I run: compass clean + Then the following files are reported removed: + | .sass-cache/ | + | tmp/border_radius.css | + | tmp/box.css | + | tmp/box_shadow.css | + | tmp/columns.css | + | tmp/fonts.css | + | images/flag-s03c3b29b35.png | + And the following files are removed: + | .sass-cache/ | + | tmp/border_radius.css | + | tmp/box.css | + | tmp/box_shadow.css | + | tmp/columns.css | + | tmp/fonts.css | + | images/flag-s03c3b29b35.png | + Scenario: Watching a project for changes Given ruby supports fork Given I am using the existing project in test/fixtures/stylesheets/compass @@ -218,7 +240,6 @@ Feature: Command Line | sass_dir | sass | | css_dir | assets/css | - @now Scenario Outline: Print out a configuration value Given I am using the existing project in test/fixtures/stylesheets/compass When I run: compass config -p diff --git a/features/step_definitions/command_line_steps.rb b/features/step_definitions/command_line_steps.rb index 8811693d..5bddd7a7 100644 --- a/features/step_definitions/command_line_steps.rb +++ b/features/step_definitions/command_line_steps.rb @@ -116,10 +116,30 @@ Then /^a directory ([^ ]+) is (not )?created$/ do |directory, negated| File.directory?(directory).should == !negated end +Then /an? \w+ file ([^ ]+) is (not )?removed/ do |filename, negated| + File.exists?(filename).should == !!negated +end + Then /an? \w+ file ([^ ]+) is (not )?created/ do |filename, negated| File.exists?(filename).should == !negated end +Then "the following files are reported removed:" do |table| + table.rows.each do |css_file| + Then %Q{a css file #{css_file.first} is reported removed} + end +end + +Then "the following files are removed:" do |table| + table.rows.each do |css_file| + Then %Q{a css file #{css_file.first} is removed} + end +end + +Then /an? \w+ file ([^ ]+) is reported removed/ do |filename| + @last_result.should =~ /remove.*#{Regexp.escape(filename)}/ +end + Then /an? \w+ file ([^ ]+) is reported created/ do |filename| @last_result.should =~ /create.*#{Regexp.escape(filename)}/ end diff --git a/lib/compass/commands.rb b/lib/compass/commands.rb index f4230ef4..42ca37ab 100644 --- a/lib/compass/commands.rb +++ b/lib/compass/commands.rb @@ -4,7 +4,7 @@ end require 'compass/commands/registry' %w(base generate_grid_background default help list_frameworks project_base - update_project watch_project create_project imports installer_command + update_project watch_project create_project clean_project imports installer_command print_version project_stats stamp_pattern sprite validate_project write_configuration interactive unpack_extension).each do |lib| require "compass/commands/#{lib}" diff --git a/lib/compass/commands/clean_project.rb b/lib/compass/commands/clean_project.rb new file mode 100644 index 00000000..e6792326 --- /dev/null +++ b/lib/compass/commands/clean_project.rb @@ -0,0 +1,79 @@ +require 'compass/commands/project_base' +require 'compass/compiler' + +module Compass + module Commands + module CleanProjectOptionsParser + def set_options(opts) + opts.banner = %Q{ + Usage: compass clean [path/to/project] [options] + + Description: + Remove generated files and the sass cache. + + Options: + }.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n") + + super + end + end + + class CleanProject < UpdateProject + + register :clean + + def initialize(working_path, options) + super + assert_project_directory_exists! + end + + def perform + compiler = new_compiler_instance + compiler.clean! + Compass::SpriteImporter.find_all_sprite_map_files(Compass.configuration.images_path).each do |sprite| + remove sprite + end + end + + def determine_cache_location + Compass.configuration.cache_path || Sass::Plugin.options[:cache_location] || File.join(working_path, ".sass-cache") + end + + class << self + def option_parser(arguments) + parser = Compass::Exec::CommandOptionParser.new(arguments) + parser.extend(Compass::Exec::GlobalOptionsParser) + parser.extend(Compass::Exec::ProjectOptionsParser) + parser.extend(CleanProjectOptionsParser) + end + + def usage + option_parser([]).to_s + end + + def primary; true; end + + def description(command) + "Remove generated files and the sass cache" + end + + def parse!(arguments) + parser = option_parser(arguments) + parser.parse! + parse_arguments!(parser, arguments) + parser.options + end + + def parse_arguments!(parser, arguments) + if arguments.size > 0 + parser.options[:project_name] = arguments.shift if File.directory?(arguments.first) + unless arguments.empty? + parser.options[:sass_files] = arguments.dup + parser.options[:force] = true + end + end + end + end + end + end +end diff --git a/lib/compass/sprite_importer.rb b/lib/compass/sprite_importer.rb index 459c20e6..3dd1bd3e 100644 --- a/lib/compass/sprite_importer.rb +++ b/lib/compass/sprite_importer.rb @@ -4,7 +4,14 @@ module Compass VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/ SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png} VALID_EXTENSIONS = ['.png'] - + + # finds all sprite files + def self.find_all_sprite_map_files(path) + hex = "[0-9a-f]" + glob = "*-{,s}#{hex*10}{#{VALID_EXTENSIONS.join(",")}}" + Dir.glob(File.join(path, "**", glob)) + end + def self.load(uri, options) klass = Compass::SpriteImporter.new klass.uri, klass.options = uri, options From fa165a3d84adb728d59b858fd860e6d30c79eda3 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 11 Jun 2011 22:28:56 -0700 Subject: [PATCH 12/12] bump chunky_png version dependency. --- Gemfile.lock | 4 ++-- compass.gemspec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 86c2008b..7d934b0f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,8 +7,8 @@ GIT PATH remote: . specs: - compass (0.11.3.e4a22c4) - chunky_png (~> 1.1) + compass (0.11.3.a6a7069) + chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/compass.gemspec b/compass.gemspec index 87e2436f..d6c1194e 100644 --- a/compass.gemspec +++ b/compass.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |gemspec| gemspec.summary = %q{A Real Stylesheet Framework} gemspec.add_dependency 'sass', '~> 3.1' - gemspec.add_dependency 'chunky_png', '~> 1.1' + gemspec.add_dependency 'chunky_png', '~> 1.2' gemspec.add_dependency 'fssm', '>= 0.2.7' gemspec.files = %w(README.markdown LICENSE.markdown VERSION.yml Rakefile)