Permalink
Browse files

Auto-generate the navbar index

  • Loading branch information...
David Scott
David Scott committed Mar 6, 2012
1 parent 6878c5f commit 318abf067bfe2d9a6a3c4daa602c458c6d3db43b
Showing with 81 additions and 48 deletions.
  1. +1 −20 doc/header.html
  2. +74 −25 main.ml
  3. +2 −1 smapiv2.ml
  4. +2 −1 types.ml
  5. +2 −1 xenops.ml
View
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
- <title>Bootstrap, from Twitter</title>
+ <title>XCP on host interfaces</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
@@ -33,22 +33,3 @@
<body onload="prettyPrint()">
- <div class="navbar navbar-fixed-top">
- <div class="navbar-inner">
- <div class="container">
- <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </a>
- <a class="brand" href="#">API browser</a>
- <div class="nav-collapse">
- <ul class="nav">
- <li class="active"><a href="#">Home</a></li>
- <li><a href="#about">About</a></li>
- <li><a href="#contact">Contact</a></li>
- </ul>
- </div><!--/.nav-collapse -->
- </div>
- </div>
- </div>
View
99 main.ml
@@ -1,4 +1,5 @@
open Pervasiveext
+open Types
let with_file filename f =
let oc = open_out filename in
@@ -8,36 +9,84 @@ let print_file_to oc =
let output_line oc txt = output_string oc txt; output_string oc "\n" in
Unixext.file_lines_iter (output_line oc)
+type page = {
+ name: string;
+ title: string;
+ filename: string;
+ path: string;
+ description: string;
+ api: Interfaces.t;
+}
+
+let page_of_api api =
+ let open Types in {
+ name = api.Interfaces.name;
+ title = api.Interfaces.title;
+ path = "doc/" ^ api.Interfaces.name ^ ".html";
+ filename = api.Interfaces.name ^ ".html";
+ description = api.Interfaces.description;
+ api = api;
+}
+
+let html_navbar oc pages this_page =
+ let div cls = `El_start (("", "div"), [ ("", "class"), cls ]) in
+ let a cls toggle target = `El_start (("", "a"), [ ("", "class"), cls; ("", "data-toggle"), toggle; ("", "data-target"), target ]) in
+ let span cls = `El_start (("", "span"), [ ("", "class"), cls ]) in
+ let ul cls = `El_start (("", "ul"), [ ("", "class"), cls ]) in
+ let li cls = `El_start (("", "li"), match cls with None -> [] | Some x -> [ ("", "class"), x ]) in
+ let endtag = `El_end in
+ let txt = Types.with_xmlm
+ (fun xmlm ->
+ xmlm (div "navbar navbar-fixed-top");
+ xmlm (div "navbar-inner");
+ xmlm (div "container");
+ xmlm (a "btn btn-navbar" "collapse" ".nav-collapse");
+ xmlm (span "icon-bar"); xmlm endtag;
+ xmlm (span "icon-bar"); xmlm endtag;
+ xmlm (span "icon-bar"); xmlm endtag;
+ xmlm endtag;
+ xmlm (`El_start (("", "a"), [ ("", "class"), "brand"; ("", "href"), "#"]));
+ xmlm (`Data "XCP on-host APIs");
+ xmlm endtag;
+ xmlm (div "nav-collapse");
+ xmlm (ul "nav");
+ List.iter
+ (fun page ->
+ xmlm (li (if page = this_page then Some "active" else None));
+ xmlm (`El_start (("", "a"), [ ("", "href"), page.filename ]));
+ xmlm (`Data page.name);
+ xmlm endtag;
+ xmlm endtag
+ ) pages;
+ xmlm endtag;
+ xmlm endtag;
+ xmlm endtag;
+ xmlm endtag;
+ xmlm endtag
+ ) in
+ output_string oc txt
+
let _ =
-(*
- print_string (to_dbus_xml smapiv2);
- print_string "";
- print_string "\n";
- print_string "";
- print_string (to_json smapiv2);
- print_string "\n";
- print_string "";
- to_rpclight smapiv2;
- print_string "";
-*)
let resolve_refs_in_api api =
let idents, api = Types.lift_type_decls api in
Types.dump_ident_mappings idents;
idents, (Types.resolve_references idents api) in
- with_file "doc/smapiv2.html"
- (fun oc ->
- print_file_to oc ("doc/header.html");
- let idents, api = resolve_refs_in_api Smapiv2.api in
- output_string oc (Types.to_html idents api);
- print_file_to oc ("doc/footer.html")
- );
- with_file "doc/xenops.html"
- (fun oc ->
- print_file_to oc ("doc/header.html");
- let idents, api = resolve_refs_in_api Xenops.api in
- output_string oc (Types.to_html idents api);
- print_file_to oc ("doc/footer.html")
- )
+ let apis = [
+ Smapiv2.api;
+ Xenops.api;
+ ] in
+ let pages = List.map page_of_api apis in
+ List.iter
+ (fun page ->
+ with_file page.path
+ (fun oc ->
+ print_file_to oc ("doc/header.html");
+ html_navbar oc pages page;
+ let idents, api = resolve_refs_in_api page.api in
+ output_string oc (Types.to_html idents api);
+ print_file_to oc ("doc/footer.html")
+ );
+ ) pages
View
@@ -41,7 +41,8 @@ let api =
} in
{
Interfaces.name = "SMAPIv2";
- description = "The Storage Manager API";
+ title = "The Storage Manager API";
+ description = "The Storage Manager (SM) is responsible for all storage operations on an XCP host. It organises Virtual Disk Images (VDIs) into homogenous collections known as Storage Repositories (SRs) where each collection is stored in a specific format (e.g. .vhd files on NFS, raw LUN on a iSCSI/FC storage array). The Storage Manager API (SMAPI) provides a simple abstract interface which allows the toolstack to create, destroy, snapshot, clone, resize etc VDIs within SRs";
type_decls = [ { TyDecl.name = "vdi_info";
description = "All per-VDI properties";
ty = vdi_info
View
@@ -189,6 +189,7 @@ end
module Interfaces = struct
type t = {
name: string;
+ title: string;
description: string;
type_decls: TyDecl.t list;
interfaces: Interface.t list;
@@ -516,7 +517,7 @@ let to_html env x =
(* Main content *)
Xmlm.output output (`El_start (("", "div"), [ ("", "class"), "span10" ]));
- h1 ~id:(Printf.sprintf "a-%s" x.Interfaces.name) x.Interfaces.name;
+ h1 ~id:(Printf.sprintf "a-%s" x.Interfaces.name) (Printf.sprintf "%s: %s" x.Interfaces.name x.Interfaces.title);
p x.Interfaces.description;
List.iter of_type_decl x.Interfaces.type_decls;
List.iter
View
@@ -3,7 +3,8 @@ open Types
let api =
{
Interfaces.name = "xenops";
- description = "The Xen domain management API";
+ title = "The Xen domain management API";
+ description = "The Xen domain management service is responsible for all domain management on an XCP host. The API allows clients to register VM configurations with the management service and issue VM lifecycle commands such as: start, shutdown, reboot, suspend, resume and migrate. A simple event interface allows interested clients to notice when significant events have happened, for example a VM reboot or a Virtual Block Device (VBD) unplug.";
type_decls = [
{ TyDecl.name = "power_state";
description = "Power state of the VM";

0 comments on commit 318abf0

Please sign in to comment.