forked from aws/aws-sdk-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs.rake
78 lines (68 loc) · 2.16 KB
/
docs.rake
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
desc 'Delete the locally generated docs' if ENV['ALL']
task 'docs:clobber' do
rm_rf '.yardoc'
rm_rf 'api-docs'
rm_rf 'api-docs.zip'
end
# Updates the list of supported services and versions in the README
desc 'Updated the list of supported services in the README' if ENV['ALL']
task 'docs:update_readme' do
# Updates the table of supported services / api version in the README
Aws.load_all_services
lines = []
skip = false
File.read('README.md').lines.each do |line|
if line == "## Supported Services\n"
lines << line
lines += supported_services_table
skip = true
elsif line == "## License\n"
skip = false
end
lines << line unless skip
end
File.open('README.md', 'w') { |file| file.write(lines.join) }
sh('git add README.md')
end
desc 'Generates api-docs.zip'
task 'docs:zip' => 'docs' do
sh('zip -9 -r -q api-docs.zip api-docs/')
end
desc 'Generate the API documentation.'
task 'docs' => ['docs:clobber', 'docs:update_readme'] do
env = {}
env['SOURCE'] = '1'
env['SITEMAP_BASEURL'] = 'http://docs.aws.amazon.com/sdkforruby/api/'
sh(env, 'bundle exec yard')
end
# Generates an HTML table of supported services that is used by README.md
def supported_services_table
# insert one row for each supported service
table = []
Aws::SERVICE_MODULE_NAMES.each do |svc_name|
client_class = Aws.const_get(svc_name).const_get(:Client)
full_name = client_class.api.metadata('serviceFullName')
version = client_class.api.version
table << [full_name, svc_name, version]
end
table = table.sort_by(&:first)
# header row
table.unshift(['Service Name', 'Service Class', 'API Version'])
# compute the width of each column by scanning for longest values
column_width = lambda do |col|
table.map { |row| row[col].size }.max
end
widths = [
column_width.call(0),
column_width.call(1),
column_width.call(2),
]
# insert a dashed line after the header row
table = [
table[0],
['-' * widths[0], '-' * widths[1], '-' * widths[2]]
] + table[1..-1]
# build the final table
line = "| #{widths.map{|n| "%-#{n}s" }.join(' | ')} |\n"
["\n"] + table.map { |row| line % row } + ["\n"]
end