Skip to content

Commit 3cb87ca

Browse files
committed
🐛 Fix(config_manager.py): Modify the code to create config from dir to show title from sections, subsections, and components first
1 parent 4c93b60 commit 3cb87ca

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

vuegen/config_manager.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ def _create_component_config_fromfile(self, file_path: Path) -> Dict[str, str]:
6060
file_ext = file_path.suffix.lower()
6161
component_config = {}
6262

63+
# Add title, file path, and description
64+
component_config["title"] = self._create_title_fromdir(file_path.name)
65+
component_config["file_path"] = str(file_path.resolve())
66+
component_config["description"] = ""
67+
6368
# Infer component config
6469
if file_ext in [r.DataFrameFormat.CSV.value_with_dot, r.DataFrameFormat.TXT.value_with_dot]:
6570
# Check for CSVNetworkFormat keywords
@@ -177,36 +182,24 @@ def _create_subsect_config_fromdir(self, subsection_dir_path: Path) -> Dict[str,
177182
Dict[str, Union[str, List[Dict]]]
178183
The subsection config.
179184
"""
180-
subsection_config = {
181-
"title": self._create_title_fromdir(subsection_dir_path.name),
182-
"description": self._read_description_file(subsection_dir_path),
183-
"components": [],
184-
}
185-
186185
# Sort files by number prefix
187186
sorted_files = self._sort_paths_by_numprefix(list(subsection_dir_path.iterdir()))
188187

188+
components = []
189189
for file in sorted_files:
190190
if file.is_file():
191191
component_config = self._create_component_config_fromfile(file)
192192
# Skip unsupported files
193193
if component_config is None:
194194
continue
195-
196-
# Ensure the file path is absolute
197-
file_path = file.resolve()
198-
199-
component_config_updt = {
200-
"title": self._create_title_fromdir(file.name),
201-
"file_path": str(file_path),
202-
"description": "",
203-
}
204-
205-
# Update inferred config information
206-
component_config.update(component_config_updt)
207-
208-
subsection_config["components"].append(component_config)
209-
195+
# Add component config to list
196+
components.append(component_config)
197+
198+
subsection_config = {
199+
"title": self._create_title_fromdir(subsection_dir_path.name),
200+
"description": self._read_description_file(subsection_dir_path),
201+
"components": components,
202+
}
210203
return subsection_config
211204

212205
def _create_sect_config_fromdir(self, section_dir_path: Path) -> Dict[str, Union[str, List[Dict]]]:
@@ -223,19 +216,19 @@ def _create_sect_config_fromdir(self, section_dir_path: Path) -> Dict[str, Union
223216
Dict[str, Union[str, List[Dict]]]
224217
The section config.
225218
"""
226-
section_config = {
227-
"title": self._create_title_fromdir(section_dir_path.name),
228-
"description": self._read_description_file(section_dir_path),
229-
"subsections": [],
230-
}
231-
232219
# Sort subsections by number prefix
233220
sorted_subsections = self._sort_paths_by_numprefix(list(section_dir_path.iterdir()))
234221

222+
subsections = []
235223
for subsection_dir in sorted_subsections:
236224
if subsection_dir.is_dir():
237-
section_config["subsections"].append(self._create_subsect_config_fromdir(subsection_dir))
225+
subsections.append(self._create_subsect_config_fromdir(subsection_dir))
238226

227+
section_config = {
228+
"title": self._create_title_fromdir(section_dir_path.name),
229+
"description": self._read_description_file(section_dir_path),
230+
"subsections": subsections,
231+
}
239232
return section_config
240233

241234
def create_yamlconfig_fromdir(self, base_dir: str) -> Tuple[Dict[str, Union[str, List[Dict]]], Path]:

0 commit comments

Comments
 (0)