Skip to content

Commit f148093

Browse files
authored
Merge pull request #85 from AndorChen/kindle
Update kindle task per new version
2 parents e7b49e8 + c037284 commit f148093

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

Rakefile

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
11
namespace :guides do
2-
32
desc 'Generate guides (for authors), use ONLY=foo to process just "foo.md"'
4-
task :generate => 'generate:html'
3+
task generate: "generate:html"
4+
5+
# Guides are written in UTF-8, but the environment may be configured for some
6+
# other locale, these tasks are responsible for ensuring the default external
7+
# encoding is UTF-8.
8+
#
9+
# Real use cases: Generation was reported to fail on a machine configured with
10+
# GBK (Chinese). The docs server once got misconfigured somehow and had "C",
11+
# which broke generation too.
12+
task :encoding do
13+
%w(LANG LANGUAGE LC_ALL).each do |env_var|
14+
ENV[env_var] = "en_US.UTF-8"
15+
end
16+
end
517

618
namespace :generate do
7-
819
desc "Generate HTML guides"
9-
task :html do
20+
task html: :encoding do
1021
ENV["WARNINGS"] = "1" # authors can't disable this
1122
ruby "rails_guides.rb"
1223
end
1324

1425
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"
15-
task :kindle do
16-
unless `kindlerb -v 2> /dev/null` =~ /kindlerb 0.1.1/
17-
abort "Please `gem install kindlerb` and make sure you have `kindlegen` in your PATH"
26+
task kindle: :encoding do
27+
require "kindlerb"
28+
unless Kindlerb.kindlegen_available?
29+
abort "Please run `setupkindlerb` to install kindlegen"
1830
end
19-
unless `convert` =~ /convert/
20-
abort "Please install ImageMagick`"
31+
unless `convert` =~ /convert/
32+
abort "Please install ImageMagick"
2133
end
22-
ENV['KINDLE'] = '1'
23-
Rake::Task['guides:generate:html'].invoke
34+
ENV["KINDLE"] = "1"
35+
Rake::Task["guides:generate:html"].invoke
2436
end
2537
end
2638

2739
# Validate guides -------------------------------------------------------------------------
2840
desc 'Validate guides, use ONLY=foo to process just "foo.html"'
29-
task :validate do
41+
task validate: :encoding do
3042
ruby "w3c_validator.rb"
3143
end
3244

3345
desc "Show help"
3446
task :help do
35-
puts <<-help
47+
puts <<HELP
3648
3749
Guides are taken from the source directory, and the result goes into the
3850
output directory. Assets are stored under files, and copied to output/files as
@@ -45,8 +57,9 @@ All of these processes are handled via rake tasks, here's a full list of them:
4557
#{%x[rake -T]}
4658
Some arguments may be passed via environment variables:
4759
48-
WARNINGS=1
49-
Internal links (anchors) are checked, also detects duplicated IDs.
60+
RAILS_VERSION=tag
61+
If guides are being generated for a specific Rails version set the Git tag
62+
here, otherwise the current SHA1 is going to be used to generate edge guides.
5063
5164
ALL=1
5265
Force generation of all guides.
@@ -64,16 +77,13 @@ Some arguments may be passed via environment variables:
6477
Use it when you want to generate translated guides in
6578
source/<GUIDES_LANGUAGE> folder (such as source/es)
6679
67-
EDGE=1
68-
Indicate generated guides should be marked as edge.
69-
7080
Examples:
71-
$ rake guides:generate ALL=1
72-
$ rake guides:generate EDGE=1
73-
$ rake guides:generate:kindle EDGE=1
81+
$ rake guides:generate ALL=1 RAILS_VERSION=v5.1.0
82+
$ rake guides:generate ONLY=migrations
83+
$ rake guides:generate:kindle
7484
$ rake guides:generate GUIDES_LANGUAGE=es
75-
help
85+
HELP
7686
end
7787
end
7888

79-
task :default => 'guides:help'
89+
task default: "guides:help"

0 commit comments

Comments
 (0)