From 5630395b40133cfc7757e95414fbf3f52b2f8e5c Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Tue, 2 Jun 2015 13:48:23 -0700 Subject: [PATCH] allow bad paths in i18n links. for #850 --- middleman-core/features/i18n_link_to.feature | 10 ++++++++++ .../lib/middleman-more/core_extensions/i18n.rb | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/middleman-core/features/i18n_link_to.feature b/middleman-core/features/i18n_link_to.feature index 3eed05ab..a10787c4 100644 --- a/middleman-core/features/i18n_link_to.feature +++ b/middleman-core/features/i18n_link_to.feature @@ -87,9 +87,15 @@ Feature: i18n Paths msg: Hola 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: """ Page: <%= t(:home) %> + <%= stylesheet_link_tag :main %> """ And a file named "source/localizable/hello.html.erb" with: """ @@ -107,11 +113,15 @@ Feature: i18n Paths """ And a file named "config.rb" with: """ + set :css_dir, 'assets/css' set :relative_links, true set :strip_index_file, false activate :i18n, mount_at_root: :en + activate :relative_assets """ 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" Then I should see "Page: Hello" Then I should see 'Current Home' diff --git a/middleman-core/lib/middleman-more/core_extensions/i18n.rb b/middleman-core/lib/middleman-more/core_extensions/i18n.rb index 32846b14..318b2b47 100644 --- a/middleman-core/lib/middleman-more/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-more/core_extensions/i18n.rb @@ -63,11 +63,13 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension def url_for(path_or_resource, options={}) 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) result @@ -76,8 +78,13 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension href end - options[:relative] = should_relativize - super(final_path, options) + opts[:relative] = should_relativize + + begin + super(final_path, opts) + rescue RuntimeError + super(path_or_resource, options) + end end end