get relative_assets working with a specified http_path
This commit is contained in:
parent
98764eb93a
commit
91bc86640a
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
0
spec/fixtures/sample/public/stylesheets/auto-css.css
vendored
Normal file
0
spec/fixtures/sample/public/stylesheets/auto-css.css
vendored
Normal file
0
spec/fixtures/sample/public/stylesheets/sub1/auto-css.css
vendored
Normal file
0
spec/fixtures/sample/public/stylesheets/sub1/auto-css.css
vendored
Normal file
0
spec/fixtures/sample/public/stylesheets/sub1/sub2/auto-css.css
vendored
Normal file
0
spec/fixtures/sample/public/stylesheets/sub1/sub2/auto-css.css
vendored
Normal file
1
spec/fixtures/sample/views/auto-css.html.haml
vendored
Normal file
1
spec/fixtures/sample/views/auto-css.html.haml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
= auto_stylesheet_link_tag
|
1
spec/fixtures/sample/views/page-classes.html.haml
vendored
Normal file
1
spec/fixtures/sample/views/page-classes.html.haml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
= page_classes
|
45
spec/helpers_spec.rb
Normal file
45
spec/helpers_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue