tests pass, added autosize and relative tests
This commit is contained in:
parent
fb17900ed2
commit
75c5825ec2
12 changed files with 92 additions and 72 deletions
|
@ -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) }
|
||||
|
|
|
@ -2,6 +2,7 @@ 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
|
||||
|
|
|
@ -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
|
|
@ -68,32 +68,39 @@ 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.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!
|
||||
|
|
23
spec/auto_image_sizes.rb
Normal file
23
spec/auto_image_sizes.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
2
spec/fixtures/sample/init.rb
vendored
2
spec/fixtures/sample/init.rb
vendored
|
@ -1 +1 @@
|
|||
enable :maruku
|
||||
# enable :maruku
|
BIN
spec/fixtures/sample/public/images/blank.gif
vendored
Normal file
BIN
spec/fixtures/sample/public/images/blank.gif
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 43 B |
1
spec/fixtures/sample/views/auto-image-sizes.html.haml
vendored
Normal file
1
spec/fixtures/sample/views/auto-image-sizes.html.haml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
= image_tag "blank.gif"
|
3
spec/fixtures/sample/views/stylesheets/relative_assets.css.sass
vendored
Normal file
3
spec/fixtures/sample/views/stylesheets/relative_assets.css.sass
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
@import compass.sass
|
||||
h1
|
||||
background= image_url("blank.gif")
|
|
@ -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
|
||||
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
|
Loading…
Reference in a new issue