chiark / gitweb /
documentation/python: save URLs of crawled classes, modules and pages.
authorVladimír Vondruš <mosra@centrum.cz>
Wed, 17 Jul 2019 17:55:40 +0000 (19:55 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 18 Jul 2019 11:34:34 +0000 (13:34 +0200)
Makes link creation much simpler later.

documentation/python.py

index e6436e1b8681e476e2e448c1be788acc5a37f697..dd67fe4f2db41be23278550007672f53816842d0 100755 (executable)
@@ -285,6 +285,7 @@ def crawl_class(state: State, path: List[str], class_):
     class_entry.type = EntryType.CLASS
     class_entry.object = class_
     class_entry.path = path
+    class_entry.url = state.config['URL_FORMATTER'](EntryType.CLASS, path)[1]
     class_entry.members = []
 
     for name, object in inspect.getmembers(class_):
@@ -350,6 +351,7 @@ def crawl_module(state: State, path: List[str], module) -> List[Tuple[List[str],
     module_entry.type = EntryType.MODULE
     module_entry.object = module
     module_entry.path = path
+    module_entry.url = state.config['URL_FORMATTER'](EntryType.MODULE, path)[1]
     module_entry.members = []
 
     # This gets returned to ensure the modules get processed in a breadth-first
@@ -553,17 +555,15 @@ def make_name_link(state: State, referrer_path: List[str], type) -> str:
 
     # Format the URL
     if entry.type == EntryType.CLASS:
-        url = state.config['URL_FORMATTER'](entry.type, entry.path)[1]
+        url = entry.url
     else:
         if entry.type == EntryType.ENUM:
             parent_index = -1
         else:
             assert entry.type == EntryType.ENUM_VALUE
             parent_index = -2
-        parent_entry = state.name_map['.'.join(entry.path[:parent_index])]
-        url = '{}#{}'.format(
-            state.config['URL_FORMATTER'](parent_entry.type, parent_entry.path)[1],
-            state.config['ID_FORMATTER'](entry.type, entry.path[parent_index:]))
+        parent_url = state.name_map['.'.join(entry.path[:parent_index])].url
+        url = '{}#{}'.format(parent_url, state.config['ID_FORMATTER'](entry.type, entry.path[parent_index:]))
 
     return '<a href="{}" class="m-doc">{}</a>'.format(url, '.'.join(shortened_path))
 
@@ -1616,6 +1616,7 @@ def run(basedir, config, templates):
         entry = Empty()
         entry.type = EntryType.PAGE
         entry.path = [page_name]
+        entry.url = config['URL_FORMATTER'](EntryType.PAGE, [page_name])[1]
         entry.filename = os.path.join(config['INPUT'], page)
         state.name_map[page_name] = entry