-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-docs.lua
executable file
·46 lines (32 loc) · 1.01 KB
/
gen-docs.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local nldoc = require 'nldoc'
local symbol_template = [[
### $(name)
```lua
$(code)
```
$(text)
]]
local function doc(filename, path, docs_path)
local emitter = nldoc.Emitter.create()
if string.find(filename, '.nelua') then
print('documenting '..path..filename..'..')
nldoc.generate_doc(emitter, path..filename, { symbol_template = symbol_template })
local emitted = emitter:generate()
local summary = {'### Summary\n'}
for title in emitted:gmatch('### ([%s%g]-)\n') do
local title_link = title:lower():gsub('[%.%:]', '')
table.insert(summary, string.format('* [%s](#%s)\n', title, title_link))
end
local outfilename = filename:gsub('.nelua', '.md')
nldoc.write_file('docs/'..docs_path..outfilename, table.concat(summary)..'\n'..emitted)
end
end
local function doc_dir(dirname, docs_dir)
local ignored_files = {}
for filename in lfs.dir(dirname) do
if not ignored_files[filename] then
doc(filename, dirname, docs_dir)
end
end
end
doc_dir('rotor/', '')