diff --git a/lib/middleman/features/cache_buster.rb b/lib/middleman/features/cache_buster.rb index b417061a..101bde6a 100755 --- a/lib/middleman/features/cache_buster.rb +++ b/lib/middleman/features/cache_buster.rb @@ -1,6 +1,4 @@ -class Middleman::Base - include Middleman::Sass - +class Middleman::Base after_feature_init do ::Compass.configuration do |config| config.asset_cache_buster do |path, real_path| @@ -31,8 +29,12 @@ class << Middleman::Base rescue end - real_path = File.join(self.public, prefix, path) - http_path << "?" + File.mtime(real_path).strftime("%s") if File.readable?(real_path) + real_path_static = File.join(self.public, prefix, path) + real_path_dynamic = File.join(self.views, prefix, path) + real_path_dynamic << ".sass" if File.extname(real_path_dynamic) == ".css" + + http_path << "?" + File.mtime(real_path_static).strftime("%s") if File.readable?(real_path_static) + http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic) http_path end end diff --git a/spec/cache_buster_off_spec.rb b/spec/cache_buster_off_spec.rb new file mode 100755 index 00000000..ac612f18 --- /dev/null +++ b/spec/cache_buster_off_spec.rb @@ -0,0 +1,21 @@ +require File.join(File.dirname(__FILE__), "spec_helper") + +describe "Cache Buster Feature in CSS" do + before :each do + @base = ::Middleman::Base + @base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample") + @base.disable :cache_buster + end + + it "should not append query string in CSS if off" do + browser = Rack::Test::Session.new(Rack::MockSession.new(@base.new)) + browser.get("/stylesheets/relative_assets.css") + browser.last_response.body.should_not include("?") + end + + it "should not append query string in HTML if off" do + browser = Rack::Test::Session.new(Rack::MockSession.new(@base.new)) + browser.get("/cache-buster.html") + browser.last_response.body.count("?").should == 0 + end +end \ No newline at end of file diff --git a/spec/cache_buster_on_spec.rb b/spec/cache_buster_on_spec.rb new file mode 100755 index 00000000..b91e97d8 --- /dev/null +++ b/spec/cache_buster_on_spec.rb @@ -0,0 +1,21 @@ +require File.join(File.dirname(__FILE__), "spec_helper") + +describe "Cache Buster Feature in CSS" do + before :each do + @base = ::Middleman::Base + @base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample") + @base.enable :cache_buster + end + + it "should append query string in CSS if on" do + browser = Rack::Test::Session.new(Rack::MockSession.new(@base.new)) + browser.get("/stylesheets/relative_assets.css") + browser.last_response.body.should include("?") + end + + it "should append query string in HTML if on" do + browser = Rack::Test::Session.new(Rack::MockSession.new(@base.new)) + browser.get("/cache-buster.html") + browser.last_response.body.count("?").should == 2 + end +end \ No newline at end of file diff --git a/spec/cache_buster_spec.rb b/spec/cache_buster_spec.rb deleted file mode 100755 index c44fe6bc..00000000 --- a/spec/cache_buster_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require File.join(File.dirname(__FILE__), "spec_helper") - -base = ::Middleman::Base -base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample") - -describe "Cache Buster Feature" do - it "should not append query string if off" do - base.disable :cache_buster - browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) - browser.get("/stylesheets/relative_assets.css") - browser.last_response.body.should_not include("?") - end - - it "should append query string if on" do - base.enable :cache_buster - browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) - browser.get("/stylesheets/relative_assets.css") - browser.last_response.body.should include("?") - end -end \ No newline at end of file diff --git a/spec/fixtures/sample/views/cache-buster.html.haml b/spec/fixtures/sample/views/cache-buster.html.haml new file mode 100644 index 00000000..adb1540e --- /dev/null +++ b/spec/fixtures/sample/views/cache-buster.html.haml @@ -0,0 +1,2 @@ += stylesheet_link_tag "site.css" += javascript_include_tag "empty-with-include.js" \ No newline at end of file diff --git a/spec/fixtures/sample/views/layout.haml b/spec/fixtures/sample/views/layout.haml index 4396e77c..15c1ed95 100755 --- a/spec/fixtures/sample/views/layout.haml +++ b/spec/fixtures/sample/views/layout.haml @@ -1,6 +1,5 @@ %html %head - %link{ :href => "/stylesheets/site.css", :rel => "stylesheet", :type => "text/css" } %title My Sample Site %body = yield \ No newline at end of file