From 7ea1fe5820300e003e9cd0e505df53613081c44e Mon Sep 17 00:00:00 2001 From: benxao Date: Mon, 27 May 2013 18:40:40 +0700 Subject: [PATCH 1/3] Edit Refinery::Pages::Url::Localised#url disable localised url when ::Refinery::I18n.domain_name_enabled? (domain name based i18n), edit sitemap to take in account localised domains --- core/app/views/refinery/sitemap/index.xml.builder | 9 +++++++-- pages/lib/refinery/pages/url.rb | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/app/views/refinery/sitemap/index.xml.builder b/core/app/views/refinery/sitemap/index.xml.builder index 8ed9abb293..b5176add2b 100644 --- a/core/app/views/refinery/sitemap/index.xml.builder +++ b/core/app/views/refinery/sitemap/index.xml.builder @@ -4,6 +4,11 @@ xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do @locales.each do |locale| ::I18n.locale = locale + # request appropriate host & port depending on i18n mode + localized_domain_name = ::Refinery::I18n.domain_name_for_locale(locale) + host_with_port = (::Refinery::I18n.domain_name_enabled? && localized_domain_name) ? + [localized_domain_name, ":", request.port].join : request.host_with_port + ::Refinery::Page.live.in_menu.includes(:parts).each do |page| # exclude sites that are external to our own domain. page_url = if page.url.is_a?(Hash) @@ -11,9 +16,9 @@ xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do page.url.merge({:only_path => false}) elsif page.url.to_s !~ /^http/ # handle relative link_url addresses. - [request.protocol, request.host_with_port, page.url].join + [request.protocol, host_with_port, page.url].join end - + page_url[:host] = localized_domain_name if (localized_domain_name && page_url.is_a?(Hash)) # Add XML entry only if there is a valid page_url found above. xml.url do xml.loc refinery.url_for(page_url) diff --git a/pages/lib/refinery/pages/url.rb b/pages/lib/refinery/pages/url.rb index 169ded1c03..0131a99b06 100644 --- a/pages/lib/refinery/pages/url.rb +++ b/pages/lib/refinery/pages/url.rb @@ -11,7 +11,8 @@ def url current_url = page.link_url if current_url =~ %r{^/} && - Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale + Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale \ + && !::Refinery::I18n.domain_name_enabled? current_url = "/#{Refinery::I18n.current_frontend_locale}#{current_url}" end From 85901a5413eb9bb1052766154976d53e980c37f4 Mon Sep 17 00:00:00 2001 From: benxao Date: Tue, 28 May 2013 09:33:54 +0700 Subject: [PATCH 2/3] test url localised with i18n domain name enabled --- Gemfile | 3 ++- pages/lib/refinery/pages/url.rb | 2 +- pages/spec/lib/refinery/pages/url_spec.rb | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index d0abf08d55..e2e025fb38 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,8 @@ source 'https://rubygems.org' gemspec # Add i18n support. -gem 'refinerycms-i18n', '~> 2.1.0.dev', :git => 'git://github.com/refinery/refinerycms-i18n.git' +#gem 'refinerycms-i18n', '~> 2.1.0.dev', :git => 'git://github.com/refinery/refinerycms-i18n.git' +gem 'refinerycms-i18n', '~> 2.1.0.dev', :path => '../refinerycms-i18n' # Add support for refinerycms-acts-as-indexed gem 'refinerycms-acts-as-indexed', :git => 'git://github.com/refinery/refinerycms-acts-as-indexed.git' diff --git a/pages/lib/refinery/pages/url.rb b/pages/lib/refinery/pages/url.rb index 0131a99b06..915201cc0a 100644 --- a/pages/lib/refinery/pages/url.rb +++ b/pages/lib/refinery/pages/url.rb @@ -11,7 +11,7 @@ def url current_url = page.link_url if current_url =~ %r{^/} && - Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale \ + (Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale) \ && !::Refinery::I18n.domain_name_enabled? current_url = "/#{Refinery::I18n.current_frontend_locale}#{current_url}" end diff --git a/pages/spec/lib/refinery/pages/url_spec.rb b/pages/spec/lib/refinery/pages/url_spec.rb index 604868fe43..56f40f39c7 100644 --- a/pages/spec/lib/refinery/pages/url_spec.rb +++ b/pages/spec/lib/refinery/pages/url_spec.rb @@ -29,6 +29,24 @@ module Pages Url::Localised.new(page).url.should eq("/test") end end + + context "when current frontend locale != default frontend locale and domain name enabled" do + it "returns unaltered link_url" do + Refinery::I18n.stub(:current_frontend_locale).and_return(:lv) + Refinery::I18n.stub(:default_frontend_locale).and_return(:en) + Refinery::I18n.stub(:domain_name_enabled?).and_return(true) + Url::Localised.new(page).url.should eq("/test") + end + end + + context "when current frontend locale != default frontend locale and domain name disabled" do + it "returns link_url prefixed with current frontend locale" do + Refinery::I18n.stub(:current_frontend_locale).and_return(:lv) + Refinery::I18n.stub(:default_frontend_locale).and_return(:en) + Refinery::I18n.stub(:domain_name_enabled?).and_return(false) + Url::Localised.new(page).url.should eq("/lv/test") + end + end end end From e0971214420baf58d77f4fb46126e432d4f62b08 Mon Sep 17 00:00:00 2001 From: benxao Date: Tue, 28 May 2013 10:11:52 +0700 Subject: [PATCH 3/3] remove changes on Gemfile --- Gemfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index e2e025fb38..d0abf08d55 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,7 @@ source 'https://rubygems.org' gemspec # Add i18n support. -#gem 'refinerycms-i18n', '~> 2.1.0.dev', :git => 'git://github.com/refinery/refinerycms-i18n.git' -gem 'refinerycms-i18n', '~> 2.1.0.dev', :path => '../refinerycms-i18n' +gem 'refinerycms-i18n', '~> 2.1.0.dev', :git => 'git://github.com/refinery/refinerycms-i18n.git' # Add support for refinerycms-acts-as-indexed gem 'refinerycms-acts-as-indexed', :git => 'git://github.com/refinery/refinerycms-acts-as-indexed.git'