From 75c5825ec2486953effafb4b6898836f074984ac Mon Sep 17 00:00:00 2001 From: tdreyno Date: Tue, 27 Oct 2009 18:13:19 -0700 Subject: [PATCH] tests pass, added autosize and relative tests --- lib/middleman/base.rb | 9 +++- lib/middleman/features/cache_buster.rb | 3 +- lib/middleman/features/compass.rb | 18 ------- lib/middleman/sass.rb | 41 ++++++++------ spec/auto_image_sizes.rb | 23 ++++++++ spec/builder_spec.rb | 2 +- spec/cache_buster_spec.rb | 11 ++-- spec/fixtures/sample/init.rb | 2 +- spec/fixtures/sample/public/images/blank.gif | Bin 0 -> 43 bytes .../sample/views/auto-image-sizes.html.haml | 1 + .../stylesheets/relative_assets.css.sass | 3 ++ spec/relative_assets_spec.rb | 51 ++++++++---------- 12 files changed, 92 insertions(+), 72 deletions(-) delete mode 100644 lib/middleman/features/compass.rb create mode 100644 spec/auto_image_sizes.rb create mode 100644 spec/fixtures/sample/public/images/blank.gif create mode 100644 spec/fixtures/sample/views/auto-image-sizes.html.haml create mode 100644 spec/fixtures/sample/views/stylesheets/relative_assets.css.sass diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index f5187e7b..50419d5b 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -120,13 +120,18 @@ class Middleman::Base if File.exists? local_config puts "== Reading: Local config" if logging? class_eval File.read(local_config) + set :app_file, File.expand_path(local_config) end # loop over enabled feature @@features.flatten.each do |feature_name| next unless send(:"#{feature_name}?") - puts "== Enabling: #{feature_name.capitalize}" if logging? - require "middleman/features/#{feature_name}" + + feature_path = "features/#{feature_name}" + if File.exists? File.join(File.dirname(__FILE__), "#{feature_path}.rb") + puts "== Enabling: #{feature_name.to_s.capitalize}" if logging? + require "middleman/#{feature_path}" + end end @@afters.each { |block| class_eval(&block) } diff --git a/lib/middleman/features/cache_buster.rb b/lib/middleman/features/cache_buster.rb index ae9e1732..bc019be8 100644 --- a/lib/middleman/features/cache_buster.rb +++ b/lib/middleman/features/cache_buster.rb @@ -1,7 +1,8 @@ -class << Middleman::Base +class << Middleman::Base alias_method :pre_cache_buster_asset_url, :asset_url def asset_url(path, prefix="", request=nil) http_path = pre_cache_buster_asset_url(path, prefix, request) + if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path)) http_path else diff --git a/lib/middleman/features/compass.rb b/lib/middleman/features/compass.rb deleted file mode 100644 index 8f5501c4..00000000 --- a/lib/middleman/features/compass.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Middleman::Base - configure do - ::Compass.configuration do |config| - images_location = (self.environment == "build") ? self.build_dir : self.public - - config.project_path = Dir.pwd - config.sass_dir = File.join(File.basename(self.views), self.css_dir) - config.output_style = :nested - config.css_dir = File.join(File.basename(images_location), self.css_dir) - config.images_dir = File.join(File.basename(images_location), self.images_dir) - # File.expand_path(self.images_dir, self.public) - - config.add_import_path(config.sass_dir) - end - - ::Compass.configure_sass_plugin! - end -end \ No newline at end of file diff --git a/lib/middleman/sass.rb b/lib/middleman/sass.rb index f1bc8755..2226ef8d 100644 --- a/lib/middleman/sass.rb +++ b/lib/middleman/sass.rb @@ -68,34 +68,41 @@ end class Middleman::Base include Middleman::Sass - configure do + after do ::Compass.configuration do |config| - config.project_path = Dir.pwd + config.project_path = self.root config.sass_dir = File.join(File.basename(self.views), self.css_dir) config.output_style = :nested config.css_dir = File.join(File.basename(self.public), self.css_dir) config.images_dir = File.join(File.basename(self.public), self.images_dir) - config.add_import_path(config.sass_dir) - end - end - configure :build do - ::Compass.configuration do |config| - config.css_dir = File.join(File.basename(self.build_dir), self.css_dir) - config.images_dir = File.join(File.basename(self.build_dir), self.images_dir) - end - end - - after do - ::Compass.configuration do |config| + config.add_import_path(config.sass_dir) + config.http_images_path = self.http_images_path rescue File.join(self.http_prefix, self.images_dir) config.http_stylesheets_path = self.http_css_path rescue File.join(self.http_prefix, self.css_dir) - config.asset_cache_buster do - false - end if !self.cache_buster? + if self.cache_buster? + config.asset_cache_buster do |path, real_path| + if File.readable?(real_path) + File.mtime(real_path).strftime("%s") + else + $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}" + end + end + else + config.asset_cache_buster do + false + end + end end + configure :build do + ::Compass.configuration do |config| + config.css_dir = File.join(File.basename(self.build_dir), self.css_dir) + config.images_dir = File.join(File.basename(self.build_dir), self.images_dir) + end + end + ::Compass.configure_sass_plugin! end end \ No newline at end of file diff --git a/spec/auto_image_sizes.rb b/spec/auto_image_sizes.rb new file mode 100644 index 00000000..b065a84b --- /dev/null +++ b/spec/auto_image_sizes.rb @@ -0,0 +1,23 @@ +require 'rack/test' +require File.join(File.dirname(__FILE__), "spec_helper") + +base = ::Middleman::Base +base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample") + +describe "Auto Image sizes Feature" do + it "should not append width and height if off" do + base.disable :automatic_image_sizes + browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) + browser.get("/auto-image-sizes.html") + browser.last_response.body.should_not include("width=") + browser.last_response.body.should_not include("height=") + end + + it "should append width and height if off" do + base.enable :automatic_image_sizes + browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) + browser.get("/auto-image-sizes.html") + browser.last_response.body.should include("width=") + browser.last_response.body.should include("height=") + end +end \ No newline at end of file diff --git a/spec/builder_spec.rb b/spec/builder_spec.rb index 66d3b1ee..fa5dc715 100644 --- a/spec/builder_spec.rb +++ b/spec/builder_spec.rb @@ -39,7 +39,7 @@ describe "Builder" do it "should build sass files" do File.exists?("#{@root_dir}/build/stylesheets/site.css").should be_true - File.read("#{@root_dir}/build/stylesheets/site.css").should include("html,body,div,span,applet,object,iframe") + File.read("#{@root_dir}/build/stylesheets/site.css").gsub(/\s/, "").should include("html,body,div,span,applet,object,iframe") end it "should build static css files" do diff --git a/spec/cache_buster_spec.rb b/spec/cache_buster_spec.rb index a92a63fc..9e89b781 100644 --- a/spec/cache_buster_spec.rb +++ b/spec/cache_buster_spec.rb @@ -1,3 +1,4 @@ +require 'rack/test' require File.join(File.dirname(__FILE__), "spec_helper") base = ::Middleman::Base @@ -6,13 +7,15 @@ 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 - base.new - base.asset_url("stylesheets/static.css").should_not include("?") + 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 - base.new - base.asset_url("stylesheets/static.css").should include("?") + 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/init.rb b/spec/fixtures/sample/init.rb index 41a78066..81e19eb0 100644 --- a/spec/fixtures/sample/init.rb +++ b/spec/fixtures/sample/init.rb @@ -1 +1 @@ -enable :maruku \ No newline at end of file +# enable :maruku \ No newline at end of file diff --git a/spec/fixtures/sample/public/images/blank.gif b/spec/fixtures/sample/public/images/blank.gif new file mode 100644 index 0000000000000000000000000000000000000000..2498f1aac58dab923f0fd99b1c8ee6b8c53c7158 GIT binary patch literal 43 scmZ?wbhEHbWMp7uXkcKtd-pB_1B2pE79h#MpaUX6G7L;iE{qJ;0KEqWk^lez literal 0 HcmV?d00001 diff --git a/spec/fixtures/sample/views/auto-image-sizes.html.haml b/spec/fixtures/sample/views/auto-image-sizes.html.haml new file mode 100644 index 00000000..7588118c --- /dev/null +++ b/spec/fixtures/sample/views/auto-image-sizes.html.haml @@ -0,0 +1 @@ += image_tag "blank.gif" \ No newline at end of file diff --git a/spec/fixtures/sample/views/stylesheets/relative_assets.css.sass b/spec/fixtures/sample/views/stylesheets/relative_assets.css.sass new file mode 100644 index 00000000..6d131005 --- /dev/null +++ b/spec/fixtures/sample/views/stylesheets/relative_assets.css.sass @@ -0,0 +1,3 @@ +@import compass.sass +h1 + background= image_url("blank.gif") \ No newline at end of file diff --git a/spec/relative_assets_spec.rb b/spec/relative_assets_spec.rb index 622dabf1..b1754072 100644 --- a/spec/relative_assets_spec.rb +++ b/spec/relative_assets_spec.rb @@ -1,28 +1,23 @@ -# require File.join(File.dirname(__FILE__), "spec_helper") -# -# base = ::Middleman::Base -# base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample") -# -# describe "Relative Assets Feature" do -# before do -# base.disable :relative_assets -# base.init! -# @app = base.new -# end -# -# it "should not contain ../ if off" do -# @app.asset_url("stylesheets/static.css").should_not include("?") -# end -# end -# -# describe "Relative Assets Feature" do -# before do -# base.enable :relative_assets -# base.init! -# @app = base.new -# end -# -# it "should contain ../ if on" do -# @app.asset_url("stylesheets/static.css").should include("?") -# end -# end \ No newline at end of file +require 'rack/test' +require File.join(File.dirname(__FILE__), "spec_helper") + +base = ::Middleman::Base +base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample") + +describe "Relative Assets Feature" do + it "should not contain ../ if off" do + base.disable :relative_assets + browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) + browser.get("/stylesheets/relative_assets.css") + browser.last_response.body.should_not include("../") + end +end + +describe "Relative Assets Feature" do + it "should contain ../ if on" do + base.enable :relative_assets + 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