diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index a0a0cf96..315dc2b0 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -17,7 +17,7 @@ module Middleman set :css_dir, "stylesheets" set :images_dir, "images" set :build_dir, "build" - set :http_prefix, "/" + set :http_prefix, nil use Rack::ConditionalGet if environment == :development diff --git a/lib/middleman/features/relative_assets.rb b/lib/middleman/features/relative_assets.rb index 97959c99..88e694b5 100644 --- a/lib/middleman/features/relative_assets.rb +++ b/lib/middleman/features/relative_assets.rb @@ -10,18 +10,23 @@ class << Middleman::Base rescue end - path = pre_relative_asset_url(path, prefix, request) if path.include?("://") + pre_relative_asset_url(path, prefix, request) + elsif path[0,1] == "/" path else - path = path[1,path.length-1] if path[0,1] == '/' + path = File.join(prefix, path) if prefix.length > 0 request_path = request.path_info.dup - request_path << self.class.index_file if path.match(%r{/$}) + request_path << self.index_file if path.match(%r{/$}) request_path.gsub!(%r{^/}, '') parts = request_path.split('/') - + if parts.length > 1 - "../" * (parts.length - 1) + path + arry = [] + (parts.length - 1).times { arry << ".." } + arry << path + File.join(*arry) + #"../" * (parts.length - 1) + path else path end diff --git a/lib/middleman/helpers.rb b/lib/middleman/helpers.rb index 8eabea96..abf986ff 100644 --- a/lib/middleman/helpers.rb +++ b/lib/middleman/helpers.rb @@ -1,8 +1,7 @@ module Middleman class Base def self.asset_url(path, prefix="", request=nil) - base_url = File.join(self.http_prefix, prefix) - path.include?("://") ? path : File.join(base_url, path) + path.include?("://") ? path : File.join(self.http_prefix || "/", prefix, path) end end diff --git a/lib/middleman/sass.rb b/lib/middleman/sass.rb index 72a4a2ed..d85c96d1 100644 --- a/lib/middleman/sass.rb +++ b/lib/middleman/sass.rb @@ -1,4 +1,5 @@ require "sass" +#gem "compass-edge" require "compass" module Middleman @@ -75,8 +76,8 @@ class Middleman::Base 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.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.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 { false } config.add_import_path(config.sass_dir) diff --git a/spec/fixtures/sample/public/stylesheets/auto-css.css b/spec/fixtures/sample/public/stylesheets/auto-css.css new file mode 100644 index 00000000..e69de29b diff --git a/spec/fixtures/sample/public/stylesheets/sub1/auto-css.css b/spec/fixtures/sample/public/stylesheets/sub1/auto-css.css new file mode 100644 index 00000000..e69de29b diff --git a/spec/fixtures/sample/public/stylesheets/sub1/sub2/auto-css.css b/spec/fixtures/sample/public/stylesheets/sub1/sub2/auto-css.css new file mode 100644 index 00000000..e69de29b diff --git a/spec/fixtures/sample/views/auto-css.html.haml b/spec/fixtures/sample/views/auto-css.html.haml new file mode 100644 index 00000000..36324bb3 --- /dev/null +++ b/spec/fixtures/sample/views/auto-css.html.haml @@ -0,0 +1 @@ += auto_stylesheet_link_tag \ No newline at end of file diff --git a/spec/fixtures/sample/views/page-classes.html.haml b/spec/fixtures/sample/views/page-classes.html.haml new file mode 100644 index 00000000..0a933c0a --- /dev/null +++ b/spec/fixtures/sample/views/page-classes.html.haml @@ -0,0 +1 @@ += page_classes \ No newline at end of file diff --git a/spec/helpers_spec.rb b/spec/helpers_spec.rb new file mode 100644 index 00000000..da15e8cb --- /dev/null +++ b/spec/helpers_spec.rb @@ -0,0 +1,45 @@ +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 "page_classes helper" do + it "should generate root paths correctly" do + browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) + browser.get("/page-class.html") + browser.last_response.body.chomp.should == "page-class" + end + + it "should generate 1-deep paths correctly" do + browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) + browser.get("/sub1/page-class.html") + browser.last_response.body.chomp.should == "sub1 sub1_page-class" + end + + it "should generate 2-deep paths correctly" do + browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) + browser.get("/sub1/sub2/page-class.html") + browser.last_response.body.chomp.should == "sub1 sub1_sub2 sub1_sub2_page-class" + end +end + +describe "auto_stylesheet_link_tag helper" do + it "should generate root paths correctly" do + browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) + browser.get("/auto-css.html") + browser.last_response.body.chomp.should include("stylesheets/auto-css.css") + end + + it "should generate 1-deep paths correctly" do + browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) + browser.get("/sub1/auto-css.html") + browser.last_response.body.chomp.should include("stylesheets/sub1/auto-css.css") + end + + it "should generate 2-deep paths correctly" do + browser = Rack::Test::Session.new(Rack::MockSession.new(base.new)) + browser.get("/sub1/sub2/auto-css.html") + browser.last_response.body.chomp.should include("stylesheets/sub1/sub2/auto-css.css") + end +end \ No newline at end of file