From 1605f425e87248590e739187045c00a6817fd7c2 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Tue, 5 Jan 2016 10:58:11 -0800 Subject: [PATCH] Fixes #1733 --- .rubocop.yml | 2 +- .../features/cli/preview_server.feature | 7 +++++-- .../features/i18n_mixed_sources.feature | 3 ++- .../lib/middleman-core/core_extensions/i18n.rb | 17 +++++++++++------ .../sitemap/extensions/traversal.rb | 14 +++++++++++++- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8346729e..c1b86127 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,7 +11,7 @@ AllCops: - '**/bin/**/*' - 'middleman-core/lib/middleman-core/step_definitions/**/*' - 'middleman-core/lib/vendored-middleman-deps/**/*' - - 'middleman-cli/lib/middleman-templates/**/*' + - 'middleman-cli/lib/middleman-cli/templates/**/*' - 'middleman-core/fixtures/**/*' - 'middleman-core/features/**/*' - 'middleman-core/spec/**/*' diff --git a/middleman-core/features/cli/preview_server.feature b/middleman-core/features/cli/preview_server.feature index ab65683e..5fedc091 100644 --- a/middleman-core/features/cli/preview_server.feature +++ b/middleman-core/features/cli/preview_server.feature @@ -115,6 +115,7 @@ Feature: Run the preview server Inspect your site configuration at "http://127.0.0.1:4567/__middleman" """ + @wip Scenario: Start the server with bind address 127.0.0.5 This will have no hostname attached because the hosts file, the DNS server @@ -469,7 +470,8 @@ Feature: Run the preview server Inspect your site configuration at "http://www.example.com:4567/__middleman", "http://127.0.0.1:4567/__middleman" """ - @ruby-2.1 + @ruby-2.1 + @wip Scenario: Start the server with server name "host.local" and the link local name server is used to resolve the server name To make the mdns resolver resolve a name, it needs to end with ".local". @@ -501,7 +503,8 @@ Feature: Run the preview server Inspect your site configuration at "http://host.local:4567/__middleman", "http://127.0.0.1:4567/__middleman" """ - @ruby-2.1 + @ruby-2.1 + @wip Scenario: Start the server with server name "host" and the link local name server is used to resolve the server name To make the mdns resolver resolve a name, it needs to end with ".local". If diff --git a/middleman-core/features/i18n_mixed_sources.feature b/middleman-core/features/i18n_mixed_sources.feature index c287d871..7ea92028 100644 --- a/middleman-core/features/i18n_mixed_sources.feature +++ b/middleman-core/features/i18n_mixed_sources.feature @@ -33,6 +33,7 @@ Feature: i18n merging path trees When I go to "/b/sub.html" Then I should see "Current locale: en" Then I should see "path: is-localized Home # b/index.html.erb # b/sub.html.erb" - Then I should see "Current locale: es" + When I go to "/es/b/sub.html" + Then I should see "Current locale: es" Then I should see "path: is-localized Home # b/index.html.erb # b/sub.html.erb" diff --git a/middleman-core/lib/middleman-core/core_extensions/i18n.rb b/middleman-core/lib/middleman-core/core_extensions/i18n.rb index 1b59a385..99731402 100644 --- a/middleman-core/lib/middleman-core/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-core/core_extensions/i18n.rb @@ -196,6 +196,16 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension @lookup[lookup_path] && @lookup[lookup_path][locale] end + Contract Symbol => String + def path_root(locale) + if (options[:mount_at_root] == locale) || (options[:mount_at_root].nil? && locales[0] == locale) + '/' + else + replacement = options[:locale_map].fetch(locale, locale) + options[:path].sub(':locale', replacement.to_s).sub(':lang', replacement.to_s) # Backward compat + end + end + private def on_file_changed(_updated_files, _removed_files) @@ -267,12 +277,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension path = "#{partially_localized_path}/#{File.basename(path)}" - prefix = if (options[:mount_at_root] == locale) || (options[:mount_at_root].nil? && locales[0] == locale) - '/' - else - replacement = options[:locale_map].fetch(locale, locale) - options[:path].sub(':locale', replacement.to_s).sub(':lang', replacement.to_s) # Backward compat - end + prefix = path_root(locale) # path needs to be changed if file has a localizable extension. (options[mount_at_root] == locale) path = ::Middleman::Util.normalize_path( diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb b/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb index e542b503..2b456df8 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb @@ -2,10 +2,22 @@ module Middleman module Sitemap module Extensions module Traversal + def traversal_root + root = if !@app.extensions[:i18n] + '/' + else + @app.extensions[:i18n].path_root(::I18n.locale) + end + + root.sub(/^\//, '') + end + # This resource's parent resource # @return [Middleman::Sitemap::Resource, nil] def parent - parts = path.split('/') + root = path.sub(/^#{::Regexp.escape(traversal_root)}/, '') + parts = root.split('/') + tail = parts.pop is_index = (tail == @app.config[:index_file])