From efc82d6fbf2e937cbb1547592d1cedb32ca6d41c Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Sun, 4 Feb 2018 22:37:17 +0900 Subject: [PATCH 1/2] Fix error invalid byte sequence without en_US.UTF-8 locale Because Ruby does not set `Encoding.default_external` with non-existent locale such as `en_US.UTF-8`. Original code expects that `en_US.UTF-8` is available locale implicitly. However, it shouldn't be assumed. In this case, we can use `-Eutf-8:utf-8` to specify external encoding and internal encoding. --- guides/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/Rakefile b/guides/Rakefile index 84e18e0972..1c14560c68 100644 --- a/guides/Rakefile +++ b/guides/Rakefile @@ -21,7 +21,7 @@ namespace :guides do desc "Generate HTML guides" task html: :encoding do ENV["WARNINGS"] = "1" # authors can't disable this - ruby "rails_guides.rb" + ruby "-Eutf-8:utf-8", "rails_guides.rb" end desc "Generate .mobi file. The kindlegen executable must be in your PATH. You can get it for free from http://www.amazon.com/gp/feature.html?docId=1000765211" From 510db97991719aa2b4a7af181886a6e657a3c368 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Sun, 4 Feb 2018 22:49:22 +0900 Subject: [PATCH 2/2] Remove code that is no longer effective In previous change, we set external encoding and internal encoding explicitly. So we can remove the code that set environment variables `LANG, LANGUAGE, LC_ALL`. --- guides/Rakefile | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/guides/Rakefile b/guides/Rakefile index 1c14560c68..28b50fe93c 100644 --- a/guides/Rakefile +++ b/guides/Rakefile @@ -4,28 +4,15 @@ namespace :guides do desc 'Generate guides (for authors), use ONLY=foo to process just "foo.md"' task generate: "generate:html" - # Guides are written in UTF-8, but the environment may be configured for some - # other locale, these tasks are responsible for ensuring the default external - # encoding is UTF-8. - # - # Real use cases: Generation was reported to fail on a machine configured with - # GBK (Chinese). The docs server once got misconfigured somehow and had "C", - # which broke generation too. - task :encoding do - %w(LANG LANGUAGE LC_ALL).each do |env_var| - ENV[env_var] = "en_US.UTF-8" - end - end - namespace :generate do desc "Generate HTML guides" - task html: :encoding do + task :html do ENV["WARNINGS"] = "1" # authors can't disable this ruby "-Eutf-8:utf-8", "rails_guides.rb" end desc "Generate .mobi file. The kindlegen executable must be in your PATH. You can get it for free from http://www.amazon.com/gp/feature.html?docId=1000765211" - task kindle: :encoding do + task :kindle do require "kindlerb" unless Kindlerb.kindlegen_available? abort "Please run `setupkindlerb` to install kindlegen"