13076: R SDK online docs include both README and method docs.
[arvados.git] / doc / Rakefile
1 #!/usr/bin/env rake
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: CC-BY-SA-3.0
5
6 require "rubygems"
7 require "colorize"
8
9 task :generate => [ :realclean, 'sdk/python/arvados/index.html', 'sdk/R/arvados/index.html' ] do
10   vars = ['baseurl', 'arvados_api_host', 'arvados_workbench_host']
11   vars.each do |v|
12     if ENV[v]
13       website.config.h[v] = ENV[v]
14     end
15   end
16 end
17
18 file "sdk/python/arvados/index.html" do |t|
19   `which epydoc`
20   if $? == 0
21     STDERR.puts `epydoc --html --parse-only -o sdk/python/arvados ../sdk/python/arvados/ 2>&1`
22     raise if $? != 0
23   else
24     puts "Warning: epydoc not found, Python documentation will not be generated".colorize(:light_red)
25   end
26 end
27
28 file "sdk/R/arvados/index.html" do |t|
29   `which R`
30   if $? == 0
31     tgt = Dir.pwd
32     Dir.mkdir("sdk/R/arvados")
33     docfiles = []
34     Dir.chdir("../sdk/R/") do
35       STDERR.puts `Rscript createDoc.R README.Rmd #{tgt}/sdk/R/README.md 2>&1`
36       Dir.entries("man").each do |rd|
37         if rd[-3..-1] == ".Rd"
38           htmlfile = "#{rd[0..-4]}.html"
39           `R CMD Rdconv -t html man/#{rd} > #{tgt}/sdk/R/arvados/#{htmlfile}`
40           docfiles << htmlfile
41         end
42       end
43     end
44     raise if $? != 0
45
46     File.open("sdk/R/README.md", "r") do |rd|
47     File.open("sdk/R/index.html.md", "w") do |fn|
48       fn.write(<<-EOF
49 ---
50 layout: default
51 navsection: sdk
52 navmenu: R
53 title: "R SDK Overview"
54 ...
55
56 #{rd.read.gsub("```", "\n~~~\n").gsub(/^[ ]+/, "")}
57 EOF
58               )
59       end
60     end
61
62     File.open("sdk/R/arvados/index.html.textile.liquid", "w") do |fn|
63       fn.write(<<-EOF
64 ---
65 layout: default
66 navsection: sdk
67 navmenu: R
68 title: "R Reference"
69 ...
70 {% comment %}
71 Copyright (C) The Arvados Authors. All rights reserved.
72
73 SPDX-License-Identifier: CC-BY-SA-3.0
74 {% endcomment %}
75
76 EOF
77               )
78
79       docfiles.sort.each do |d|
80         fn.write("* \"#{d[0..-6]}\":#{d}\n")
81       end
82
83     end
84   else
85     puts "Warning: R not found, R documentation will not be generated".colorize(:light_red)
86   end
87 end
88
89 task :linkchecker => [ :generate ] do
90   Dir.chdir(".site") do
91     `which linkchecker`
92     if $? == 0
93       system "linkchecker index.html --ignore-url='!file://'" or exit $?.exitstatus
94     else
95       puts "Warning: linkchecker not found, skipping run".colorize(:light_red)
96     end
97   end
98 end
99
100 task :clean do
101   rm_rf "sdk/python/arvados"
102   rm_rf "sdk/R/arvados"
103   rm_rf "../sdk/R/docs"
104 end
105
106 require "zenweb/tasks"
107 load "zenweb-textile.rb"
108 load "zenweb-liquid.rb"
109
110 task :extra_wirings do
111   $website.pages["sdk/python/python.html.textile.liquid"].depends_on("sdk/python/arvados/index.html")
112 end