|
1 |
| -require 'pathname' |
2 |
| - |
3 |
| -BASE_PATH = Pathname(IO.readlines('./BASE_PATH').first.chomp) |
4 |
| - |
5 |
| -RAILS_PATH = BASE_PATH + 'rails' |
6 |
| -GUIDES_PATH = BASE_PATH + 'guides' |
7 |
| -PAGES_PATH = BASE_PATH + 'ruby-china.github.io' |
8 |
| - |
9 |
| -RAILS_GUIDE_SOURCE_PATH = RAILS_PATH + 'guides/source/' |
10 |
| - |
11 |
| -def update_rails_repo! |
12 |
| - FileUtils.cd(RAILS_PATH.expand_path) { `git pull origin master` } |
13 |
| -end |
14 |
| - |
15 |
| -def get_rails_latest_sha1 |
16 |
| - sha1 = nil |
17 |
| - FileUtils.cd(RAILS_PATH.expand_path) { sha1 = `git rev-parse HEAD` } |
18 |
| - sha1[0, 7] |
19 |
| -end |
20 |
| - |
21 |
| -task :sanity_checks do |
22 |
| - abort("Abort. please clone the rails/rails repo under #{BASE_PATH}") if !File.exist? RAILS_PATH.expand_path |
23 |
| - abort("Abort. please clone the ruby-china/guides repo under #{BASE_PATH}") if !File.exist? GUIDES_PATH.expand_path |
24 |
| -end |
25 |
| - |
26 | 1 | namespace :guides do
|
| 2 | + |
27 | 3 | desc 'Generate guides (for authors), use ONLY=foo to process just "foo.md"'
|
28 | 4 | task :generate => 'generate:html'
|
29 | 5 |
|
30 |
| - desc 'Deploy generated guides to github pages repository' |
31 |
| - task :deploy => :sanity_checks do |
32 |
| - ENV['RAILS_VERSION'] = get_rails_latest_sha1 |
33 |
| - ENV['ALL'] = '1' |
34 |
| - ENV['GUIDES_LANGUAGE'] = 'zh-CN' |
35 |
| - Rake::Task['guides:generate:html'].invoke |
36 |
| - |
37 |
| - # the dot will copy contents under a folder, instead of copy the folder. |
38 |
| - FileUtils.cp_r("#{GUIDES_PATH.expand_path}/output/zh-CN/.", PAGES_PATH.expand_path) |
| 6 | + namespace :generate do |
39 | 7 |
|
40 |
| - Dir.chdir(PAGES_PATH.expand_path) do |
41 |
| - `git add -A .` |
42 |
| - `git commit -m '#{%Q[Site updated @ #{Time.now.strftime("%a %b %-d %H:%M:%S %Z %Y")}]}'` |
43 |
| - `git push origin master` |
| 8 | + desc "Generate HTML guides" |
| 9 | + task :html do |
| 10 | + ENV["WARNINGS"] = "1" # authors can't disable this |
| 11 | + ruby "rails_guides.rb" |
44 | 12 | end
|
45 | 13 |
|
46 |
| - puts 'Deploy Complete. : )' |
47 |
| - end |
48 |
| - |
49 |
| - desc 'Update a given English guide' |
50 |
| - task :update_guide => :sanity_checks do |
51 |
| - update_rails_repo! |
52 |
| - |
53 |
| - guide_to_be_updated = ARGV.last |
54 |
| - guide_path = (RAILS_GUIDE_SOURCE_PATH + guide_to_be_updated).expand_path |
55 |
| - |
56 |
| - if File.exist? guide_path |
57 |
| - FileUtils.cp(guide_path, "#{GUIDES_PATH.expand_path}/source/") |
58 |
| - puts "Update: #{guide_path} Complete. : )" |
59 |
| - else |
60 |
| - `ls #{guide_path}` |
| 14 | + 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" |
| 18 | + end |
| 19 | + unless `convert` =~ /convert/ |
| 20 | + abort "Please install ImageMagick`" |
| 21 | + end |
| 22 | + ENV['KINDLE'] = '1' |
| 23 | + Rake::Task['guides:generate:html'].invoke |
61 | 24 | end
|
62 |
| - |
63 |
| - # trick rake that ARGV.last is a task :P |
64 |
| - task guide_to_be_updated.to_sym do; end |
65 |
| - end |
66 |
| - |
67 |
| - desc 'Update all English guides' |
68 |
| - task :update_guides => :sanity_checks do |
69 |
| - update_rails_repo! |
70 |
| - |
71 |
| - FileUtils.cp_r(Pathname.glob("#{RAILS_GUIDE_SOURCE_PATH.expand_path}/*.md"), "#{GUIDES_PATH.expand_path}/source") |
72 |
| - |
73 |
| - puts 'Update all English Guides. : D' |
74 | 25 | end
|
75 | 26 |
|
76 |
| - namespace :generate do |
77 |
| - desc "Generate HTML guides" |
78 |
| - task :html do |
79 |
| - ENV["WARN_BROKEN_LINKS"] = "1" # authors can't disable this |
80 |
| - ruby "rails_guides.rb" |
81 |
| - end |
| 27 | + # Validate guides ------------------------------------------------------------------------- |
| 28 | + desc 'Validate guides, use ONLY=foo to process just "foo.html"' |
| 29 | + task :validate do |
| 30 | + ruby "w3c_validator.rb" |
82 | 31 | end
|
83 | 32 |
|
84 | 33 | desc "Show help"
|
85 | 34 | task :help do
|
86 | 35 | puts <<-help
|
87 | 36 |
|
88 |
| -Guides are taken from the source directory, and the resulting HTML goes into the |
| 37 | +Guides are taken from the source directory, and the result goes into the |
89 | 38 | output directory. Assets are stored under files, and copied to output/files as
|
90 | 39 | part of the generation process.
|
91 | 40 |
|
92 |
| -All this process is handled via rake tasks, here's a full list of them: |
| 41 | +You can generate HTML, Kindle or both formats using the `guides:generate` task. |
| 42 | +
|
| 43 | +All of these processes are handled via rake tasks, here's a full list of them: |
93 | 44 |
|
94 | 45 | #{%x[rake -T]}
|
95 | 46 | Some arguments may be passed via environment variables:
|
@@ -125,6 +76,4 @@ Examples:
|
125 | 76 | end
|
126 | 77 | end
|
127 | 78 |
|
128 |
| -task :default do |
129 |
| - Rake::Task['guides:generate'].invoke |
130 |
| -end |
| 79 | +task :default => 'guides:help' |
0 commit comments