Skip to content

Commit a801c0b

Browse files
committed
Moved string templating to nix
1 parent 28df077 commit a801c0b

3 files changed

Lines changed: 47 additions & 71 deletions

File tree

doc/default.nix

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ let
33
lib = pkgs.lib;
44
sources = lib.sourceFilesBySuffices ./. [".xml"];
55
sources-langs = ./languages-frameworks;
6-
libDocJSON = builtins.toFile "options.json" (builtins.toJSON (import ./fn-docs.nix));
7-
libDocBook= pkgs.runCommand "options-db.xml" {} ''
8-
${pkgs.ruby}/bin/ruby ${./lib2docbook.rb} < ${libDocJSON} > $out
9-
'';
6+
libChapter = builtins.toFile "lib.xml" (import ./fn-docs.nix).docChapter;
107
in
118
pkgs.stdenv.mkDerivation {
129
name = "nixpkgs-manual";
@@ -77,7 +74,7 @@ pkgs.stdenv.mkDerivation {
7774
outputFile = "./languages-frameworks/vim.xml";
7875
}
7976
+ ''
80-
cp ${libDocBook} ./lib.xml
77+
cp ${libChapter} ./lib.xml
8178
8279
echo ${lib.nixpkgsVersion} > .version
8380

doc/fn-docs.nix

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,52 @@ let
2929
set_val = lib.${set};
3030
documentedFunctions = filterDocumentedFunctions set_val;
3131
in map (n: {name = ["lib" set n]; docs = mkDocs set_val.${n}; }) documentedFunctions;
32+
33+
makeDocChapter = topLevel: categorized:
34+
let
35+
prefix = ''
36+
<chapter xmlns="http://docbook.org/ns/docbook"
37+
xmlns:xlink="http://www.w3.org/1999/xlink"
38+
xml:id="chap-lib-functions">
39+
40+
<title>Library functions</title>
41+
<para>This paragraph describes the available library functions.</para>
42+
'';
43+
postfix = "</chapter>";
44+
toplevel.prefix = ''
45+
<section xml:id="sec-lib-functions-top-level">
46+
<title>Top level functions</title>
47+
<para>These functions are available under <varname>pkgs.lib</varname></para>
48+
'';
49+
toplevel.postfix = "</section>";
50+
categories.prefix = ''
51+
<section xml:id="sec-lib-functions-all">
52+
<title>All library functions</title>
53+
<para>These functions are available under <varname>pkgs.$category.$name</varname></para>
54+
'';
55+
categories.postfix = "</section>";
56+
makeDocExample = example:
57+
"<para><emphasis>Example:</emphasis><programlisting>${example}</programlisting></para>";
58+
makeDocFn = { docs, name }: ''
59+
<varlistentry>
60+
<term><option>${concatStringsSep "." name}</option></term>
61+
<listitem>
62+
<para>${docs.description}</para>
63+
${
64+
lib.concatStrings (map makeDocExample docs.examples)
65+
}
66+
</listitem>
67+
</varlistentry>
68+
'';
69+
makeDocFns = fns: "<variablelist>" + (lib.concatStrings (map makeDocFn fns)) + "</variablelist>";
70+
in
71+
prefix +
72+
toplevel.prefix + (makeDocFns topLevel) + toplevel.postfix +
73+
categories.prefix + (makeDocFns categorized) + categories.postfix +
74+
postfix;
3275
in
33-
{
76+
rec {
3477
categorized = concatLists (map find_functions sets);
3578
topLevel = topLevelDocumentedFunctions;
79+
docChapter = makeDocChapter topLevel categorized;
3680
}

doc/lib2docbook.rb

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)