Merge pull request #1842 from puyo/fix/asset-url-and-relative-paths

Fix asset_url and relative option bug.
feature/manifest
Thomas Reynolds 2016-03-20 16:06:47 -07:00
commit 02a0b557f6
2 changed files with 19 additions and 1 deletions

View File

@ -77,7 +77,11 @@ module Middleman
uri = URI(path)
path = uri.path
result = if resource = app.sitemap.find_resource_by_destination_path(url_for(app, path, options))
# Ensure the url we pass into find_resource_by_destination_path is not a
# relative path, since it only takes absolute url paths.
dest_path = url_for(app, path, options.merge(relative: false))
result = if resource = app.sitemap.find_resource_by_destination_path(dest_path)
resource.url
else
path = ::File.join(prefix, path)

View File

@ -120,6 +120,20 @@ describe Middleman::Util do
relative: true ) ).to eq '../images/blank.gif'
end
context "when the asset is stored in the same directory as current_resource" do
before do
Given.file 'source/a-path/index.html', ''
Given.file 'source/a-path/blank.gif', ''
@mm = Middleman::Application.new
end
it "returns path relative to the provided current_resource" do
current_resource = @mm.sitemap.find_resource_by_path('a-path/index.html')
expect( Middleman::Util.asset_url( @mm, 'blank.gif', 'images', current_resource: current_resource,
relative: true) ).to eq 'blank.gif'
end
end
it "raises error if not given a current_resource" do
expect{
Middleman::Util.asset_url( @mm, 'blank.gif', 'images', relative: true )