forked from rubygems/guides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
171 lines (137 loc) · 4.19 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
gem "rdoc"
require 'rdoc/rdoc'
require 'rdoc/task'
require 'fileutils'
$:.unshift '.', '../rubygems/lib'
ENV['RUBYGEMS_DIR'] ||= File.expand_path '../../rubygems', __FILE__
task :RUBYGEMS_DIR_exists do
message = <<-NO_RUBYGEMS_DIR
The Rubygems rdocs are required to build the spec guide.
Install or clone it from GitHub, then:
RUBYGEMS_DIR=/path/to/rubygems/source rake spec_guide --trace
The RUBYGEMS_DIR is assumed to exist at:
#{ENV['RUBYGEMS_DIR']}
NO_RUBYGEMS_DIR
abort message unless File.exist? ENV['RUBYGEMS_DIR']
end
# RUBYGEMS_DIR should be checked first
task rdoc_spec: %w[RUBYGEMS_DIR_exists]
RDoc::Task.new(:rdoc_spec) do |rd|
spec_file = File.join(ENV["RUBYGEMS_DIR"].to_s, "lib", "rubygems", "specification.rb")
rd.rdoc_files.include(spec_file)
rd.template = "jekdoc"
rd.options << '--quiet'
end
desc "move spec guide into the right place"
task :move_spec => %w[specification-reference.md]
file 'html/Gem/Specification.html' => %w[rdoc_spec]
file 'specification-reference.md' => %w[html/Gem/Specification.html] do
cp 'html/Gem/Specification.html', 'specification-reference.md'
end
desc "clean up after rdoc"
task :clean do
FileUtils.rm_rf "html"
end
desc "generate specification guide"
task :spec_guide => [:rdoc_spec, :move_spec, :clean]
desc "generate command guide"
task :command_guide => %w[command-reference.md]
command_reference_files = Rake::FileList.new(*%W[
Rakefile
command-reference.erb
#{ENV['RUBYGEMS_DIR']}/lib/rubygems.rb
#{ENV['RUBYGEMS_DIR']}/lib/rubygems/command_manager.rb
#{ENV['RUBYGEMS_DIR']}/lib/rubygems/commands/*.rb
])
file 'command-reference.md' =>
%w[RUBYGEMS_DIR_exists] + command_reference_files do
require 'rubygems/command_manager'
require 'rdoc/erbio'
rubygems_version = Gem.rubygems_version.version
names = Gem::CommandManager.instance.command_names
commands = {}
names.each do |name|
command = Gem::CommandManager.instance[name]
command.options[:help] = ''
commands[name] = command
end
def htmlify(string)
lines = string.split("\n")
html_string = ''
lines.each do |line|
if line
if line =~ /^ /
# This will end up in a <pre> block
html_string += line
else
html_string += line.gsub("<", "<").gsub(">", ">")
end
html_string += "\n"
end
end
html_string[0..-2]
end
def argument_list_item(string)
if string =~ /^(\S+)(.*)/
string = "*#{$1}* - #{$2}"
end
htmlify("* #{string}")
end
def options_list(command)
ui = Gem::SilentUI.new
Gem::DefaultUserInteraction.use_ui ui do
# Invoke the Ruby options parser by asking for help. Otherwise the
# options list in the parser will never be initialized.
command.show_help
end
parser = command.send(:parser)
options = ''
helplines = parser.summarize
helplines.each do |helpline|
break if (helpline =~ /Arguments/) || (helpline =~ /Summary/)
unless helpline.gsub(/\n/, '').strip == ''
# Use zero-width space to prevent "helpful" change of -- to –
helpline = helpline.gsub('--', '-​-').gsub('[', '\\[').gsub(']', '\\]')
if helpline =~ /^\s{10,}(.*)/
options = options[0..-2] + " #{$1}\n"
else
if helpline =~ /^(.*)\s{3,}(.*)/
helpline = "#{$1} - #{$2}"
end
if helpline =~ /options/i
options += "\n### #{helpline}\n"
else
options += "* #{helpline}\n"
end
end
end
end
options
end
filename = "command-reference.erb"
erbio = RDoc::ERBIO.new File.read(filename), nil, nil
erbio.filename = filename
open 'command-reference.md', 'w' do |io|
erbio.result binding
end
end
desc "serve documentation on http://localhost:4000"
task :server do
pids = [
spawn('jekyll', 'serve', '4000'),
spawn('scss', '--watch', 'stylesheets:stylesheets'),
]
trap "INT" do
Process.kill "INT", *pids
exit 1
end
trap "TERM" do
Process.kill "TERM", *pids
exit 1
end
pids.each do |pid|
Process.waitpid pid
end
end
desc 'build documentation and display it on http://localhost:4000'
task default: %w[spec_guide command_guide server]