-
Notifications
You must be signed in to change notification settings - Fork 19
/
Rakefile
143 lines (110 loc) · 4.18 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require 'pathname'
BASE_PATH = Pathname(IO.readlines('./BASE_PATH').first.chomp)
RAILS_PATH = BASE_PATH + 'rails'
GUIDES_PATH = BASE_PATH + 'guides'
PAGES_PATH = BASE_PATH + 'docrails-tw.github.io'
RAILS_GUIDE_SOURCE_PATH = RAILS_PATH + 'guides/source/'
def update_rails_repo!
FileUtils.cd(RAILS_PATH.expand_path) { `git pull origin master` }
end
def get_rails_latest_sha1
sha1 = nil
FileUtils.cd(RAILS_PATH.expand_path) { sha1 = `git rev-parse HEAD` }
sha1[0, 7]
end
task :sanity_checks do
abort("Abort. please clone the rails/rails repo under #{BASE_PATH}") if !File.exist? RAILS_PATH.expand_path
abort("Abort. please clone the docrails-tw/guides repo under #{BASE_PATH}") if !File.exist? GUIDES_PATH.expand_path
abort("Abort. please clone the docrails-tw/docrails-tw.github.io repo under #{BASE_PATH}") if !File.exist? PAGES_PATH.expand_path
end
namespace :guides do
desc 'Generate guides (for authors), use ONLY=foo to process just "foo.md"'
task :generate => 'generate:html'
desc 'Deploy generated guides to github pages repository'
task :deploy => :sanity_checks do
ENV['RAILS_VERSION'] = get_rails_latest_sha1
ENV['ALL'] = '1'
ENV['GUIDES_LANGUAGE'] = 'zh-TW'
Rake::Task['guides:generate:html'].invoke
# the dot will copy contents under a folder, instead of copy the folder.
FileUtils.cp_r("#{GUIDES_PATH.expand_path}/output/zh-TW/.", PAGES_PATH.expand_path)
Dir.chdir(PAGES_PATH.expand_path) do
`git add -A .`
`git commit -m '#{%Q[Site updated @ #{Time.now.strftime("%a %b %-d %H:%M:%S %Z %Y")}]}'`
`git push origin master`
end
puts 'Deploy Complete. : )'
end
desc 'Update a given English guide'
task :update_guide => :sanity_checks do
update_rails_repo!
guide_to_be_updated = ARGV.last
guide_path = (RAILS_GUIDE_SOURCE_PATH + guide_to_be_updated).expand_path
if File.exist? guide_path
FileUtils.cp(guide_path, "#{GUIDES_PATH.expand_path}/source/")
puts "Update: #{guide_path} Complete. : )"
else
`ls #{guide_path}`
end
# trick rake that ARGV.last is a task :P
task guide_to_be_updated.to_sym do; end
end
desc 'Update all English guides'
task :update_guides => :sanity_checks do
update_rails_repo!
FileUtils.cp_r(Pathname.glob("#{RAILS_GUIDE_SOURCE_PATH.expand_path}/*.md"), "#{GUIDES_PATH.expand_path}/source")
puts 'Update all English Guides. : D'
end
namespace :generate do
desc "Generate HTML guides"
task :html do
ENV["WARN_BROKEN_LINKS"] = "1" # authors can't disable this
ruby "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/kindlepublishing"
task :kindle do
unless `kindlerb -v 2> /dev/null` =~ /kindlerb 0.1.1/
abort "Please `gem install kindlerb` and make sure you have `kindlegen` in your PATH"
end
unless `convert` =~ /convert/
abort "Please install ImageMagick`"
end
ENV['KINDLE'] = '1'
Rake::Task['guides:generate:html'].invoke
end
end
desc "Show help"
task :help do
puts <<-help
Guides are taken from the source directory, and the resulting HTML goes into the
output directory. Assets are stored under files, and copied to output/files as
part of the generation process.
All this process is handled via rake tasks, here's a full list of them:
#{%x[rake -T]}
Some arguments may be passed via environment variables:
WARNINGS=1
Internal links (anchors) are checked, also detects duplicated IDs.
ALL=1
Force generation of all guides.
ONLY=name
Useful if you want to generate only one or a set of guides.
Generate only association_basics.html:
ONLY=assoc
Separate many using commas:
ONLY=assoc,migrations
GUIDES_LANGUAGE
Use it when you want to generate translated guides in
source/<GUIDES_LANGUAGE> folder (such as source/es)
EDGE=1
Indicate generated guides should be marked as edge.
Examples:
$ rake guides:generate ALL=1
$ rake guides:generate EDGE=1
$ rake guides:generate:kindle EDGE=1
$ rake guides:generate GUIDES_LANGUAGE=es
help
end
end
task :default do
Rake::Task['guides:generate'].invoke
end