Skip to content

Commit

Permalink
Don't lookup resource for path if the path is absolute. Fixes middlem…
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Mar 3, 2015
1 parent a71589b commit 7f2048b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions middleman-core/features/helpers_link_to.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ Feature: link_to helper
When I go to "/link_to_erb.html"
Then I should see "erb <s>with html tags</s>"

Scenario: link_to works with absolute URLs (where the relative part matches a local path)
Given a fixture app "link-to-app"
And a file named "config.rb" with:
"""
set :relative_links, true
"""
And a file named "source/test.html.erb" with:
"""
Hello
"""
And a file named "source/link_to_absolute.html.erb" with:
"""
<%= link_to "test", "http://google.com/test.html" %>
"""
And the Server is running at "link-to-app"
When I go to "/link_to_absolute.html"
Then I should see '<a href="http://google.com/test.html">test</a>'

Scenario: link_to works with blocks (slim)
Given the Server is running at "link-to-app"
When I go to "/link_to_slim.html"
Expand Down
4 changes: 2 additions & 2 deletions middleman-core/lib/middleman-core/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ def url_for(app, path_or_resource, options={})
if path_or_resource.is_a?(::Middleman::Sitemap::Resource)
resource = path_or_resource
resource_url = url
elsif this_resource && uri.path
elsif this_resource && uri.path && !uri.host
# Handle relative urls
url_path = Pathname(uri.path)
current_source_dir = Pathname('/' + this_resource.path).dirname
url_path = current_source_dir.join(url_path) if url_path.relative?
resource = app.sitemap.find_resource_by_path(url_path.to_s)
resource_url = resource.url if resource
elsif options[:find_resource] && uri.path
elsif options[:find_resource] && uri.path && !uri.host
resource = app.sitemap.find_resource_by_path(uri.path)
resource_url = resource.url if resource
end
Expand Down

0 comments on commit 7f2048b

Please sign in to comment.