4
4
5
5
from __future__ import annotations
6
6
7
+ import copy
7
8
import posixpath
8
9
from collections import ChainMap
9
10
from 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
+ )
11
22
12
23
from griffe .logger import patch_loggers
13
24
from markdown import Markdown
@@ -53,7 +64,7 @@ def __init__(self, *, base_dir: Path, **kwargs: Any) -> None:
53
64
The theme to fall back to.
54
65
"""
55
66
56
- default_config : dict = {
67
+ default_config = {
57
68
"show_root_heading" : False ,
58
69
"show_root_toc_entry" : True ,
59
70
"show_root_full_path" : True ,
@@ -126,12 +137,10 @@ def load_inventory(
126
137
def render (
127
138
self ,
128
139
data : VbaModuleInfo ,
129
- config : dict ,
140
+ config : Mapping [ str , Any ] ,
130
141
) -> 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" )
135
144
136
145
# Heading level is a "state" variable, that will change at each step
137
146
# of the rendering recursion. Therefore, it's easier to use it as a plain value
@@ -148,18 +157,16 @@ def render(
148
157
return template .render (
149
158
** {
150
159
"config" : final_config ,
151
- render_type : data ,
160
+ "module" : data ,
152
161
"heading_level" : heading_level ,
153
162
"root" : True ,
154
163
},
155
164
)
156
165
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 )}
161
168
162
- def update_env (self , md : Markdown , config : dict ) -> None :
169
+ def update_env (self , md : Markdown , config : Dict [ Any , Any ] ) -> None :
163
170
super ().update_env (md , config )
164
171
self .env .trim_blocks = True
165
172
self .env .lstrip_blocks = True
@@ -171,7 +178,7 @@ def update_env(self, md: Markdown, config: dict) -> None:
171
178
def collect (
172
179
self ,
173
180
identifier : str ,
174
- config : dict ,
181
+ config : MutableMapping [ str , Any ] ,
175
182
) -> VbaModuleInfo :
176
183
"""Collect the documentation tree given an identifier and selection options.
177
184
@@ -222,7 +229,7 @@ def get_handler(
222
229
An instance of `VbaHandler`.
223
230
"""
224
231
return VbaHandler (
225
- base_dir = Path (config_file_path ).parent ,
232
+ base_dir = Path (config_file_path or "." ).parent ,
226
233
handler = "vba" ,
227
234
theme = theme ,
228
235
custom_templates = custom_templates ,
0 commit comments