diff --git a/telethon_generator/docswriter.py b/telethon_generator/docswriter.py index 595fe931..6d37d729 100644 --- a/telethon_generator/docswriter.py +++ b/telethon_generator/docswriter.py @@ -3,25 +3,25 @@ import re class DocsWriter: - """Utility class used to write the HTML files used on the documentation""" - def __init__(self, filename, type_to_path): - """Initializes the writer to the specified output file, - creating the parent directories when used if required. - - 'type_to_path_function' should be a function which, given a type - name and a named argument relative_to, returns the file path for - the specified type, relative to the given filename + """ + Utility class used to write the HTML files used on the documentation. + """ + def __init__(self, root, filename, type_to_path): """ + Initializes the writer to the specified output file, + creating the parent directories when used if required. + """ + self.root = root self.filename = filename + self._parent = str(self.filename.parent) self.handle = None + self.title = '' # Should be set before calling adding items to the menu self.menu_separator_tag = None - # Utility functions TODO There must be a better way - self.type_to_path = lambda t: type_to_path( - t, relative_to=self.filename - ) + # Utility functions + self.type_to_path = lambda t: self._rel(type_to_path(t)) # Control signals self.menu_began = False @@ -30,11 +30,20 @@ class DocsWriter: self.write_copy_script = False self._script = '' + def _rel(self, path): + """ + Get the relative path for the given path from the current + file by working around https://bugs.python.org/issue20012. + """ + return os.path.relpath(str(path), self._parent) + # High level writing - def write_head(self, title, relative_css_path, default_css): + def write_head(self, title, css_path, default_css): """Writes the head part for the generated document, with the given title and CSS """ + # + self.title = title self.write( ''' @@ -54,17 +63,17 @@ class DocsWriter: