Debian Codegraph @

doc/_stdlib_gen/stdlib.jsonnet

raw
1 local html = import 'html.libsonnet';
2 local jekyll = import 'jekyll.libsonnet';
3 local content = import 'stdlib-content.jsonnet';
4
5 local
6 h1 = html.h1,
7 p = html.p;
8
9 local manifestJsonSingleLine(val) = std.strReplace(std.manifestJsonEx(val, ''), '\n', ' ');
10
11 local exampleDoc(ex) =
12 local exRep =
13 if std.isString(ex) then
14 ex
15 else
16 html.spaceless([html.code({}, ex.input), ' yields ', html.code({}, manifestJsonSingleLine(ex.output))])
17 ;
18 if std.objectHas(ex, 'type') then
19 ex
20 else
21 html.p({}, html.spaceless(['Example: ', exRep, '.']))
22 ;
23
24 local hgroup(body) = html.div({ class: 'hgroup' }, body);
25 local hgroup_inline(body) = html.div({ class: 'hgroup-inline' }, [body, '<div style="clear: both"></div>']);
26 local panel(body) = html.div({ class: 'panel' }, body);
27
28 local in_panel(body) = hgroup(hgroup_inline(panel(body)));
29
30 local fieldParams(f) =
31 if std.objectHas(f, 'params') then
32 '(' + std.join(', ', f.params) + ')'
33 else
34 ''
35 ;
36
37 local fieldDescription(f) =
38 if std.isString(f.description) then
39 html.p({}, f.description)
40 else
41 f.description
42 ;
43
44 local fieldDoc(f, prefix) =
45 [
46 in_panel(html.h4({ id: 'std-' + f.name }, prefix + '.' + f.name + fieldParams(f))),
47 in_panel([
48 if std.objectHas(f, 'availableSince') then (
49 html.p(
50 {},
51 html.em(
52 {},
53 if f.availableSince == 'upcoming' then
54 'Available in upcoming release.'
55 else
56 'Available since version ' + f.availableSince + '.'
57 )
58 )
59 ),
60 fieldDescription(f),
61 if std.objectHas(f, 'examples') then [
62 exampleDoc(ex)
63 for ex in f.examples
64 ] else [],
65 ]),
66 '',
67 ];
68
69 local group(group_spec, prefix) =
70 [
71 in_panel(html.h3({ id: group_spec.id }, group_spec.name)),
72 if std.objectHas(group_spec, 'intro') then in_panel(group_spec.intro),
73 '',
74 [fieldDoc(f, prefix) for f in group_spec.fields],
75 '',
76 ];
77
78 local stdlibPage = [
79 in_panel(html.h1({ id: 'standard_library' }, 'Standard Library')),
80 '',
81 in_panel(content.intro),
82 '',
83 [group(g, content.prefix) for g in content.groups],
84 ];
85
86 local stdlibFrontMatter = {
87 layout: 'stdlib',
88 title: 'Standard Library',
89 };
90
91 jekyll.renderWithFrontMatter(stdlibFrontMatter, stdlibPage)