correctly handle passing resources into relative link_to
This commit is contained in:
parent
0a580c8b9a
commit
49ad35b2c8
|
@ -21,6 +21,40 @@ Feature: link_to helper
|
||||||
Then I should see 'absolute: <a href="../needs_index.html">Needs Index</a>'
|
Then I should see 'absolute: <a href="../needs_index.html">Needs Index</a>'
|
||||||
Then I should see 'relative: <a href="../needs_index.html">Relative</a>'
|
Then I should see 'relative: <a href="../needs_index.html">Relative</a>'
|
||||||
|
|
||||||
|
Scenario: link_to relative works with strip_index_file
|
||||||
|
Given a fixture app "indexable-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
set :relative_links, true
|
||||||
|
set :strip_index_file, true
|
||||||
|
helpers do
|
||||||
|
def menu_items(path='link_to.html')
|
||||||
|
sitemap.find_resource_by_destination_path(path).children
|
||||||
|
end
|
||||||
|
end
|
||||||
|
"""
|
||||||
|
And a file named "source/link_to.html.erb" with:
|
||||||
|
"""
|
||||||
|
<% menu_items.each do |item| %>
|
||||||
|
<%= link_to(item.metadata[:page]['title'], item.url) %>
|
||||||
|
<%= link_to(item.metadata[:page]['title'], item) %>
|
||||||
|
<% end %>
|
||||||
|
"""
|
||||||
|
And a file named "source/link_to/sub.html.erb" with:
|
||||||
|
"""
|
||||||
|
<% menu_items.each do |item| %>
|
||||||
|
<%= link_to(item.metadata[:page]['title'], item.url) %>
|
||||||
|
<%= link_to(item.metadata[:page]['title'], item) %>
|
||||||
|
<% end %>
|
||||||
|
"""
|
||||||
|
And the Server is running at "indexable-app"
|
||||||
|
When I go to "/link_to.html"
|
||||||
|
Then I should see '"link_to/sub.html"'
|
||||||
|
Then I should not see "/link_to/sub.html"
|
||||||
|
When I go to "/link_to/sub.html"
|
||||||
|
Then I should see '"sub.html"'
|
||||||
|
Then I should not see "/link_to/sub.html"
|
||||||
|
|
||||||
Scenario: link_to produces relative links when :relative_links is set to true
|
Scenario: link_to produces relative links when :relative_links is set to true
|
||||||
Given a fixture app "indexable-app"
|
Given a fixture app "indexable-app"
|
||||||
And a file named "config.rb" with:
|
And a file named "config.rb" with:
|
||||||
|
|
|
@ -129,8 +129,10 @@ module Middleman
|
||||||
|
|
||||||
# Handle Resources, which define their own url method
|
# Handle Resources, which define their own url method
|
||||||
if url.respond_to? :url
|
if url.respond_to? :url
|
||||||
args[url_arg_index] = url.url
|
url = args[url_arg_index] = url.url
|
||||||
elsif url.include? '://'
|
end
|
||||||
|
|
||||||
|
if url.include? '://'
|
||||||
raise "Can't use the relative option with an external URL" if relative
|
raise "Can't use the relative option with an external URL" if relative
|
||||||
elsif current_resource
|
elsif current_resource
|
||||||
# Handle relative urls
|
# Handle relative urls
|
||||||
|
|
Loading…
Reference in a new issue