Merge remote-tracking branch 'upstream/master'
[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")
33     Dir.mkdir("sdk/R/arvados")
34     docfiles = []
35     Dir.chdir("../sdk/R/") do
36       STDERR.puts `Rscript createDoc.R README.Rmd #{tgt}/sdk/R/README.md 2>&1`
37       Dir.entries("man").each do |rd|
38         if rd[-3..-1] == ".Rd"
39           htmlfile = "#{rd[0..-4]}.html"
40           `R CMD Rdconv -t html man/#{rd} > #{tgt}/sdk/R/arvados/#{htmlfile}`
41           docfiles << htmlfile
42         end
43       end
44     end
45     raise if $? != 0
46
47     File.open("sdk/R/README.md", "r") do |rd|
48     File.open("sdk/R/index.html.md", "w") do |fn|
49       fn.write(<<-EOF
50 ---
51 layout: default
52 navsection: sdk
53 navmenu: R
54 title: "R SDK Overview"
55 ...
56
57 #{rd.read.gsub("```", "\n~~~\n").gsub(/^[ ]+/, "")}
58 EOF
59               )
60       end
61     end
62
63     File.open("sdk/R/arvados/index.html.textile.liquid", "w") do |fn|
64       fn.write(<<-EOF
65 ---
66 layout: default
67 navsection: sdk
68 navmenu: R
69 title: "R Reference"
70 ...
71 {% comment %}
72 Copyright (C) The Arvados Authors. All rights reserved.
73
74 SPDX-License-Identifier: CC-BY-SA-3.0
75 {% endcomment %}
76
77 EOF
78               )
79
80       docfiles.sort.each do |d|
81         fn.write("* \"#{d[0..-6]}\":#{d}\n")
82       end
83
84     end
85   else
86     puts "Warning: R not found, R documentation will not be generated".colorize(:light_red)
87   end
88 end
89
90 task :linkchecker => [ :generate ] do
91   Dir.chdir(".site") do
92     `which linkchecker`
93     if $? == 0
94       system "linkchecker index.html --ignore-url='!file://'" or exit $?.exitstatus
95     else
96       puts "Warning: linkchecker not found, skipping run".colorize(:light_red)
97     end
98   end
99 end
100
101 task :clean do
102   rm_rf "sdk/python/arvados"
103   rm_rf "sdk/R"
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