--- a/src/eric7/DocumentationTools/IndexGenerator.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/DocumentationTools/IndexGenerator.py Wed Jul 13 14:55:47 2022 +0200 @@ -21,27 +21,24 @@ Class implementing the index generator for the builtin documentation generator. """ + def __init__(self, outputDir): """ Constructor - + @param outputDir The output directory for the files @type str """ self.outputDir = outputDir self.packages = { - "00index": { - "description": "", - "subpackages": {}, - "modules": {} - } + "00index": {"description": "", "subpackages": {}, "modules": {}} } self.remembered = False - + def remember(self, file, moduleDocument, basename=""): """ Public method to remember a documentation file. - + @param file The filename to be remembered. (string) @param moduleDocument The ModuleDocument object containing the information for the file. @@ -52,7 +49,7 @@ self.remembered = True if basename: file = file.replace(basename, "") - + if "__init__" in file: dirName = os.path.dirname(file) udir = os.path.dirname(dirName) @@ -66,28 +63,27 @@ elt = self.packages["00index"] package = dirName.replace(os.sep, ".") elt["subpackages"][package] = moduleDocument.shortDescription() - + self.packages[package] = { "description": moduleDocument.description(), "subpackages": {}, - "modules": {} + "modules": {}, } - + if moduleDocument.isEmpty(): return - + package = os.path.dirname(file).replace(os.sep, ".") try: elt = self.packages[package] except KeyError: elt = self.packages["00index"] - elt["modules"][moduleDocument.name()] = ( - moduleDocument.shortDescription()) - + elt["modules"][moduleDocument.name()] = moduleDocument.shortDescription() + def __writeIndex(self, packagename, package, newline=None): """ Private method to generate an index file for a package. - + @param packagename The name of the package. (string) @param package A dictionary with information about the package. @param newline newline character to be used (string) @@ -99,12 +95,12 @@ else: f = os.path.join(self.outputDir, "index-{0}".format(packagename)) title = packagename - + filename = joinext(f, ".html") - + subpackages = "" modules = "" - + # 1) subpackages if package["subpackages"]: subpacks = package["subpackages"] @@ -113,18 +109,20 @@ for name in names: link = joinext("index-{0}".format(name), ".html") lst.append( - TemplatesListsStyleCSS.indexListEntryTemplate.format(**{ - "Description": subpacks[name], - "Name": name.split(".")[-1], - "Link": link, - }) + TemplatesListsStyleCSS.indexListEntryTemplate.format( + **{ + "Description": subpacks[name], + "Name": name.split(".")[-1], + "Link": link, + } + ) ) - subpackages = ( - TemplatesListsStyleCSS.indexListPackagesTemplate.format(**{ + subpackages = TemplatesListsStyleCSS.indexListPackagesTemplate.format( + **{ "Entries": "".join(lst), - }) + } ) - + # 2) modules if package["modules"]: mods = package["modules"] @@ -136,38 +134,42 @@ if nam == "__init__": nam = name.split(".")[-2] lst.append( - TemplatesListsStyleCSS.indexListEntryTemplate.format(**{ - "Description": mods[name], - "Name": nam, - "Link": link, - }) + TemplatesListsStyleCSS.indexListEntryTemplate.format( + **{ + "Description": mods[name], + "Name": nam, + "Link": link, + } + ) ) - modules = ( - TemplatesListsStyleCSS.indexListModulesTemplate.format(**{ + modules = TemplatesListsStyleCSS.indexListModulesTemplate.format( + **{ "Entries": "".join(lst), - }) + } ) - + doc = ( - TemplatesListsStyleCSS.headerTemplate.format( - **{"Title": title} - ) + TemplatesListsStyleCSS.indexBodyTemplate.format( - **{"Title": title, - "Description": package["description"], - "Subpackages": subpackages, - "Modules": modules} - ) + TemplatesListsStyleCSS.footerTemplate + TemplatesListsStyleCSS.headerTemplate.format(**{"Title": title}) + + TemplatesListsStyleCSS.indexBodyTemplate.format( + **{ + "Title": title, + "Description": package["description"], + "Subpackages": subpackages, + "Modules": modules, + } + ) + + TemplatesListsStyleCSS.footerTemplate ) - + with open(filename, "w", encoding="utf-8", newline=newline) as f: f.write(doc) - + return filename - + def writeIndices(self, basename="", newline=None): """ Public method to generate all index files. - + @param basename The basename of the file hierarchy to be documented. The basename is stripped off the filename if it starts with the basename. @@ -176,7 +178,7 @@ if not self.remembered: sys.stderr.write("No index to generate.\n") return - + if basename: basename = basename.replace(os.sep, ".") if not basename.endswith("."): @@ -191,7 +193,7 @@ else: if out: sys.stdout.write("{0} ok\n".format(out)) - + sys.stdout.write("Indices written.\n") sys.stdout.flush() sys.stderr.flush()