Skip to content

Commit 323ba8f

Browse files
authored
Merge pull request xapi-project#3145 from kc284/master
Added option to generate the api reference in docbook format and prov…
2 parents 04f47f8 + 5d3b955 commit 323ba8f

File tree

7 files changed

+100
-32
lines changed

7 files changed

+100
-32
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build: setup.data
1313
doc: setup.data build
1414
$(SETUP) -doc $(DOCFLAGS)
1515
./jsapi.native -destdir _build/ocaml/doc -templdir ocaml/doc/templates
16-
./datamodel_main.native -closed -markdown _build/ocaml/doc/markdown
16+
./datamodel_main.native -closed -markdown -templdir ocaml/doc/templates _build/ocaml/doc/markdown
1717
cp ocaml/doc/*.dot ocaml/doc/*.md ocaml/doc/doc-convert.sh _build/ocaml/doc/markdown
1818

1919
test: setup.data build

_oasis

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ Executable datamodel_main
433433
Install: false
434434
MainIs: datamodel_main.ml
435435
BuildDepends:
436-
xapi-datamodel
436+
xapi-datamodel,
437+
mustache
437438

438439

439440
############################################################################

ocaml/doc/doc-convert.sh

100644100755
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,48 @@ GRAPHVIZ_FLAGS="-Tpng"
77
dot vm-lifecycle.dot ${GRAPHVIZ_FLAGS} -o vm-lifecycle.png
88
dot classes.dot ${GRAPHVIZ_FLAGS} -o classes.png
99

10-
if [ ! "$1" = "--pdf" ]; then
10+
usage() {
11+
echo "Usage:"
12+
echo " sh $0 [--pdf|--docbook]"
13+
}
14+
15+
if [ "$#" -lt 1 ]; then
1116
exit 0
17+
elif [ "$#" -gt 1 ]; then
18+
usage
19+
exit 1
1220
fi
1321

22+
OUTNAME=xenserver-management-api-guide
23+
1424
FILES="
1525
basics.md
1626
wire-protocol.md
1727
vm-lifecycle.md
1828
api-ref-autogen.md
19-
cover.yaml
2029
"
2130

22-
PANDOC_FLAGS="
31+
PDF_FLAGS="
2332
--latex-engine=pdflatex
2433
--number-sections
2534
--chapters
35+
--output=${OUTNAME}.pdf
36+
"
37+
38+
DB_FLAGS="
39+
--to=docbook
40+
--output=${OUTNAME}.db
41+
--template=template.db
2642
"
2743

28-
pandoc ${FILES} ${PANDOC_FLAGS} -o xenserver-management-api-guide.pdf
44+
case "$1" in
45+
--pdf)
46+
pandoc ${FILES} cover.yaml ${PDF_FLAGS}
47+
;;
48+
--docbook)
49+
pandoc ${FILES} ${DB_FLAGS}
50+
;;
51+
*)
52+
usage
53+
exit 1
54+
esac

ocaml/doc/jsapi.ml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,6 @@ let json_releases =
103103
in
104104
`O [ "releases", `A (List.map json_of_rel release_order) ]
105105

106-
let json_current_version =
107-
let time = Unix.gettimeofday () in
108-
let month, year =
109-
match String.split ' ' (Date.rfc822_to_string (Date.rfc822_of_float time)) with
110-
| [ _; _; m; y; _; _ ] -> m,y
111-
| _ -> failwith "Invalid datetime string"
112-
in
113-
`O [
114-
"api_version_major", `Float (Int64.to_float api_version_major);
115-
"api_version_minor", `Float (Int64.to_float api_version_minor);
116-
"current_year", `String year;
117-
"current_month", `String month;
118-
]
119-
120106
let render_template template_file json output_file =
121107
let templ = Stdext.Unixext.string_of_file template_file |> Mustache.of_string in
122108
let rendered = Mustache.render templ json in
@@ -137,11 +123,3 @@ let _ =
137123
(Filename.concat !templdir "branding.mustache")
138124
json_releases
139125
(Filename.concat !destdir "branding.js");
140-
141-
let markdown_dir = Filename.concat !destdir "markdown" in
142-
Stdext.Unixext.mkdir_rec markdown_dir 0o755;
143-
144-
render_template
145-
(Filename.concat !templdir "cover.mustache")
146-
json_current_version
147-
(Filename.concat markdown_dir "cover.yaml")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "../../../tools/docbook-xml/docbookx.dtd"[
3+
<!ENTITY % local SYSTEM "local.ent">
4+
<!ENTITY legal SYSTEM "shared/legal.ent">
5+
<!ENTITY % ISOamsr SYSTEM "../../../tools/docbook-xml/ent/iso-amsr.ent">
6+
<!ENTITY % ISOnum SYSTEM "../../../tools/docbook-xml/ent/iso-num.ent">
7+
8+
%local;
9+
]>
10+
11+
<book lang="en">
12+
<bookinfo id="bookinfo_titlestuff">
13+
<title>&COMPANY_NAME_SHORT; &PRODUCT_BRAND; <trademark class="registered" role="die"/>
14+
Management API
15+
</title>
16+
<subtitle>API Revision {{api_version_major}}.{{api_version_minor}}</subtitle>
17+
<pubdate><?dbtimestamp format="B Y"?></pubdate>
18+
<productnumber>&PRODUCT_VERSION;</productnumber>
19+
<edition>1.0</edition>
20+
<pubsnumber>&PRODUCT_BRAND;-&PRODUCT_VERSION;-&BUILD_NUMBER;</pubsnumber>
21+
<copyright>
22+
<year>&COPYRIGHT_YEARS;</year>
23+
<holder>&COMPANY_NAME_LEGAL;</holder>
24+
</copyright>&legal;
25+
</bookinfo>
26+
27+
$for(include-before)$
28+
$include-before$
29+
$endfor$
30+
$body$
31+
$for(include-after)$
32+
$include-after$
33+
$endfor$
34+
35+
</book>

ocaml/idl/datamodel_main.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ let _ =
2525
and dtd_mode = ref false
2626
and closed = ref false (* shows release_closed *)
2727
and all = ref false (* shows release_impl as well *)
28-
and dirname = ref "" in
28+
and dirname = ref ""
29+
and templdir = ref "" in
2930

3031
Arg.parse [ "-dot", Arg.Set dot_mode, "output dot graph";
3132
"-markdown", Arg.Set markdown_mode, "output markdown document";
3233
"-dtd", Arg.Set dtd_mode, "output XML DTD";
3334
"-closed", Arg.Set closed, "output all OSS + closed API functions but not including internal ones";
34-
"-all", Arg.Set all, "output all API functions, including internal ones"
35+
"-all", Arg.Set all, "output all API functions, including internal ones";
36+
"-templdir", Arg.Set_string templdir, "the directory with the template (mustache) files";
3537
]
3638
(fun x -> dirname := x)
3739
"compile XenSource API datamodel specification";
@@ -67,7 +69,7 @@ let _ =
6769
let api = filter (fun _ -> true) (fun f -> not f.internal_only) (fun m -> not m.msg_hide_from_docs) api in
6870

6971
if (!markdown_mode) then
70-
Markdown_backend.all api !dirname;
72+
Markdown_backend.all api !templdir !dirname;
7173

7274
if !dirname <> "" then Unix.chdir !dirname;
7375
if !dot_mode then begin

ocaml/idl/markdown_backend.ml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,34 @@ Each possible error code is documented in the following section.
423423
(snd (List.split
424424
(List.sort (fun (n1, _) (n2, _)-> compare n1 n2) errs)))
425425

426-
let all api destdir =
426+
let json_current_version =
427+
let time = Unix.gettimeofday () in
428+
let month, year =
429+
match String.split ' ' (Date.rfc822_to_string (Date.rfc822_of_float time)) with
430+
| [ _; _; m; y; _; _ ] -> m,y
431+
| _ -> failwith "Invalid datetime string"
432+
in
433+
`O [
434+
"api_version_major", `Float (Int64.to_float api_version_major);
435+
"api_version_minor", `Float (Int64.to_float api_version_minor);
436+
"current_year", `String year;
437+
"current_month", `String month;
438+
]
439+
440+
let render_template template_file json output_file =
441+
let templ = Stdext.Unixext.string_of_file template_file |> Mustache.of_string in
442+
let rendered = Mustache.render templ json in
443+
let out_chan = open_out output_file in
444+
finally (fun () -> output_string out_chan rendered)
445+
(fun () -> close_out out_chan)
446+
447+
let all api templdir destdir =
427448
Stdext.Unixext.mkdir_rec destdir 0o755;
449+
450+
["cover.mustache", "cover.yaml"; "docbook.mustache", "template.db"] |>
451+
List.iter (fun (x,y) -> render_template
452+
(Filename.concat templdir x) json_current_version (Filename.concat destdir y));
453+
428454
let out_chan = open_out (Filename.concat destdir "api-ref-autogen.md") in
429455
let printer text =
430456
fprintf out_chan "%s" text;

0 commit comments

Comments
 (0)