-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
mkapi
executable file
·60 lines (52 loc) · 1.69 KB
/
mkapi
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
import os
print('''
Public API for gopher.vim. This is not stable yet!
This file is generated using the mkapi script
''')
for root, dirs, files in os.walk('autoload'):
for file in files:
if file.endswith('_test.vim'):
continue
with open('{}/{}'.format(root, file)) as fp:
lines = fp.readlines()
# allfuns[foo.vim] = [{
# doc: 'this file contians ...',
# funs: [{
# sig: 'foo#fun(a)
# doc: 'This is ...'
# }]
# }, ...]
allfuns = {}
lines.reverse()
curfun = None
curdoc = None
for line in lines:
if line.startswith('fun! gopher#'):
# "private" function
last = line.split('#').pop().split('(')[0]
if last[0] == '_' and last[-1] == '_':
continue
if allfuns.get(file, None) is None:
allfuns[file] = {'doc': ':'.join(lines[-1].split(':')[1:]).strip(), 'funs': []}
curfun = line.replace('fun! ', '').replace(' abort\n', '')
curdoc = []
elif line.startswith('" ') and curfun is not None:
curdoc.append(' ' + line[2:].strip())
elif line.strip() == '' and curfun is not None:
curdoc.reverse()
allfuns[file]['funs'].append({'fun': curfun, 'doc': '\n'.join(curdoc)})
curfun = None
curdoc = None
# TODO: order better; os.walk() isn't sorted (and neither is dict we use to
# store).
for file, funs in allfuns.items():
header = '[{}]({}/{})'.format(file, root, file)
print(header)
print('-' * len(header))
print(funs['doc'])
print()
funs['funs'].reverse()
for f in funs['funs']:
print(' {}\n{}\n'.format(f['fun'], f['doc']))
print()