Use Addressable to improve inline url detection and rewriting. Only rewrite relative paths. Closes #1499
This commit is contained in:
parent
40e01b0b21
commit
4740159a3a
|
@ -1,17 +1,4 @@
|
||||||
Feature: Alternate between multiple asset hosts
|
Feature: Alternate between multiple asset hosts
|
||||||
In order to speed up page loading
|
|
||||||
|
|
||||||
Scenario: Set single host globally
|
|
||||||
Given a fixture app "asset-host-app"
|
|
||||||
And a file named "config.rb" with:
|
|
||||||
"""
|
|
||||||
activate :asset_host, host: "http://assets1.example.com"
|
|
||||||
"""
|
|
||||||
And the Server is running
|
|
||||||
When I go to "/asset_host.html"
|
|
||||||
Then I should see "http://assets1"
|
|
||||||
When I go to "/stylesheets/asset_host.css"
|
|
||||||
Then I should see "http://assets1"
|
|
||||||
|
|
||||||
Scenario: Set single host with inline-option
|
Scenario: Set single host with inline-option
|
||||||
Given a fixture app "asset-host-app"
|
Given a fixture app "asset-host-app"
|
||||||
|
@ -21,6 +8,7 @@ Feature: Alternate between multiple asset hosts
|
||||||
"""
|
"""
|
||||||
And the Server is running
|
And the Server is running
|
||||||
When I go to "/asset_host.html"
|
When I go to "/asset_host.html"
|
||||||
|
Then I should see 'src="https://code.jquery.com/jquery-2.1.3.min.js"'
|
||||||
Then I should see content matching %r{http://assets1.example.com/}
|
Then I should see content matching %r{http://assets1.example.com/}
|
||||||
Then I should not see content matching %r{http://assets1.example.com//}
|
Then I should not see content matching %r{http://assets1.example.com//}
|
||||||
When I go to "/stylesheets/asset_host.css"
|
When I go to "/stylesheets/asset_host.css"
|
||||||
|
@ -37,6 +25,7 @@ Feature: Alternate between multiple asset hosts
|
||||||
"""
|
"""
|
||||||
And the Server is running
|
And the Server is running
|
||||||
When I go to "/asset_host.html"
|
When I go to "/asset_host.html"
|
||||||
|
Then I should see 'src="https://code.jquery.com/jquery-2.1.3.min.js"'
|
||||||
Then I should see content matching %r{http://assets1.example.com/}
|
Then I should see content matching %r{http://assets1.example.com/}
|
||||||
Then I should not see content matching %r{http://assets1.example.com//}
|
Then I should not see content matching %r{http://assets1.example.com//}
|
||||||
When I go to "/stylesheets/asset_host.css"
|
When I go to "/stylesheets/asset_host.css"
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
|
||||||
|
|
||||||
<%= image_tag "blank0.gif" %>
|
<%= image_tag "blank0.gif" %>
|
||||||
<%= image_tag "blank1.gif" %>
|
<%= image_tag "blank1.gif" %>
|
||||||
<%= image_tag "blank2.gif" %>
|
<%= image_tag "blank2.gif" %>
|
||||||
|
|
|
@ -15,6 +15,7 @@ require 'rack/mime'
|
||||||
require 'middleman-core/contracts'
|
require 'middleman-core/contracts'
|
||||||
|
|
||||||
# For URI templating
|
# For URI templating
|
||||||
|
require 'addressable/uri'
|
||||||
require 'addressable/template'
|
require 'addressable/template'
|
||||||
require 'active_support/inflector'
|
require 'active_support/inflector'
|
||||||
require 'active_support/inflector/transliterate'
|
require 'active_support/inflector/transliterate'
|
||||||
|
@ -323,9 +324,15 @@ module Middleman
|
||||||
opening_character = $1
|
opening_character = $1
|
||||||
asset_path = $2
|
asset_path = $2
|
||||||
|
|
||||||
if result = yield(asset_path)
|
begin
|
||||||
"#{opening_character}#{result}"
|
uri = ::Addressable::URI.parse(asset_path)
|
||||||
else
|
|
||||||
|
if uri.relative? && result = yield(asset_path)
|
||||||
|
"#{opening_character}#{result}"
|
||||||
|
else
|
||||||
|
match
|
||||||
|
end
|
||||||
|
rescue
|
||||||
match
|
match
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue