diff --git a/docs/docs_writer.py b/docs/docs_writer.py index 29bc2be4..202557ac 100644 --- a/docs/docs_writer.py +++ b/docs/docs_writer.py @@ -24,6 +24,7 @@ class DocsWriter: self.menu_began = False self.table_columns = 0 self.table_columns_left = None + self.write_copy_script = False # High level writing def write_head(self, title, relative_css_path): @@ -232,8 +233,27 @@ class DocsWriter: self.write(text) self.write('

') + def write_copy_button(self, text, text_to_copy): + """Writes a button with 'text' which can be used + to copy 'text_to_copy' to clipboard when it's clicked.""" + self.write_copy_script = True + self.write('' + .format(text_to_copy, text)) + def end_body(self): """Ends the whole document. This should be called the last""" + if self.write_copy_script: + self.write( + '' + '') + self.write('') # "Low" level writing diff --git a/docs/generate.py b/docs/generate.py index ff95ed4b..d9960aec 100755 --- a/docs/generate.py +++ b/docs/generate.py @@ -49,6 +49,15 @@ def get_file_name(tlobject, add_extension=False): return result +# TLObject -> from ... import ... +def get_import_code(tlobject): + kind = 'functions' if tlobject.is_function else 'types' + ns = '.' + tlobject.namespace if tlobject.namespace else '' + + return 'from telethon.tl.{}{} import {}'\ + .format(kind, ns, get_class_name(tlobject)) + + def get_create_path_for(tlobject): """Gets the file path (and creates the parent directories) for the given 'tlobject', relative to nothing; only its local path""" @@ -229,6 +238,8 @@ def generate_documentation(scheme_file): # Write the code definition for this TLObject docs.write_code(tlobject) + docs.write_copy_button('Copy import to the clipboard', + get_import_code(tlobject)) # Write the return type (or constructors belonging to the same type) docs.write_title('Returns' if tlobject.is_function diff --git a/docs/res/css/docs.css b/docs/res/css/docs.css index e41e5da8..9a9b710b 100644 --- a/docs/res/css/docs.css +++ b/docs/res/css/docs.css @@ -122,6 +122,36 @@ span.sh4 { font-style: italic; } +button { + border-radius: 2px; + font-size: 16px; + padding: 8px; + color: #000; + background-color: #fff; + border: 2px solid #42aaed; + transition-duration: 300ms; +} + +button:hover { + background-color: #42aaed; + color: #fff; +} + +/* https://stackoverflow.com/a/30810322 */ +.invisible { + left: 0; + top: -99px; + padding: 0; + width: 2em; + height: 2em; + border: none; + outline: none; + position: fixed; + box-shadow: none; + color: transparent; + background: transparent; +} + @media (max-width: 640px) { h1 { font-size: 18px;