Build proper HTML documentation

This commit is contained in:
Felix Krause 2016-01-13 22:43:12 +01:00
parent 7cabfc652e
commit 40e3e32f5d
7 changed files with 1487 additions and 4 deletions

2
.gitignore vendored
View File

@ -10,4 +10,4 @@ yaml.html
libyaml.dylib
libyaml.so
bench/json
docout

View File

@ -23,8 +23,13 @@ task serializationTests, "Run serialization tests":
--verbosity:0
setCommand "c", "test/serializing"
task doc, "Generate documentation":
setCommand "doc2", "yaml"
task documentation, "Generate documentation":
exec "mkdir -p docout"
exec r"nim doc2 -o:docout/yaml.html yaml"
exec r"nim doc2 -o:docout/serialization.html yaml/serialization.nim"
exec r"nim rst2html -o:docout/index.html doc/index.txt"
exec "cp doc/docutils.css doc/style.css doc/testing.html docout"
setCommand "nop"
task bench, "Benchmarking":
--d:release
@ -32,7 +37,7 @@ task bench, "Benchmarking":
setCommand "c", "bench/json"
task clean, "Remove all generated files":
exec "rm -f yaml.html libyaml.* test/tests test/parsing test/lexing"
exec "rm -f libyaml.* test/tests test/parsing test/lexing docout"
setCommand "nop"
task server, "Compile server daemon":

1124
doc/docutils.css Normal file

File diff suppressed because it is too large Load Diff

5
doc/index.txt Normal file
View File

@ -0,0 +1,5 @@
=======
NimYAML
=======
TBD: General information here. Possibly move text from yaml.html. Eat pizza.

84
doc/style.css Normal file
View File

@ -0,0 +1,84 @@
header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 50px;
background: #111;
margin: 0;
padding: 0;
z-index: 1;
}
header a {
display: inline-block;
line-height: 50px;
font-size: large;
padding-left: 5px;
padding-right: 5px;
}
header span {
display: inline-block;
line-height: 50px;
font-size: large;
color: white;
padding-left: 15px;
padding-right: 5px;
}
header a:link,
header a:visited {
background: inherit;
color: #aaa;
}
header a:hover {
background: inherit;
color: white;
text-decoration: inherit;
}
header a:active {
background: #222;
color: white;
text-decoration: inherit;
}
a.pagetitle:link,
a.pagetitle:hover,
a.pagetitle:active,
a.pagetitle:visited {
background: inherit;
color: white;
text-decoration: inherit;
}
body {
margin-left: 0;
margin-right: 0;
margin-top: 55px;
margin-bottom: 5px;
padding: 0;
}
html {
background-color: rgba(252, 248, 244, 0.75);
}
#testingground textarea {
width: 100%;
height: 100%;
}
#testingground textarea,
#testingground pre {
font-family: "Source Code Pro", Menlo, "Courier New", Courier, monospace;
margin: 0;
}
#testingground pre {
font-size: small;
}
#testingground .style-option {
display: inline-block;
margin-right: 20px;
}

136
doc/testing.html Normal file
View File

@ -0,0 +1,136 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NimYAML - $title</title>
<link href="docutils.css" rel="stylesheet" type="text/css"/>
<link href="style.css" rel="stylesheet" type="text/css"/>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,600,900' rel='stylesheet' type='text/css'/>
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
</head>
<body>
<header>
<a class="pagetitle" href="/">NimYAML</a>
<a href="index.html">Home</a>
<a href="testing.html">Testing Ground</a>
<span>API:</span>
<a href="yaml.html">Module yaml</a>
<a href="serialization.html">Module yaml.serialization</a>
</header>
<article id="documentId">
<div class="container">
<h1 class="title">Testing Ground</h1>
<p>Output is being processed on the fly by a friendly web service and is
updated as you type.</p>
<section id="testingground">
<table style="width: 100%; table-layout: fixed">
<thead>
<tr>
<th>Input</th>
<th>Output</th>
</tr>
</thead>
<tbody>
<tr>
<td style="width: 50%; height: 400px; vertical-align: top;">
<textarea id="yaml-input" style="width: 100%; height: 100%">
- test some
- {YAML: here}
- foo: bar
? [1, 2, 3]
: !!str "string"
-
? &amp;a anchor
: !!bool yes
? reference to anchor
: *a</textarea>
</td>
<td style="width: 50%; vertical-align: top; height: 400px; padding-left: 10px">
<div style="width:100%; height:100%; overflow: scroll">
<pre id="yaml-output" style="width: 100%"/>
</div>
</td>
</tr>
</tbody>
</table>
<div id="style-options">
<p>Output style:</p>
<div class="style-option">
<input type="radio" name="style" id="style-minimal" value="minimal"/>
<label for="style-minimal">Minimal</label>
</div>
<div class="style-option">
<input type="radio" name="style" id="style-default" value="default"/>
<label for="style-default">Default</label>
</div>
<div class="style-option">
<input type="radio" name="style" id="style-canonical" value="canonical" checked="checked"/>
<label for="style-canonical">Canonical</label>
</div>
<div class="style-option">
<input type="radio" name="style" id="style-block" value="block"/>
<label for="style-block">Block Only</label>
</div>
<div class="style-option">
<input type="radio" name="style" id="style-json" value="json"/>
<label for="style-json">JSON</label>
</div>
</div>
</section>
</div>
</article>
<script type="text/javascript">
function parse() {
var r = new XMLHttpRequest();
var params = "style=" + encodeURIComponent(document.querySelector(
"input[name=style]:checked").value) + "&input=" + encodeURIComponent(
document.getElementById("yaml-input").value);
r.open("POST", "http://flyx.org:5000", true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
r.onreadystatechange = function() {
if (r.readyState == 4) {
var output = document.getElementById("yaml-output");
if (r.status == 200) {
var result = JSON.parse(r.responseText);
switch(result.code) {
case 0:
output.innerText = result.output;
output.style.color = "black";
break;
case 1:
output.innerText = "Parser error at line " + result.line +
", column " + result.column + ":\n" + result.message +
"\n\n" + result.detail;
output.style.color = "orange";
break;
case 2:
output.innerText = "Presenter error:\n" + result.message;
output.style.color = "orange";
break;
}
} else if (r.status == 0) {
output.innerText =
"YAML parser server does not seem to be available.";
output.style.color = "red";
} else {
output.innerText = "Status: " + r.status +
"\nException occurred on server:\n\n" +
r.responseText;
output.style.color = "red";
}
}
}
r.send(params);
}
document.getElementById("yaml-input").addEventListener('input', parse,
false);
var radios = document.querySelectorAll("input[name=style]");
for (var i = 0; i < radios.length; ++i) {
radios[i].onclick = parse;
}
parse();
</script>
</body>
</html>

129
nimdoc.cfg Normal file
View File

@ -0,0 +1,129 @@
# This is the config file for the documentation generator.
# (c) 2012 Andreas Rumpf
# Feel free to edit the templates as you need. If you modify this file, it
# might be worth updating the hardcoded values in packages/docutils/rstgen.nim
split.item.toc = "20"
# too long entries in the table of contents wrap around
# after this number of characters
doc.section = """
<section id="$sectionID">
<h1><a class="toc-backref" href="#$sectionID">$sectionTitle</a></h1>
<dl class="item">
$content
</dl></section>
"""
doc.section.toc = """
<li>
<a class="reference reference-toplevel" href="#$sectionID" id="$sectionTitleID">$sectionTitle</a>
<ul class="simple simple-toc-section">
$content
</ul>
</li>
"""
# Chunk of HTML emitted for each entry in the HTML table of contents.
# Available variables are:
# * $desc: the actual docstring of the item.
# * $header: the full version of name, including types, pragmas, tags, etc.
# * $header_plain: like header but without HTML, for attribute embedding.
# * $itemID: numerical unique entry of the item in the HTML.
# * $itemSym: short symbolic name of the item for easier hyperlinking.
# * $itemSymEnc: quoted version for URLs or attributes.
# * $itemSymOrID: the symbolic name or the ID if that is not unique.
# * $itemSymOrIDEnc: quoted version for URLs or attributes.
# * $name: reduced name of the item.
# * $seeSrc: generated HTML from doc.item.seesrc (if some switches are used).
doc.item = """
<dt id="$itemSym"><a name="$itemSymOrID"></a><pre>$header</pre></dt>
<dd>
$desc
$seeSrc
</dd>
"""
# Chunk of HTML emitted for each entry in the HTML table of contents.
# See doc.item for available substitution variables.
doc.item.toc = """
<li><a class="reference" href="#$itemSymOrID"
title="$header_plain">$name</a></li>
"""
# HTML rendered for doc.item's seeSrc variable. Note that this will render to
# the empty string if you don't pass anything through --docSeeSrcURL. Available
# substitutaion variables here are:
# * $path: relative path to the file being processed.
# * $line: line of the item in the original source file.
# * $url: whatever you did pass through the --docSeeSrcUrl switch (which also
# gets variables path/line replaced!)
doc.item.seesrc = """&nbsp;&nbsp;<a
href="${url}/${path}#L${line}"
class="link-seesrc" target="_blank">Source</a>"""
doc.toc = """
<ul class="simple simple-toc" id="toc-list">
$content
</ul>
"""
doc.body_toc = """
<div class="row">
<div class="three columns">
$tableofcontents
</div>
<div class="nine columns" id="content">
<p class="module-desc">$moduledesc</p>
$content
</div>
</div>
"""
doc.body_no_toc = """
$moduledesc
$content
"""
doc.listing_start = "<pre class = \"listing\">"
doc.listing_end = "</pre>"
doc.file = """
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NimYAML - $title</title>
<link href="docutils.css" rel="stylesheet" type="text/css"/>
<link href="style.css" rel="stylesheet" type="text/css"/>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,600,900' rel='stylesheet' type='text/css'/>
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
</head>
<body>
<header>
<a class="pagetitle" href="/">NimYAML</a>
<a href="index.html">Home</a>
<a href="testing.html">Testing Ground</a>
<span>API:</span>
<a href="yaml.html">Module yaml</a>
<a href="serialization.html">Module yaml.serialization</a>
</header>
<article id="documentId">
<div class="container">
<h1 class="title">$title</h1>
$content
<div class="row">
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br/>
<small>Made with Nim. Generated: $date $time UTC</small>
</div>
</div>
</div>
</article>
</body>
</html>
"""