improved webdocs; added nix flake for webdocs

This commit is contained in:
Felix Krause 2022-06-04 01:45:41 +02:00
parent 89e18cebfa
commit d80b6fb52e
9 changed files with 249 additions and 33 deletions

1
.gitignore vendored
View File

@ -22,3 +22,4 @@ doc/rstPreproc
doc/tmp.rst
doc/**/code
nimsuggest.log
result

View File

@ -35,8 +35,6 @@ nim lexerTests # run lexer tests
nim parserTests # run parser tests (git-clones yaml-dev-kit)
nim serializationTests # runs serialization tests
nim quickstartTests # run tests for quickstart snippets from documentation
nim documentation # builds documentation to folder docout
nim server # builds the REST server used for the testing ground
nim bench # runs benchmarks, requires libyaml
nim clean # guess
nim build # build a library
@ -48,6 +46,20 @@ NimYAML v0.9.1 is the last release to support Nim 0.15.x and 0.16.0.
When debugging crashes in this library, use the `d:debug` compile flag to enable printing of the internal stack traces for calls to `internalError` and `yAssert`.
### Web Documentation
The online documentation on [nimyaml.org](https://nimyaml.org), including the
testing ground, is generated via [Nix Flake][3] and easily deployable on NixOS.
Just include the NixOS module in the flake and do
```nix
services.nimyaml-webdocs.enable = true;
```
This will run the documentation server locally at `127.0.0.1:5000`. You can
change the `address` setting to make it public, but I suggest proxying via nginx
to get HTTPS.
## License
[MIT][2]
@ -58,3 +70,4 @@ If you like this project and want to give something back, you can check out GitH
[1]: http://flyx.github.io/NimYAML/
[2]: copying.txt
[3]: https://nixos.wiki/wiki/Flakes

View File

@ -17,7 +17,7 @@
## available as source files for automatic testing. This way, we can make sure
## that the code in the docs actually works.
import parseopt2, streams, tables, strutils, os, options
import parseopt2, streams, tables, strutils, os, options, algorithm
var
infile = ""
@ -78,10 +78,13 @@ proc outputExamples(curPath: string, level: int = 0) =
# process content files under this directory
var subdirs = newSeq[string]()
var codeFiles = newSeq[string]()
for kind, filePath in walkDir(curPath, true):
if kind == pcFile:
if filePath != "title": codeFiles.add(filePath)
elif kind == pcDir:
subdirs.add(filePath)
case codeFiles.len
of 0: discard
of 1:
@ -110,9 +113,9 @@ proc outputExamples(curPath: string, level: int = 0) =
# process child directories
for kind, dirPath in walkDir(curPath):
if kind == pcDir:
outputExamples(dirPath, level + 1)
subdirs.sort()
for dirPath in subdirs:
outputExamples(curPath / dirPath, level + 1)
var lineNum = 0
for line in infile.lines():

View File

@ -172,4 +172,9 @@ object {
border-radius: 0;
-moz-border-radius: 0;
-webkit-border-radius: 0;
}
/* hide autogenerated stuff we don't need */
.theme-switch-wrapper, #global-links, #searchInputDiv {
display: none;
}

View File

@ -74,7 +74,7 @@ updated as you type.
var params = "style=" + encodeURIComponent(document.querySelector(
"input[name=style]:checked").value) + "&input=" + encodeURIComponent(
document.getElementById("yaml-input").value);
r.open("POST", "https://nimyaml.org/webservice/", true);
r.open("POST", "/webservice/", true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
r.onreadystatechange = function() {
if (r.readyState == 4) {

59
flake.lock Normal file
View File

@ -0,0 +1,59 @@
{
"nodes": {
"nix-filter": {
"locked": {
"lastModified": 1653590866,
"narHash": "sha256-E4yKIrt/S//WfW5D9IhQ1dVuaAy8RE7EiCMfnbrOC78=",
"owner": "numtide",
"repo": "nix-filter",
"rev": "3e81a637cdf9f6e9b39aeb4d6e6394d1ad158e16",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "nix-filter",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1653936696,
"narHash": "sha256-M6bJShji9AIDZ7Kh7CPwPBPb/T7RiVev2PAcOi4fxDQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ce6aa13369b667ac2542593170993504932eb836",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "22.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nix-filter": "nix-filter",
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

128
flake.nix Normal file
View File

@ -0,0 +1,128 @@
{
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/22.05;
utils.url = github:numtide/flake-utils;
nix-filter.url = github:numtide/nix-filter;
};
outputs = {
self, nixpkgs, utils, nix-filter
}: let
version = "0.16.0";
systemDependent = with utils.lib; eachSystem allSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in with nix-filter.lib; {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ nim ];
};
packages.webdocs = let
nim-jester = pkgs.stdenv.mkDerivation {
name = "nim-jester-0.5.0";
src = pkgs.fetchFromGitHub {
owner = "dom96";
repo = "jester";
rev = "v0.5.0";
sha256 = "0m8a4ss4460jd2lcbqcbdd68jhcy35xg7qdyr95mh8rflwvmcvhk";
};
dontBuild = true;
installPhase = ''
mkdir -p $out/lib
cp -r jester.nim jester $out/lib
'';
};
nim-httpbeast = pkgs.stdenv.mkDerivation {
name = "nim-httpbeast-0.2.2";
src = pkgs.fetchFromGitHub {
owner = "dom96";
repo = "httpbeast";
rev = "v0.2.2";
sha256 = "1f8ch7sd5kcyaw1b1lpqywvhx2h6aa5an37zm7x0j22giqlml5c6";
};
dontBuild = true;
installPhase = ''
mkdir -p $out/lib
cp -r src/* $out/lib
'';
};
nim-cligen = pkgs.stdenv.mkDerivation {
name = "nim-cligen-0.15.3";
src = pkgs.fetchFromGitHub {
owner = "c-blake";
repo = "cligen";
rev = "v1.5.23";
sha256 = "rcledZbmcAXs0l5uQRmOennyMiw4G+zye6frGqksjyA=";
};
dontBuild = true;
installPhase = ''
mkdir -p $out/lib
cp -rt $out/lib cligen.nim cligen
'';
};
in pkgs.stdenv.mkDerivation {
pname = "nimyaml-server-deamon";
inherit version;
src = filter {
root = ./.;
exclude = [ ./flake.nix ./flake.lock ./tools ./bench ./.github ];
};
configurePhase = ''
mkdir -p docout/api
(
cd doc
for rstFile in *.rst; do
${pkgs.nim}/bin/nim rst2html -o:../docout/''${rstFile%.rst}.html $rstFile
done
${pkgs.nim}/bin/nim c --nimcache:.cache rstPreproc
for txtFile in *.txt; do
./rstPreproc -o:tmp.rst $txtFile
${pkgs.nim}/bin/nim rst2html -o:../docout/''${txtFile%.txt}.html tmp.rst
done
cp docutils.css style.css processing.svg ../docout
)
${pkgs.nim}/bin/nim doc2 -o:docout/api/yaml.html --docSeeSrcUrl:https://github.com/flyx/NimYAML/blob/${self.rev or "master"} yaml
for srcFile in yaml/*.nim; do
bn=''${srcFile#yaml/}
${pkgs.nim}/bin/nim doc2 -o:docout/api/''${bn%.nim}.html --docSeeSrcUrl:https://github.com/flyx/NimYAML/blob/yaml/${self.rev or "master"} $srcFile
done
'';
buildPhase = ''
cat <<EOF >server/server_cfg.nim
proc shareDir*(): string =
result = "$out/share"
EOF
${pkgs.nim}/bin/nim c --d:release --d:yamlScalarRepInd -p:"${nim-jester}/lib" -p:"${nim-httpbeast}/lib" -p:"${nim-cligen}/lib" --nimcache:.cache server/server
'';
installPhase = ''
mkdir -p $out/{bin,share}
cp server/server $out/bin
cp -rt $out/share docout/*
'';
};
});
in systemDependent // {
nixosModule = {config, lib, pkg, ...}: with lib; let
cfg = config.services.nimyaml-webdocs;
webdocs = systemDependents.packages.${config.nixpkgs.system}.webdocs;
in {
options.services.nimyaml-webdocs = {
enable = mkEnableOption "NimYAML webdocs server";
address = mkOption {
type = types.str;
default = "127.0.0.1";
description = "Listen address";
};
port = mkOption {
type = types.int;
default = 5000;
description = "Listen port";
};
};
config = mkIf cfg.enable {
systemd.services.dsa41generator = {
wantedBy = ["multi-user.target"];
after = ["network.target"];
serviceConfig.ExecStart = ''${webdocs}/bin/server --address "${cfg.address}" --port ${cfg.port}'';
};
};
};
};
}

View File

@ -96,8 +96,8 @@ doc.file = """
<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="/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'/>
@ -105,31 +105,31 @@ doc.file = """
<body>
<a href="https://github.com/flyx/NimYAML"><img style="position: fixed; top: 0; right: 0; border: 0; z-index: 10;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>
<header>
<a class="pagetitle" href="index.html">NimYAML</a>
<a href="index.html">Home</a>
<a href="testing.html">Testing Ground</a>
<a class="pagetitle" href="/index.html">NimYAML</a>
<a href="/index.html">Home</a>
<a href="/testing.html">Testing Ground</a>
<span>Docs:</span>
<a href="api.html">Overview</a>
<a href="/api.html">Overview</a>
<span>
<a href="#">Serialization</a>
<a href="/serialization.html">Serialization</a>
<ul>
<li><a href="serialization.html">Overview</a></li>
<li><a href="schema.html">Schema</a></li>
<li><a href="/serialization.html">Overview</a></li>
<li><a href="/schema.html">Schema</a></li>
</ul>
</span>
<span>
<a href="#">Modules</a>
<a href="/api/yaml.html">Modules</a>
<ul class="monospace">
<li><a href="yaml.html">yaml</a></li>
<li><a href="yaml.dom.html">yaml.dom</a></li>
<li><a href="yaml.hints.html">yaml.hints</a></li>
<li><a href="yaml.parser.html">yaml.parser</a></li>
<li><a href="yaml.presenter.html">yaml.presenter</a></li>
<li><a href="yaml.serialization.html">yaml.serialization</a></li>
<li><a href="yaml.annotations.html">yaml.annotations</a></li>
<li><a href="yaml.stream.html">yaml.stream</a></li>
<li><a href="yaml.taglib.html">yaml.taglib</a></li>
<li><a href="yaml.tojson.html">yaml.tojson</a></li>
<li><a href="/api/yaml.html">yaml</a></li>
<li><a href="/api/dom.html">yaml.dom</a></li>
<li><a href="/api/hints.html">yaml.hints</a></li>
<li><a href="/api/parser.html">yaml.parser</a></li>
<li><a href="/api/presenter.html">yaml.presenter</a></li>
<li><a href="/api/serialization.html">yaml.serialization</a></li>
<li><a href="/api/annotations.html">yaml.annotations</a></li>
<li><a href="/api/stream.html">yaml.stream</a></li>
<li><a href="/api/taglib.html">yaml.taglib</a></li>
<li><a href="/api/tojson.html">yaml.tojson</a></li>
</ul>
</span>
</header>

View File

@ -4,14 +4,14 @@
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
import jester, asyncdispatch, json, streams, strutils
import jester, cligen, asyncdispatch, json, streams, strutils
import packages/docutils/rstgen, packages/docutils/highlite, options
import ../yaml
import ../yaml, server_cfg
routes:
get "/":
router nyRouter:
get "/webservice/":
resp(Http200, [("Content-Type", "text/plain")], "I am a friendly NimYAML parser webservice.")
post "/":
post "/webservice/":
var
style: PresentationStyle
resultNode = newJObject()
@ -85,4 +85,11 @@ routes:
contentType = "text/plain;charset=utf-8"
headers.add(("Content-Type", contentType))
resp retStatus, headers, msg
runForever()
proc main(port = 5000, address = "127.0.0.1") =
let settings = newSettings(port=port.Port, bindAddr=address, staticDir=shareDir())
var jester = initJester(nyrouter, settings=settings)
jester.serve()
when isMainModule:
dispatch(main)