Improve link_to so that it can handle a Resource in place of a url. Fixes #474.
This commit is contained in:
parent
f81b6c7c40
commit
8a01b28369
|
@ -1,6 +1,6 @@
|
||||||
Feature: relative_link_to helper
|
Feature: link_to helper
|
||||||
|
|
||||||
Scenario: relative_link_to produces relative links
|
Scenario: link_to produces relative links
|
||||||
Given a fixture app "indexable-app"
|
Given a fixture app "indexable-app"
|
||||||
And an empty file named "config.rb"
|
And an empty file named "config.rb"
|
||||||
And a file named "source/link_to.html.erb" with:
|
And a file named "source/link_to.html.erb" with:
|
||||||
|
@ -21,7 +21,7 @@ Feature: relative_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: relative_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:
|
||||||
"""
|
"""
|
||||||
|
@ -47,7 +47,7 @@ Feature: relative_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: relative_link_to knows about directory indexes
|
Scenario: link_to knows about directory indexes
|
||||||
Given a fixture app "indexable-app"
|
Given a fixture app "indexable-app"
|
||||||
And a file named "source/link_to.html.erb" with:
|
And a file named "source/link_to.html.erb" with:
|
||||||
"""
|
"""
|
||||||
|
@ -66,3 +66,13 @@ Feature: relative_link_to helper
|
||||||
When I go to "/link_to/sub/"
|
When I go to "/link_to/sub/"
|
||||||
Then I should see 'absolute: <a href="../needs_index/">Needs Index</a>'
|
Then I should see 'absolute: <a href="../needs_index/">Needs Index</a>'
|
||||||
Then I should see 'relative: <a href="../needs_index/">Relative</a>'
|
Then I should see 'relative: <a href="../needs_index/">Relative</a>'
|
||||||
|
|
||||||
|
Scenario: link_to can take a Resource
|
||||||
|
Given a fixture app "indexable-app"
|
||||||
|
And a file named "source/link_to.html.erb" with:
|
||||||
|
"""
|
||||||
|
<%= link_to "Needs Index", sitemap.find_resource_by_path("/needs_index.html") %>
|
||||||
|
"""
|
||||||
|
And the Server is running at "indexable-app"
|
||||||
|
When I go to "/link_to/"
|
||||||
|
Then I should see '<a href="/needs_index/">Needs Index</a>'
|
|
@ -124,8 +124,10 @@ module Middleman
|
||||||
options = args[options_index] || {}
|
options = args[options_index] || {}
|
||||||
relative = options.delete(:relative)
|
relative = options.delete(:relative)
|
||||||
|
|
||||||
|
# Handle Resources, which define their own url method
|
||||||
if url.include? '://'
|
if url.respond_to? :url
|
||||||
|
args[url_arg_index] = url.url
|
||||||
|
elsif 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
|
||||||
else
|
else
|
||||||
# Handle relative urls
|
# Handle relative urls
|
||||||
|
|
Loading…
Reference in a new issue