mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-17 18:46:40 +00:00
Adds new docs index for methods can be used as bots (#840)
This commit is contained in:
parent
0418f7e375
commit
cea75a4365
@ -96,23 +96,37 @@ def _build_menu(docs, filename, root, relative_main_index):
|
|||||||
docs.end_menu()
|
docs.end_menu()
|
||||||
|
|
||||||
|
|
||||||
def _generate_index(folder, original_paths, root):
|
def _generate_index(folder, original_paths, root,
|
||||||
|
bots_index=False, bots_index_paths=()):
|
||||||
"""Generates the index file for the specified folder"""
|
"""Generates the index file for the specified folder"""
|
||||||
# Determine the namespaces listed here (as sub folders)
|
# Determine the namespaces listed here (as sub folders)
|
||||||
# and the files (.html files) that we should link to
|
# and the files (.html files) that we should link to
|
||||||
namespaces = []
|
namespaces = []
|
||||||
files = []
|
files = []
|
||||||
|
INDEX = 'index.html'
|
||||||
|
BOT_INDEX = 'botindex.html'
|
||||||
|
|
||||||
|
if not bots_index:
|
||||||
for item in os.listdir(folder):
|
for item in os.listdir(folder):
|
||||||
if os.path.isdir(os.path.join(folder, item)):
|
if os.path.isdir(os.path.join(folder, item)):
|
||||||
namespaces.append(item)
|
namespaces.append(item)
|
||||||
elif item != 'index.html':
|
elif item not in (INDEX, BOT_INDEX):
|
||||||
|
files.append(item)
|
||||||
|
else:
|
||||||
|
# bots_index_paths should be a list of "namespace/method.html"
|
||||||
|
# or "method.html"
|
||||||
|
for item in bots_index_paths:
|
||||||
|
dirname = os.path.dirname(item)
|
||||||
|
if dirname and dirname not in namespaces:
|
||||||
|
namespaces.append(dirname)
|
||||||
|
elif not dirname and item not in (INDEX, BOT_INDEX):
|
||||||
files.append(item)
|
files.append(item)
|
||||||
|
|
||||||
paths = {k: _get_relative_path(v, folder, folder=True)
|
paths = {k: _get_relative_path(v, folder, folder=True)
|
||||||
for k, v in original_paths.items()}
|
for k, v in original_paths.items()}
|
||||||
|
|
||||||
# Now that everything is setup, write the index.html file
|
# Now that everything is setup, write the index.html file
|
||||||
filename = os.path.join(folder, 'index.html')
|
filename = os.path.join(folder, BOT_INDEX if bots_index else INDEX)
|
||||||
with DocsWriter(filename, type_to_path=_get_path_for_type) as docs:
|
with DocsWriter(filename, type_to_path=_get_path_for_type) as docs:
|
||||||
# Title should be the current folder name
|
# Title should be the current folder name
|
||||||
docs.write_head(folder.title(),
|
docs.write_head(folder.title(),
|
||||||
@ -124,16 +138,33 @@ def _generate_index(folder, original_paths, root):
|
|||||||
relative_main_index=paths['index_all'])
|
relative_main_index=paths['index_all'])
|
||||||
|
|
||||||
docs.write_title(_get_relative_path(folder, root, folder=True).title())
|
docs.write_title(_get_relative_path(folder, root, folder=True).title())
|
||||||
|
if bots_index:
|
||||||
|
docs.write_text('These are the methods that you can use as a bot. '
|
||||||
|
'Click <a href="{}">here</a> to '
|
||||||
|
'view them all.'.format(INDEX))
|
||||||
|
else:
|
||||||
|
docs.write_text('Click <a href="{}">here</a> to view the methods '
|
||||||
|
'that you can use as a bot.'.format(BOT_INDEX))
|
||||||
if namespaces:
|
if namespaces:
|
||||||
docs.write_title('Namespaces', level=3)
|
docs.write_title('Namespaces', level=3)
|
||||||
docs.begin_table(4)
|
docs.begin_table(4)
|
||||||
namespaces.sort()
|
namespaces.sort()
|
||||||
for namespace in namespaces:
|
for namespace in namespaces:
|
||||||
# For every namespace, also write the index of it
|
# For every namespace, also write the index of it
|
||||||
|
namespace_paths = []
|
||||||
|
if bots_index:
|
||||||
|
for item in bots_index_paths:
|
||||||
|
if os.path.dirname(item) == namespace:
|
||||||
|
namespace_paths.append(os.path.basename(item))
|
||||||
_generate_index(os.path.join(folder, namespace),
|
_generate_index(os.path.join(folder, namespace),
|
||||||
original_paths, root)
|
original_paths, root,
|
||||||
|
bots_index, namespace_paths)
|
||||||
|
if bots_index:
|
||||||
docs.add_row(namespace.title(),
|
docs.add_row(namespace.title(),
|
||||||
link=os.path.join(namespace, 'index.html'))
|
link=os.path.join(namespace, BOT_INDEX)
|
||||||
|
else:
|
||||||
|
docs.add_row(namespace.title(),
|
||||||
|
link=os.path.join(namespace, INDEX))
|
||||||
|
|
||||||
docs.end_table()
|
docs.end_table()
|
||||||
|
|
||||||
@ -214,6 +245,7 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
|||||||
'search.js': 'js/search.js',
|
'search.js': 'js/search.js',
|
||||||
'404': '404.html',
|
'404': '404.html',
|
||||||
'index_all': 'index.html',
|
'index_all': 'index.html',
|
||||||
|
'bot_index': 'botindex.html',
|
||||||
'index_types': 'types/index.html',
|
'index_types': 'types/index.html',
|
||||||
'index_methods': 'methods/index.html',
|
'index_methods': 'methods/index.html',
|
||||||
'index_constructors': 'constructors/index.html'
|
'index_constructors': 'constructors/index.html'
|
||||||
@ -247,6 +279,7 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
|||||||
# Since the output directory is needed everywhere partially apply it now
|
# Since the output directory is needed everywhere partially apply it now
|
||||||
create_path_for = functools.partial(_get_create_path_for, output_dir)
|
create_path_for = functools.partial(_get_create_path_for, output_dir)
|
||||||
path_for_type = functools.partial(_get_path_for_type, output_dir)
|
path_for_type = functools.partial(_get_path_for_type, output_dir)
|
||||||
|
bot_docs_paths = []
|
||||||
|
|
||||||
for tlobject in tlobjects:
|
for tlobject in tlobjects:
|
||||||
filename = create_path_for(tlobject)
|
filename = create_path_for(tlobject)
|
||||||
@ -269,6 +302,8 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
|||||||
if tlobject.is_function:
|
if tlobject.is_function:
|
||||||
docs.write_text('Bots <strong>can{}</strong> use this method.'
|
docs.write_text('Bots <strong>can{}</strong> use this method.'
|
||||||
.format("" if tlobject.bot_usable else "'t"))
|
.format("" if tlobject.bot_usable else "'t"))
|
||||||
|
if tlobject.is_function and tlobject.bot_usable:
|
||||||
|
bot_docs_paths.append(filename)
|
||||||
|
|
||||||
# Write the code definition for this TLObject
|
# Write the code definition for this TLObject
|
||||||
docs.write_code(tlobject)
|
docs.write_code(tlobject)
|
||||||
@ -383,6 +418,11 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
|||||||
docs.add_script(relative_src=paths['search.js'])
|
docs.add_script(relative_src=paths['search.js'])
|
||||||
docs.end_body()
|
docs.end_body()
|
||||||
|
|
||||||
|
temp = []
|
||||||
|
for item in bot_docs_paths:
|
||||||
|
temp.append(os.path.sep.join(item.split(os.path.sep)[2:]))
|
||||||
|
bot_docs_paths = temp
|
||||||
|
|
||||||
# Find all the available types (which are not the same as the constructors)
|
# Find all the available types (which are not the same as the constructors)
|
||||||
# Each type has a list of constructors associated to it, hence is a map
|
# Each type has a list of constructors associated to it, hence is a map
|
||||||
for t, cs in type_to_constructors.items():
|
for t, cs in type_to_constructors.items():
|
||||||
@ -510,6 +550,9 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
|||||||
_generate_index(os.path.join(output_dir, folder), original_paths,
|
_generate_index(os.path.join(output_dir, folder), original_paths,
|
||||||
output_dir)
|
output_dir)
|
||||||
|
|
||||||
|
_generate_index(os.path.join(output_dir, 'methods'), original_paths,
|
||||||
|
output_dir, True, bot_docs_paths)
|
||||||
|
|
||||||
# Write the final core index, the main index for the rest of files
|
# Write the final core index, the main index for the rest of files
|
||||||
types = set()
|
types = set()
|
||||||
methods = []
|
methods = []
|
||||||
|
Loading…
Reference in New Issue
Block a user