1818
1919import ast
2020import os
21+ import re
2122import shutil
2223
2324HOME = "compiler/docs"
2930FUNCTIONS_BASE = "functions"
3031TYPES_BASE = "types"
3132
32- shutil .rmtree (TYPES_BASE , ignore_errors = True )
33- shutil .rmtree (FUNCTIONS_BASE , ignore_errors = True )
33+
34+ def snek (s : str ):
35+ s = re .sub (r"(.)([A-Z][a-z]+)" , r"\1_\2" , s )
36+ return re .sub (r"([a-z0-9])([A-Z])" , r"\1_\2" , s ).lower ()
3437
3538
3639def generate (source_path , base ):
@@ -50,9 +53,11 @@ def build(path, level=0):
5053 for node in ast .walk (p ):
5154 if isinstance (node , ast .ClassDef ):
5255 name = node .name
56+ break
57+ else :
58+ continue
5359
54- # name = "".join([str(j.title()) for j in os.path.splitext(i)[0].split("_")])
55- full_path = os .path .basename (path ) + "/" + name + ".rst"
60+ full_path = os .path .basename (path ) + "/" + snek (name ).replace ("_" , "-" ) + ".rst"
5661
5762 if level :
5863 full_path = base + "/" + full_path
@@ -65,7 +70,7 @@ def build(path, level=0):
6570 title = name ,
6671 title_markup = "=" * len (name ),
6772 full_class_path = "pyrogram.api.{}" .format (
68- os . path . splitext (full_path )[ 0 ]. replace ("/" , "." )
73+ "." . join (full_path . split ("/" )[: - 1 ]) + "." + name
6974 )
7075 )
7176 )
@@ -82,7 +87,7 @@ def build(path, level=0):
8287 entities = []
8388
8489 for i in v :
85- entities .append (i )
90+ entities .append (snek ( i ). replace ( "_" , "-" ) )
8691
8792 if k != base :
8893 inner_path = base + "/" + k + "/index" + ".rst"
@@ -98,6 +103,7 @@ def build(path, level=0):
98103 with open (DESTINATION + "/" + inner_path , "w" , encoding = "utf-8" ) as f :
99104 if k == base :
100105 f .write (":tocdepth: 1\n \n " )
106+ k = "Raw " + k
101107
102108 f .write (
103109 toctree .format (
@@ -115,6 +121,8 @@ def start():
115121 global page_template
116122 global toctree
117123
124+ shutil .rmtree (DESTINATION , ignore_errors = True )
125+
118126 with open (HOME + "/template/page.txt" , encoding = "utf-8" ) as f :
119127 page_template = f .read ()
120128
0 commit comments