allow bad paths in i18n links. for #850
This commit is contained in:
parent
ca8655744a
commit
5630395b40
|
@ -87,9 +87,15 @@ Feature: i18n Paths
|
||||||
msg: Hola
|
msg: Hola
|
||||||
home: Casa
|
home: Casa
|
||||||
"""
|
"""
|
||||||
|
And a file named "source/assets/css/main.css.scss" with:
|
||||||
|
"""
|
||||||
|
$color: red;
|
||||||
|
body { background: $color; }
|
||||||
|
"""
|
||||||
And a file named "source/localizable/index.html.erb" with:
|
And a file named "source/localizable/index.html.erb" with:
|
||||||
"""
|
"""
|
||||||
Page: <%= t(:home) %>
|
Page: <%= t(:home) %>
|
||||||
|
<%= stylesheet_link_tag :main %>
|
||||||
"""
|
"""
|
||||||
And a file named "source/localizable/hello.html.erb" with:
|
And a file named "source/localizable/hello.html.erb" with:
|
||||||
"""
|
"""
|
||||||
|
@ -107,11 +113,15 @@ Feature: i18n Paths
|
||||||
"""
|
"""
|
||||||
And a file named "config.rb" with:
|
And a file named "config.rb" with:
|
||||||
"""
|
"""
|
||||||
|
set :css_dir, 'assets/css'
|
||||||
set :relative_links, true
|
set :relative_links, true
|
||||||
set :strip_index_file, false
|
set :strip_index_file, false
|
||||||
activate :i18n, mount_at_root: :en
|
activate :i18n, mount_at_root: :en
|
||||||
|
activate :relative_assets
|
||||||
"""
|
"""
|
||||||
Given the Server is running at "empty-app"
|
Given the Server is running at "empty-app"
|
||||||
|
When I go to "/index.html"
|
||||||
|
Then I should see "assets/css/main.css"
|
||||||
When I go to "/hello.html"
|
When I go to "/hello.html"
|
||||||
Then I should see "Page: Hello"
|
Then I should see "Page: Hello"
|
||||||
Then I should see '<a class="current" href="index.html">Current Home</a>'
|
Then I should see '<a class="current" href="index.html">Current Home</a>'
|
||||||
|
|
|
@ -63,11 +63,13 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
def url_for(path_or_resource, options={})
|
def url_for(path_or_resource, options={})
|
||||||
locale = options.delete(:locale) || ::I18n.locale
|
locale = options.delete(:locale) || ::I18n.locale
|
||||||
|
|
||||||
should_relativize = options.key?(:relative) ? options[:relative] : config[:relative_links]
|
opts = options.dup
|
||||||
|
|
||||||
options[:relative] = false
|
should_relativize = opts.key?(:relative) ? opts[:relative] : config[:relative_links]
|
||||||
|
|
||||||
href = super(path_or_resource, options)
|
opts[:relative] = false
|
||||||
|
|
||||||
|
href = super(path_or_resource, opts)
|
||||||
|
|
||||||
final_path = if result = extensions[:i18n].localized_path(href, locale)
|
final_path = if result = extensions[:i18n].localized_path(href, locale)
|
||||||
result
|
result
|
||||||
|
@ -76,8 +78,13 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
href
|
href
|
||||||
end
|
end
|
||||||
|
|
||||||
options[:relative] = should_relativize
|
opts[:relative] = should_relativize
|
||||||
super(final_path, options)
|
|
||||||
|
begin
|
||||||
|
super(final_path, opts)
|
||||||
|
rescue RuntimeError
|
||||||
|
super(path_or_resource, options)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue