commit
cf74088085
|
@ -36,3 +36,20 @@ Feature: Directory Index
|
||||||
Given the Server is running at "indexable-app"
|
Given the Server is running at "indexable-app"
|
||||||
When I go to "/leave_me_alone/"
|
When I go to "/leave_me_alone/"
|
||||||
Then I should see "File Not Found"
|
Then I should see "File Not Found"
|
||||||
|
|
||||||
|
Scenario: Link_to knows about directory indexes
|
||||||
|
Given a fixture app "indexable-app"
|
||||||
|
And a file named "source/link_to.html.erb" with:
|
||||||
|
"""
|
||||||
|
link_to: <%= link_to "Needs Index", "/needs_index.html" %>
|
||||||
|
explicit_link_to: <%= link_to "Explicit", "/needs_index/index.html" %>
|
||||||
|
unknown_link_to: <%= link_to "Unknown", "/unknown.html" %>
|
||||||
|
relative_link_to: <%= link_to "Relative", "needs_index.html" %>
|
||||||
|
"""
|
||||||
|
And the Server is running at "indexable-app"
|
||||||
|
When I go to "/link_to/"
|
||||||
|
Then I should see 'link_to: <a href="/needs_index/">Needs Index</a>'
|
||||||
|
Then I should see 'explicit_link_to: <a href="/needs_index/index.html">Explicit</a>'
|
||||||
|
Then I should see 'unknown_link_to: <a href="/unknown.html">Unknown</a>'
|
||||||
|
# Relative links aren't touched
|
||||||
|
Then I should see 'relative_link_to: <a href="needs_index.html">Relative</a>'
|
|
@ -102,5 +102,17 @@ module Middleman::CoreExtensions::DefaultHelpers
|
||||||
result_path ||= asset_url(source, asset_folder)
|
result_path ||= asset_url(source, asset_folder)
|
||||||
"#{result_path}"
|
"#{result_path}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def link_to(*args, &block)
|
||||||
|
url_arg_index = block_given? ? 0 : 1
|
||||||
|
if url = args[url_arg_index]
|
||||||
|
# Only try to work with absolute URLs
|
||||||
|
if url.start_with? '/'
|
||||||
|
resource = sitemap.find_resource_by_path(url)
|
||||||
|
args[url_arg_index] = resource.url if resource
|
||||||
|
end
|
||||||
|
end
|
||||||
|
super(*args, &block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue