diff --git a/docs/generate.py b/docs/generate.py
index 537d41a3..ec5d5574 100644
--- a/docs/generate.py
+++ b/docs/generate.py
@@ -5,8 +5,6 @@ import shutil
from docs.docs_writer import DocsWriter
# Small trick so importing telethon_generator works
-from docs.generate_core import write_core_index
-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from telethon_generator.parser import TLParser, TLObject
@@ -333,8 +331,25 @@ def generate_documentation(scheme_file):
# Write the final core index, the main index for the rest of files
layer = TLParser.find_layer(scheme_file)
- with DocsWriter(original_paths['index_all'], type_to_path_function=get_path_for_type) as docs:
- write_core_index(docs, tlobjects, layer)
+ types = set()
+ methods = []
+ for tlobject in tlobjects:
+ if tlobject.is_function:
+ methods.append(tlobject)
+
+ types.add(tlobject.result)
+
+ replace_dict = {
+ 'type_count': len(types),
+ 'method_count': len(methods),
+ 'constructor_count': len(methods) - len(tlobjects),
+ 'layer': layer
+ }
+
+ with open('../res/core.html') as infile:
+ with open(original_paths['index_all'], 'w') as outfile:
+ outfile.write(infile.read()
+ .format_map(replace_dict))
# Everything done
print('Documentation generated.')
@@ -344,8 +359,8 @@ def copy_resources():
for d in ['css', 'img']:
os.makedirs(d, exist_ok=True)
- shutil.copy('../res/arrow.svg', 'img')
- shutil.copy('../res/docs.css', 'css')
+ shutil.copy('../res/img/arrow.svg', 'img')
+ shutil.copy('../res/css/docs.css', 'css')
if __name__ == '__main__':
diff --git a/docs/generate_core.py b/docs/generate_core.py
deleted file mode 100644
index 7212b288..00000000
--- a/docs/generate_core.py
+++ /dev/null
@@ -1,172 +0,0 @@
-def write_core_index(docs, tlobjects, layer):
- # Determine method, types and constructors count
- types = set()
- method_count = 0
- constructor_count = 0
- for tlobject in tlobjects:
- if tlobject.is_function:
- method_count += 1
- else:
- constructor_count += 1
-
- types.add(tlobject.result)
-
- type_count = len(types)
- types.clear()
-
- # Write the head and the full HTML
- docs.write_head('Telethon API', relative_css_path='css/docs.css')
-
- # Welcome text, small explanation about this page
- docs.write('''
Telethon API
-
This documentation was generated straight from the scheme.tl
-provided by Telegram. However, there is no official documentation per se
-on what the methods, constructors and types mean. Nevertheless, this
-page aims to provide easy access to all the available methods, their
-definition and parameters.
-
-
Although this documentation was generated for Telethon, it may
-be useful for any other Telegram library out there.
'''
-
- # Methods section
- '''
Methods
-
Currently there are {methodcount} methods available for the layer
-{layer}. The complete list can be seen here.
-
-To invoke any of these methods (also called requests), you can do
-as shown on the following example:
'''
-
- # Example usage for the methods
- '''
#!/usr/bin/python3
-from telethon import TelegramClient
-from telethon.tl.functions.messages import GetHistoryRequest
-from telethon.utils import get_input_peer
-
-# Use your own values here
-api_id = 12345
-api_hash = '0123456789abcdef0123456789abcdef'
-phone_number = '+34600000000'
-
-# Create the client and connect
-client = TelegramClient('username', api_id, api_hash)
-client.connect()
-
-# Ensure you're authorized
-if not client.is_user_authorized():
- client.send_code_request(phone)
- client.sign_in(phone, input('Enter the code: '))
-
-# Using built-in methods
-dialogs, entities = client.get_dialogs(10)
-entity = entities[0]
-
-# !! Invoking a request manually !!
-result = client.invoke(
- GetHistoryRequest(
- get_input_peer(entity),
- limit=20,
- offset_date=None,
- offset_id=0,
- max_id=0,
- min_id=0,
- add_offset=0))
-
-# Now you have access to the first 20 messages
-messages = result.messages
'''
-
- # Example end
- '''
As you can see, manually invoking requests with client.invoke()
-is way more verbose than using the built-in methods. However, and given
-that there are so many methods available, it's impossible to provide a nice
-interface to things that may change over time. To get full access, however,
-you're still able to invoke these methods manually.
'''
-
- # Types section
- '''
Types
-
Currently there are {typecount} types. You can see the full
-list here.
-
-
The Telegram types are the abstract results that you receive
-after invoking a request. They are "abstract" because they can have
-multiple constructors. For instance, the abstract type User
-can be either UserEmpty or User. You should,
-most of the time, make sure you received the desired type by using
-the isinstance(result, Constructor) Python function.
-
-When a request needs a Telegram type as argument, you should create
-an instance of it by using one of its, possibly multiple, constructors.
'''
-
- # Constructors section
- '''
Constructors
-
Currently there are {constructorcount} constructors. You can see
-the full list here.
-
-
Constructors are the way you can create instances of the abstract types
-described above, and also the instances which are actually returned from
-the functions although they all share a common abstract type.
'''
-
- # Core types section
- '''
Core types
-
Core types are types from which the rest of Telegram types build upon:
-
-
int:
- The value should be an integer type, like 42.
- It should have 32 bits or less. You can check the bit length by
- calling a.bit_length(), where a is an
- integer variable.
-
-
long:
- Different name for an integer type. The numbers given should have
- 64 bits or less.
-
-
int128:
- Another integer type, should have 128 bits or less.
-
-
int256:
- The largest integer type, allowing 256 bits or less.
-
-
-
double:
- The value should be a floating point value, such as
- 123.456.
-
-
-
Vector<T>:
- If a type T is wrapped around Vector<T>,
- then it means that the argument should be a list of it.
- For instance, a valid value for Vector<int>
- would be [1, 2, 3].
-
-
-
string:
- A valid UTF-8 string should be supplied. This is right how
- Python strings work, no further encoding is required.
-
-
-
Bool:
- Either True or False.
-
-
-
true:
- These arguments aren't actually sent but rather encoded as flags.
- Any truthy value (True, 7) will enable
- this flag, although it's recommended to use True or
- None to symbolize that it's not present.
-
-
-
bytes:
- A sequence of bytes, like b'hello', should be supplied.
-
-
-
date:
- Although this type is internally used as an int,
- you can pass a datetime object instead to work
- with date parameters.
-
This documentation was generated straight from the scheme.tl
+ provided by Telegram. However, there is no official documentation per se
+ on what the methods, constructors and types mean. Nevertheless, this
+ page aims to provide easy access to all the available methods, their
+ definition and parameters.
+
+
Although this documentation was generated for Telethon, it may
+ be useful for any other Telegram library out there.
Methods
+
Currently there are {method_count} methods available for the layer
+ {layer}. The complete list can be seen here.
+
+ To invoke any of these methods (also called requests), you can do
+ as shown on the following example:
+
#!/usr/bin/python3
+from telethon import TelegramClient
+from telethon.tl.functions.messages import GetHistoryRequest
+from telethon.utils import get_input_peer
+
+# Use your own values here
+api_id = 12345
+api_hash = '0123456789abcdef0123456789abcdef'
+phone_number = '+34600000000'
+
+# Create the client and connect
+client = TelegramClient('username', api_id, api_hash)
+client.connect()
+
+# Ensure you're authorized
+if not client.is_user_authorized():
+ client.send_code_request(phone)
+ client.sign_in(phone, input('Enter the code: '))
+
+# Using built-in methods
+dialogs, entities = client.get_dialogs(10)
+entity = entities[0]
+
+# !! Invoking a request manually !!
+result = client.invoke(
+ GetHistoryRequest(
+ get_input_peer(entity),
+ limit=20,
+ offset_date=None,
+ offset_id=0,
+ max_id=0,
+ min_id=0,
+ add_offset=0))
+
+# Now you have access to the first 20 messages
+messages = result.messages
+
+
As you can see, manually invoking requests with client.invoke()
+ is way more verbose than using the built-in methods. However, and given
+ that there are so many methods available, it's impossible to provide a nice
+ interface to things that may change over time. To get full access, however,
+ you're still able to invoke these methods manually.
+
+
Types
+
Currently there are {type_count} types. You can see the full
+ list here.
+
+
The Telegram types are the abstract results that you receive
+ after invoking a request. They are "abstract" because they can have
+ multiple constructors. For instance, the abstract type User
+ can be either UserEmpty or User. You should,
+ most of the time, make sure you received the desired type by using
+ the isinstance(result, Constructor) Python function.
+
+ When a request needs a Telegram type as argument, you should create
+ an instance of it by using one of its, possibly multiple, constructors.
+
+
Constructors
+
Currently there are {constructor_count} constructors. You can see
+ the full list here.
+
+
Constructors are the way you can create instances of the abstract types
+ described above, and also the instances which are actually returned from
+ the functions although they all share a common abstract type.
+
+
Core types
+
Core types are types from which the rest of Telegram types build upon:
+
+
int:
+ The value should be an integer type, like 42.
+ It should have 32 bits or less. You can check the bit length by
+ calling a.bit_length(), where a is an
+ integer variable.
+
+
long:
+ Different name for an integer type. The numbers given should have
+ 64 bits or less.
+
+
int128:
+ Another integer type, should have 128 bits or less.
+
+
int256:
+ The largest integer type, allowing 256 bits or less.
+
+
double:
+ The value should be a floating point value, such as
+ 123.456.
+
+
Vector<T>:
+ If a type T is wrapped around Vector<T>,
+ then it means that the argument should be a list of it.
+ For instance, a valid value for Vector<int>
+ would be [1, 2, 3].
+
+
string:
+ A valid UTF-8 string should be supplied. This is right how
+ Python strings work, no further encoding is required.
+
+
Bool:
+ Either True or False.
+
+
true:
+ These arguments aren't actually sent but rather encoded as flags.
+ Any truthy value (True, 7) will enable
+ this flag, although it's recommended to use True or
+ None to symbolize that it's not present.
+
+
bytes:
+ A sequence of bytes, like b'hello', should be supplied.
+
+
date:
+ Although this type is internally used as an int,
+ you can pass a datetime object instead to work
+ with date parameters.
+
+
+
+
+
diff --git a/docs/res/docs.css b/docs/res/css/docs.css
similarity index 100%
rename from docs/res/docs.css
rename to docs/res/css/docs.css
diff --git a/docs/res/arrow.svg b/docs/res/img/arrow.svg
similarity index 100%
rename from docs/res/arrow.svg
rename to docs/res/img/arrow.svg