Skip to content

Commit 38fb638

Browse files
committed
new documentation generator script (draft)
1 parent 601e0df commit 38fb638

2 files changed

Lines changed: 248 additions & 0 deletions

File tree

misc/docs/docgen2.ctr

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# Documentation Generation System
2+
# for all supported human languages
3+
# Author: G.J.G.T. de Mooij
4+
# License: BSD
5+
6+
# configuration
7+
8+
>> CTREN := ['../../bin/Linux/ctren'].
9+
>> CTR := ['../../bin/Linux/ctr'].
10+
>> DICT := ['../../dict/en'].
11+
>> DIR := ['/tmp/ctrdocs'].
12+
>> TEST := ['../../tests/en/t-'].
13+
>> RUN := ['/tmp/ctrdocs/runner'].
14+
15+
>> t := Moment new.
16+
>> time := t time plain.
17+
>> date := ['year-month-day hour:minute']
18+
year: t year plain,
19+
month: t month,
20+
day: t day,
21+
hour: t hour,
22+
minute: t minute.
23+
24+
>> template := File new: ['example.tpl.html'], read.
25+
>> manual := Dict new.
26+
>> outdir := ['server'].
27+
28+
>> languages := List new.
29+
30+
>> source := ( File new: ['../../base.c'], read ) +
31+
( File new: ['../../collections.c'], read ).
32+
33+
34+
>> comments := source split: ['/**'].
35+
comments shift.
36+
>> total := comments count.
37+
38+
String on: ['html'] do: {
39+
>> html := self string copy.
40+
html replace: ['&'] with: ['&'].
41+
html replace: ['"'] with: ['"'].
42+
html replace: ['<'] with: ['&lt;'].
43+
html replace: ['>'] with: ['&gt;'].
44+
html replace: ['↵'] with: ['<br>'].
45+
<- html.
46+
}.
47+
48+
49+
File list: ['../../i18nsel'], each: { :i :dict
50+
>> lang := dict file.
51+
lang = ['..'] or: lang = ['.'], continue.
52+
manual put: (List new) at: lang.
53+
languages append: lang.
54+
}.
55+
56+
languages sort: { :a :b <- a > b. }.
57+
58+
Program os: ['mkdir -p /tmp/ctrdocs'].
59+
60+
>> book := Dict new.
61+
62+
languages each: { :i :iso
63+
book put: (List new) at: iso.
64+
}.
65+
66+
>> language-index := [''].
67+
>> first := True.
68+
69+
comments each: { :i :comment
70+
71+
>> comment := comment split: ['*/'], first.
72+
>> parts := comment split: ['@def'].
73+
(parts count < 2) continue.
74+
parts := parts last split: ['@test'].
75+
(parts count < 2) continue.
76+
>> def := parts first replace: ['\n *'] with: [''], trim.
77+
>> testno := parts last trim.
78+
79+
80+
Out write: (
81+
['Processing comment: <index>/<total>']
82+
<index>: i,
83+
<total>: total
84+
), stop.
85+
86+
Out write: def, stop.
87+
Out write: testno, stop.
88+
89+
>> path := ['../../tests/en/t-'] + testno + ['.ctr'].
90+
>> example := File new: path, read.
91+
92+
93+
94+
File new: ( ['<DIR>/defsrc.ctr'] <DIR>: DIR ), write: def.
95+
96+
97+
98+
languages each: { :j :iso
99+
100+
Out write: iso, stop.
101+
102+
103+
>> translate-def := ['<CTREN> -t <DICT><ISO>.dict <DIR>/defsrc.ctr > <DIR>/def<ISO>.ctr 2><DIR>/deferr<ISO>.log'].
104+
translate-def
105+
<CTREN>: CTREN,
106+
<DICT>: DICT,
107+
<DIR>: DIR,
108+
<ISO>: iso.
109+
110+
111+
Program os: translate-def.
112+
113+
>> translate-example := ['<CTREN> -t <DICT><ISO>.dict <TEST><NR>.ctr > <RUN><ISO>.ctr 2><DIR>/runerr<ISO>.log'].
114+
translate-example
115+
<CTREN>: CTREN,
116+
<DICT>: DICT,
117+
<DIR>: DIR,
118+
<TEST>: TEST,
119+
<RUN>: RUN,
120+
<NR>: testno,
121+
<ISO>: iso.
122+
123+
124+
Program os: translate-example.
125+
126+
>> run-example := ['<CTR><ISO> <RUN><ISO>.ctr > <DIR>/res<ISO>.txt 2><DIR>/reserr<ISO>.log'].
127+
128+
run-example
129+
<CTR>: CTR,
130+
<DIR>: DIR,
131+
<RUN>: RUN,
132+
<ISO>: iso.
133+
134+
135+
Program os: run-example.
136+
137+
>> path-localized-definition := ['<DIR>/def<ISO>.ctr'] <DIR>: DIR, <ISO>: iso.
138+
>> path-localized-example := ['<RUN><ISO>.ctr'] <RUN>: RUN, <ISO>: iso.
139+
>> path-localized-result := ['<DIR>/res<ISO>.txt'] <DIR>: DIR, <ISO>: iso.
140+
141+
>> localized-definition := File new: path-localized-definition, read.
142+
>> localized-example := File new: path-localized-example, read.
143+
>> localized-result := File new: path-localized-result, read.
144+
>> shasum := (
145+
Program os: ( ['echo "<ISO><DEF>" | sha1sum'] <ISO>: iso, <DEF>: localized-definition )
146+
) split: [' '], first.
147+
>> fname := shasum + ['.html'].
148+
149+
150+
>> chapter := Dict new
151+
name: shasum,
152+
definition: localized-definition,
153+
example: localized-example,
154+
result: localized-result.
155+
156+
book at: iso, append: chapter.
157+
158+
Out write: book, stop.
159+
Out write: languages, stop.
160+
Out write: i, stop.
161+
162+
(first) true: {
163+
language-index append:
164+
['<a href="'] + fname + ['">'] + iso + ['</a>'].
165+
}.
166+
167+
Out write: language-index, stop.
168+
169+
170+
171+
172+
#Program end.
173+
True break.
174+
}.
175+
176+
first := False.
177+
178+
}.
179+
180+
181+
182+
book each: { :iso :chapters
183+
184+
>> indexhtml := [''].
185+
186+
chapters each: { :_ :chapter
187+
indexhtml append: ['<a href="'] + chapter name + ['.html">'] + chapter definition + ['</a>'].
188+
}.
189+
190+
chapters each: { :k :chapter
191+
192+
>> page := template copy.
193+
194+
page
195+
replace: ['{{title}}'] with: chapter definition,
196+
replace: ['{{language}}'] with: iso,
197+
replace: ['{{example}}'] with: chapter example,
198+
replace: ['{{result}}'] with: chapter result,
199+
replace: ['{{languages}}'] with: language-index,
200+
replace: ['{{index}}'] with: indexhtml.
201+
202+
203+
Out write: page, stop.
204+
}.
205+
206+
}.
207+
208+
Out write: book, stop.

misc/docs/example.tpl.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="🠶taal">
3+
<head>
4+
<title>{{title}}</title>
5+
<meta charset="UTF-8">
6+
<meta name="author" content="Gabor de Mooij">
7+
<meta name="viewport" content="initial-scale=1.0,width=device-width" >
8+
<link rel="stylesheet" href="/css/citra.css?x=🠶tijd">
9+
<link rel="stylesheet" href="/fonts/fa/css/all.css?x=🠶tijd">
10+
</head>
11+
<body class="manual docs">
12+
<article>
13+
<p class="subtitle">
14+
{{language}}
15+
</p>
16+
<div id="logodiv"><a href="/"><img id="logo" src="/img/logo.png" alt="citrine"></a></div>
17+
<div class="lane3" id="manual">
18+
<h1 class="chapter">{{title}}</h1>
19+
<code>{{example}}</code>
20+
<output>{{result}}</output>
21+
<p class="doclinks">
22+
<br><br>
23+
<span class="update">{{date}}</span>
24+
</p>
25+
<hr>
26+
<ul class="chapters">
27+
{{index}}
28+
</ul>
29+
</div>
30+
<div class="lane3 white">
31+
<ul class="langs">
32+
{{languages}}
33+
</ul>
34+
</div>
35+
<footer>
36+
<p style="margin-bottom:0"><img class="footerbanner" src="/img/citrine_banner.jpg" alt=""></p>
37+
</footer>
38+
</article>
39+
</body>
40+
</html>

0 commit comments

Comments
 (0)