-
Notifications
You must be signed in to change notification settings - Fork 189
/
Rakefile
141 lines (108 loc) · 3.28 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
gem "rdoc"
require 'rdoc/rdoc'
require 'rdoc/task'
require 'fileutils'
require_relative 'lib/options_list_markdownizer'
$:.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)
OptionsListMarkdownizer.new.call command
end
filename = "command-reference.erb"
erbio = ERB.new File.read(filename), trim_mode: '-'
content = erbio.result(binding).gsub(ENV["HOME"], "~")
File.write 'command-reference.md', content
end
desc "serve documentation on http://localhost:4000"
task :server do
pids = [
spawn('jekyll', 'serve', '4000'),
spawn('sass', '--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]