44
55from __future__ import annotations
66
7+ import copy
78import posixpath
89from collections import ChainMap
910from pathlib import Path
10- from typing import Any , BinaryIO , Iterator , Optional , Tuple
11+ from typing import (
12+ Any ,
13+ BinaryIO ,
14+ Iterator ,
15+ Optional ,
16+ Tuple ,
17+ MutableMapping ,
18+ Dict ,
19+ Mapping ,
20+ Set ,
21+ )
1122
1223from griffe .logger import patch_loggers
1324from markdown import Markdown
@@ -53,7 +64,7 @@ def __init__(self, *, base_dir: Path, **kwargs: Any) -> None:
5364 The theme to fall back to.
5465 """
5566
56- default_config : dict = {
67+ default_config = {
5768 "show_root_heading" : False ,
5869 "show_root_toc_entry" : True ,
5970 "show_root_full_path" : True ,
@@ -126,12 +137,10 @@ def load_inventory(
126137 def render (
127138 self ,
128139 data : VbaModuleInfo ,
129- config : dict ,
140+ config : Mapping [ str , Any ] ,
130141 ) -> str :
131- final_config = ChainMap (config , self .default_config )
132- render_type = "module"
133-
134- template = self .env .get_template (f"{ render_type } .html" )
142+ final_config = ChainMap (dict (copy .deepcopy (config )), self .default_config )
143+ template = self .env .get_template (f"module.html" )
135144
136145 # Heading level is a "state" variable, that will change at each step
137146 # of the rendering recursion. Therefore, it's easier to use it as a plain value
@@ -148,18 +157,16 @@ def render(
148157 return template .render (
149158 ** {
150159 "config" : final_config ,
151- render_type : data ,
160+ "module" : data ,
152161 "heading_level" : heading_level ,
153162 "root" : True ,
154163 },
155164 )
156165
157- def get_anchors (self , data : VbaModuleInfo ) -> list [str ]:
158- return list (
159- {data .path .as_posix (), * (p .signature .name for p in data .procedures )}
160- )
166+ def get_anchors (self , data : VbaModuleInfo ) -> Set [str ]:
167+ return {data .path .as_posix (), * (p .signature .name for p in data .procedures )}
161168
162- def update_env (self , md : Markdown , config : dict ) -> None :
169+ def update_env (self , md : Markdown , config : Dict [ Any , Any ] ) -> None :
163170 super ().update_env (md , config )
164171 self .env .trim_blocks = True
165172 self .env .lstrip_blocks = True
@@ -171,7 +178,7 @@ def update_env(self, md: Markdown, config: dict) -> None:
171178 def collect (
172179 self ,
173180 identifier : str ,
174- config : dict ,
181+ config : MutableMapping [ str , Any ] ,
175182 ) -> VbaModuleInfo :
176183 """Collect the documentation tree given an identifier and selection options.
177184
@@ -222,7 +229,7 @@ def get_handler(
222229 An instance of `VbaHandler`.
223230 """
224231 return VbaHandler (
225- base_dir = Path (config_file_path ).parent ,
232+ base_dir = Path (config_file_path or "." ).parent ,
226233 handler = "vba" ,
227234 theme = theme ,
228235 custom_templates = custom_templates ,
0 commit comments