diff --git a/telethon_generator/docs_writer.py b/telethon_generator/docs_writer.py index 0cdd6e67..1e248341 100644 --- a/telethon_generator/docs_writer.py +++ b/telethon_generator/docs_writer.py @@ -35,34 +35,28 @@ class DocsWriter: """Writes the head part for the generated document, with the given title and CSS """ - self.write(''' + self.write( + ''' - ''') - - self.write(title) - - self.write(''' + {title} - + - + -
''') +
''', + title=title, + rel_css=relative_css_path.rstrip('/'), + def_css=default_css + ) def set_menu_separator(self, relative_image_path): """Sets the menu separator. @@ -86,9 +80,7 @@ class DocsWriter: self.write('
  • ') if link: - self.write('') + self.write('', link) # Write the real menu entry text self.write(name) @@ -107,26 +99,21 @@ class DocsWriter: """Writes a title header in the document body, with an optional depth level """ - self.write('' % level) - self.write(title) - self.write('' % level) + self.write('{title}', title=title, level=level) def write_code(self, tlobject): """Writes the code for the given 'tlobject' properly formatted with hyperlinks """ - self.write('
    ---')
    -        self.write('functions' if tlobject.is_function else 'types')
    -        self.write('---\n')
    +        self.write('
    ---{}---\n',
    +                   'functions' if tlobject.is_function else 'types')
     
             # Write the function or type and its ID
             if tlobject.namespace:
                 self.write(tlobject.namespace)
                 self.write('.')
     
    -        self.write(tlobject.name)
    -        self.write('#')
    -        self.write(hex(tlobject.id)[2:].rjust(8, '0'))
    +        self.write('{}#{:08x}', tlobject.name, tlobject.id)
     
             # Write all the arguments (or do nothing if there's none)
             for arg in tlobject.args:
    @@ -143,20 +130,19 @@ class DocsWriter:
     
                 # "Opening" modifiers
                 if arg.is_flag:
    -                self.write('flags.%d?' % arg.flag_index)
    +                self.write('flags.{}?', arg.flag_index)
     
                 if arg.is_generic:
                     self.write('!')
     
                 if arg.is_vector:
    -                self.write(
    -                    'Vector<' % self.type_to_path('vector')
    -                )
    +                self.write('Vector<',
    +                           self.type_to_path('vector'))
     
                 # Argument type
                 if arg.type:
                     if add_link:
    -                    self.write('' % self.type_to_path(arg.type))
    +                    self.write('', self.type_to_path(arg.type))
                     self.write(arg.type)
                     if add_link:
                         self.write('')
    @@ -185,19 +171,14 @@ class DocsWriter:
                     # use a lower type name for it (see #81)
                     vector, inner = tlobject.result.split('<')
                     inner = inner.strip('>')
    -                self.write('%s<' % vector)
    +                self.write('{}<',
    +                           self.type_to_path(vector), vector)
     
    -                self.write('%s' % inner)
    -
    -                self.write('>')
    +                self.write('{}>',
    +                           self.type_to_path(inner), inner)
                 else:
    -                self.write('%s' % tlobject.result)
    +                self.write('{}',
    +                           self.type_to_path(tlobject.result), tlobject.result)
     
             self.write('
    ') @@ -218,17 +199,13 @@ class DocsWriter: self.write('') if bold: self.write('') if link: - self.write('') + self.write('', link) # Finally write the real table data, the given text self.write(text) @@ -253,9 +230,7 @@ class DocsWriter: def write_text(self, text): """Writes a paragraph of text""" - self.write('

    ') - self.write(text) - self.write('

    ') + self.write('

    {}

    ', text) def write_copy_button(self, text, text_to_copy): """Writes a button with 'text' which can be used @@ -282,16 +257,18 @@ class DocsWriter: 'c.select();' 'try{document.execCommand("copy")}' 'catch(e){}}' - '') + '' + ) - self.write('
  • ') - self.write(self._script) - self.write('') + self.write('
    {}', self._script) # "Low" level writing - def write(self, s): + def write(self, s, *args, **kwargs): """Wrapper around handle.write""" - self.handle.write(s) + if args or kwargs: + self.handle.write(s.format(*args, **kwargs)) + else: + self.handle.write(s) # With block def __enter__(self): diff --git a/telethon_generator/generators/docs.py b/telethon_generator/generators/docs.py index 961712c7..745186b7 100755 --- a/telethon_generator/generators/docs.py +++ b/telethon_generator/generators/docs.py @@ -210,7 +210,6 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir): # TODO Tried using 'defaultdict(list)' with strange results, make it work. original_paths = { 'css': 'css', - 'default_css': 'docs.light.css', 'arrow': 'img/arrow.svg', 'search.js': 'js/search.js', '404': '404.html', @@ -222,6 +221,7 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir): original_paths = {k: os.path.join(output_dir, v) for k, v in original_paths.items()} + original_paths['default_css'] = 'light' # docs..css, local path type_to_constructors = {} type_to_functions = {} for tlobject in tlobjects: