21700: Install Bundler system-wide in Rails postinst
[arvados.git] / sdk / ruby-google-api-client / rakelib / wiki.rake
1 require 'rake'
2 require 'rake/clean'
3
4 CLOBBER.include('wiki')
5
6 CACHE_PREFIX =
7   "http://www.gmodules.com/gadgets/proxy/container=default&debug=0&nocache=0/"
8
9 namespace :wiki do
10   desc 'Autogenerate wiki pages'
11   task :supported_apis do
12     output = <<-WIKI
13 #summary The list of supported APIs
14
15 The Google API Client for Ruby is a small flexible client library for accessing
16 the following Google APIs.
17
18 WIKI
19     preferred_apis = {}
20     require 'google/api_client'
21     client = Google::APIClient.new
22     for api in client.discovered_apis
23       if !preferred_apis.has_key?(api.name)
24         preferred_apis[api.name] = api
25       elsif api.preferred
26         preferred_apis[api.name] = api
27       end
28     end
29     for api_name, api in preferred_apis
30       if api.documentation.to_s != "" && api.title != ""
31         output += (
32           "||#{CACHE_PREFIX}#{api['icons']['x16']}||" +
33           "[#{api.documentation} #{api.title}]||" +
34           "#{api.description}||\n"
35         )
36       end
37     end
38     output.gsub!(/-32\./, "-16.")
39     wiki_path = File.expand_path(
40       File.join(File.dirname(__FILE__), '../wiki/'))
41     Dir.mkdir(wiki_path) unless File.exists?(wiki_path)
42     File.open(File.join(wiki_path, 'SupportedAPIs.wiki'), 'w') do |file|
43       file.write(output)
44     end
45   end
46
47   task 'generate' => ['wiki:supported_apis']
48 end
49
50 begin
51   $LOAD_PATH.unshift(
52     File.expand_path(File.join(File.dirname(__FILE__), '../yard/lib'))
53   )
54   $LOAD_PATH.unshift(File.expand_path('.'))
55   $LOAD_PATH.uniq!
56
57   require 'yard'
58   require 'yard/rake/wikidoc_task'
59
60   namespace :wiki do
61     desc 'Generate Wiki Documentation with YARD'
62     YARD::Rake::WikidocTask.new do |yardoc|
63       yardoc.name = 'reference'
64       yardoc.options = [
65         '--verbose',
66         '--markup', 'markdown',
67         '-e', 'yard/lib/yard-google-code.rb',
68         '-p', 'yard/templates',
69         '-f', 'wiki',
70         '-o', 'wiki'
71       ]
72       yardoc.files = [
73         'lib/**/*.rb', 'ext/**/*.c', '-', 'README.md', 'CHANGELOG.md'
74       ]
75     end
76
77     task 'generate' => ['wiki:reference', 'wiki:supported_apis']
78   end
79 rescue LoadError
80   # If yard isn't available, it's not the end of the world
81   warn('YARD unavailable. Cannot fully generate wiki.')
82 end