forked from MohammadMD1383/Actionable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocgen.py
82 lines (66 loc) · 1.84 KB
/
docgen.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/python3
import glob
import os.path
import re
from re import compile
from textwrap import dedent
from util import all_files
class Documentation:
def __init__(self, name: str, title: str, description: str, example: str):
self.name = name
self.title = title
self.description = description
self.example = example
def __str__(self):
return '\n\n'.join([
f'## {self.title}',
f'{self.description}',
'---',
'### example:',
f'{self.example}'
])
doc_pattern = compile(
r'@Documentation\(.*?title = "(.*?)".*?description = "(.*?)".*?example = """(.*?)""".*?\n\).*?class ([a-zA-Z]+)',
re.DOTALL | re.MULTILINE
)
documentations: list[Documentation] = []
def process_annotation(content: str):
for match in doc_pattern.finditer(content):
documentations.append(Documentation(
match.groups()[3],
match.groups()[0],
match.groups()[1],
dedent(match.groups()[2]).strip()
))
if __name__ == '__main__':
for file_path in all_files():
with open(file_path, 'r') as file:
process_annotation(file.read())
if not os.path.exists("docs"):
os.mkdir("docs")
else:
for file in glob.glob("docs/*"):
os.remove(file)
with open('docs/_config.yml', 'w') as config:
config.write('theme: jekyll-theme-cayman')
with open('docs/index.md', 'w') as index:
index.write('\n'.join([
'---',
'title: Actionable',
'---',
'',
'<iframe frameborder="none" width="384px" height="325px" src="https://plugins.jetbrains.com/embeddable/card/17962"></iframe>',
'',
'## Features:'
]) + '\n\n')
for doc in documentations:
file_name = f'{doc.name}.md'
index.write(f"[{doc.title}]({file_name})\n\n")
with open(f'docs/{file_name}', 'w') as file:
file.write('\n'.join([
'---',
'title: Actionable',
'---'
]) + '\n\n')
file.write(doc.__str__())
file.write('\n\n[← Back](index.md)')