mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 10:53:44 +03:00
Let constructors be searched on the docs, and allow collapsing types
This commit is contained in:
parent
5061e22c66
commit
4563875ab5
|
@ -433,20 +433,26 @@ def generate_documentation(scheme_file):
|
|||
layer = TLParser.find_layer(scheme_file)
|
||||
types = set()
|
||||
methods = []
|
||||
constructors = []
|
||||
for tlobject in tlobjects:
|
||||
if tlobject.is_function:
|
||||
methods.append(tlobject)
|
||||
else:
|
||||
constructors.append(tlobject)
|
||||
|
||||
types.add(tlobject.result)
|
||||
|
||||
types = sorted(types)
|
||||
methods = sorted(methods, key=lambda m: m.name)
|
||||
constructors = sorted(constructors, key=lambda c: c.name)
|
||||
|
||||
request_names = ', '.join('"' + get_class_name(m) + '"' for m in methods)
|
||||
type_names = ', '.join('"' + get_class_name(t) + '"' for t in types)
|
||||
constructor_names = ', '.join('"' + get_class_name(t) + '"' for t in constructors)
|
||||
|
||||
request_urls = ', '.join('"' + get_create_path_for(m) + '"' for m in methods)
|
||||
type_urls = ', '.join('"' + get_path_for_type(t) + '"' for t in types)
|
||||
constructor_urls = ', '.join('"' + get_create_path_for(t) + '"' for t in constructors)
|
||||
|
||||
replace_dict = {
|
||||
'type_count': len(types),
|
||||
|
@ -456,8 +462,10 @@ def generate_documentation(scheme_file):
|
|||
|
||||
'request_names': request_names,
|
||||
'type_names': type_names,
|
||||
'constructor_names': constructor_names,
|
||||
'request_urls': request_urls,
|
||||
'type_urls': type_urls
|
||||
'type_urls': type_urls,
|
||||
'constructor_urls': constructor_urls
|
||||
}
|
||||
|
||||
with open('../res/core.html') as infile:
|
||||
|
|
|
@ -19,7 +19,21 @@
|
|||
placeholder="Search for requests and types…" />
|
||||
|
||||
<div id="searchDiv">
|
||||
<table id="searchTable"></table>
|
||||
|
||||
<details open><summary class="title">Methods (<span id="methodsCount">0</span>)</summary>
|
||||
<ul id="methodsList" class="together">
|
||||
</ul>
|
||||
</details>
|
||||
|
||||
<details open><summary class="title">Types (<span id="typesCount">0</span>)</summary>
|
||||
<ul id="typesList" class="together">
|
||||
</ul>
|
||||
</details>
|
||||
|
||||
<details><summary class="title">Constructors (<span id="constructorsCount">0</span>)</summary>
|
||||
<ul id="constructorsList" class="together">
|
||||
</ul>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<div id="contentDiv">
|
||||
|
@ -196,19 +210,65 @@ messages = result.messages</pre>
|
|||
contentDiv = document.getElementById("contentDiv");
|
||||
searchDiv = document.getElementById("searchDiv");
|
||||
searchBox = document.getElementById("searchBox");
|
||||
searchTable = document.getElementById("searchTable");
|
||||
|
||||
// Search lists
|
||||
methodsList = document.getElementById("methodsList");
|
||||
methodsCount = document.getElementById("methodsCount");
|
||||
|
||||
typesList = document.getElementById("typesList");
|
||||
typesCount = document.getElementById("typesCount");
|
||||
|
||||
constructorsList = document.getElementById("constructorsList");
|
||||
constructorsCount = document.getElementById("constructorsCount");
|
||||
|
||||
try {
|
||||
requests = [{request_names}];
|
||||
types = [{type_names}];
|
||||
constructors = [{constructor_names}];
|
||||
|
||||
requestsu = [{request_urls}];
|
||||
typesu = [{type_urls}];
|
||||
constructorsu = [{constructor_urls}];
|
||||
} catch (e) {
|
||||
requests = [];
|
||||
types = [];
|
||||
requetsu = [];
|
||||
constructors = [];
|
||||
requestsu = [];
|
||||
typesu = [];
|
||||
constructorsu = [];
|
||||
}
|
||||
|
||||
// Given two input arrays "original" and "original urls" and a query,
|
||||
// return a pair of arrays with matching "query" elements from "original".
|
||||
//
|
||||
// TODO Perhaps return an array of pairs instead a pair of arrays (for cache).
|
||||
function getSearchArray(original, originalu, query) {
|
||||
var destination = [];
|
||||
var destinationu = [];
|
||||
|
||||
for (var i = 0; i < original.length; ++i) {
|
||||
if (original[i].toLowerCase().indexOf(query) != -1) {
|
||||
destination.push(original[i]);
|
||||
destinationu.push(originalu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return [destination, destinationu];
|
||||
}
|
||||
|
||||
// Modify "countSpan" and "resultList" accordingly based on the elements
|
||||
// given as [[elements], [element urls]] (both with the same length)
|
||||
function buildList(countSpan, resultList, foundElements) {
|
||||
var result = "";
|
||||
for (var i = 0; i < foundElements[0].length; ++i) {
|
||||
result += '<li>';
|
||||
result += '<a href="' + foundElements[1][i] + '">';
|
||||
result += foundElements[0][i];
|
||||
result += '</a></li>';
|
||||
}
|
||||
|
||||
countSpan.innerHTML = "" + foundElements[0].length;
|
||||
resultList.innerHTML = result;
|
||||
}
|
||||
|
||||
function updateSearch() {
|
||||
|
@ -217,46 +277,16 @@ function updateSearch() {
|
|||
searchDiv.style.display = "";
|
||||
|
||||
var query = searchBox.value.toLowerCase();
|
||||
var foundRequests = [];
|
||||
var foundRequestsu = [];
|
||||
for (var i = 0; i < requests.length; ++i) {
|
||||
if (requests[i].toLowerCase().indexOf(query) != -1) {
|
||||
foundRequests.push(requests[i]);
|
||||
foundRequestsu.push(requestsu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var foundTypes = [];
|
||||
var foundTypesu = [];
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
if (types[i].toLowerCase().indexOf(query) != -1) {
|
||||
foundTypes.push(types[i]);
|
||||
foundTypesu.push(typesu[i]);
|
||||
}
|
||||
}
|
||||
var foundRequests = getSearchArray(requests, requestsu, query);
|
||||
var foundTypes = getSearchArray(types, typesu, query);
|
||||
var foundConstructors = getSearchArray(
|
||||
constructors, constructorsu, query
|
||||
);
|
||||
|
||||
var top = foundRequests.length > foundTypes.length ?
|
||||
foundRequests.length : foundTypes.length;
|
||||
|
||||
result = "";
|
||||
for (var i = 0; i <= top; ++i) {
|
||||
result += "<tr><td>";
|
||||
|
||||
if (i < foundRequests.length) {
|
||||
result +=
|
||||
'<a href="'+foundRequestsu[i]+'">'+foundRequests[i]+'</a>';
|
||||
}
|
||||
|
||||
result += "</td><td>";
|
||||
|
||||
if (i < foundTypes.length) {
|
||||
result +=
|
||||
'<a href="'+foundTypesu[i]+'">'+foundTypes[i]+'</a>';
|
||||
}
|
||||
|
||||
result += "</td></tr>";
|
||||
}
|
||||
searchTable.innerHTML = result;
|
||||
buildList(methodsCount, methodsList, foundRequests);
|
||||
buildList(typesCount, typesList, foundTypes);
|
||||
buildList(constructorsCount, constructorsList, foundConstructors);
|
||||
} else {
|
||||
contentDiv.style.display = "";
|
||||
searchDiv.style.display = "none";
|
||||
|
|
|
@ -52,7 +52,7 @@ table td {
|
|||
margin: 0 8px -2px 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
h1, summary.title {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
|
@ -137,6 +137,26 @@ button:hover {
|
|||
color: #fff;
|
||||
}
|
||||
|
||||
/* https://www.w3schools.com/css/css_navbar.asp */
|
||||
ul.together {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
ul.together li {
|
||||
float: left;
|
||||
}
|
||||
|
||||
ul.together li a {
|
||||
display: block;
|
||||
border-radius: 8px;
|
||||
background: #f0f4f8;
|
||||
padding: 4px 8px;
|
||||
margin: 8px;
|
||||
}
|
||||
|
||||
/* https://stackoverflow.com/a/30810322 */
|
||||
.invisible {
|
||||
left: 0;
|
||||
|
@ -153,7 +173,7 @@ button:hover {
|
|||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
h1 {
|
||||
h1, summary.title {
|
||||
font-size: 18px;
|
||||
}
|
||||
h3 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user