Skip to content

Commit 6570819

Browse files
committed
✨ Add section components
- add overview page for each section showing components in main section folder
1 parent 9e8f17b commit 6570819

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/vuegen/config_manager.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,25 @@ def _create_sect_config_fromdir(
257257
)
258258

259259
subsections = []
260+
components = []
260261
for subsection_dir in sorted_subsections:
261262
if subsection_dir.is_dir():
262263
subsections.append(self._create_subsect_config_fromdir(subsection_dir))
264+
else:
265+
file_in_subsection_dir = (
266+
subsection_dir # ! maybe take more generic names?
267+
)
268+
component_config = self._create_component_config_fromfile(
269+
file_in_subsection_dir
270+
)
271+
if component_config is not None:
272+
components.append(component_config)
263273

264274
section_config = {
265275
"title": self._create_title_fromdir(section_dir_path.name),
266276
"description": self._read_description_file(section_dir_path),
267277
"subsections": subsections,
278+
"components": components,
268279
}
269280
return section_config
270281

src/vuegen/streamlit_reportview.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import re
32
import subprocess
43
import sys
54
from pathlib import Path
@@ -148,6 +147,18 @@ def generate_report(self, output_dir: str = SECTIONS_DIR) -> None:
148147
self.report.logger.debug(
149148
f"Section directory already existed: {section_dir_path}"
150149
)
150+
# add an overview page to section of components exist
151+
if section.components:
152+
subsection_file_path = (
153+
Path(section_name_var)
154+
/ f"0_overview_{section.title.lower()}.py"
155+
).as_posix() # Make sure it's Posix Paths
156+
157+
# Create a Page object for each subsection and add it to the home page content
158+
report_manag_content.append(
159+
f"{section_name_var}_overview = st.Page('{subsection_file_path}', title='Overview {section.title}')"
160+
)
161+
subsection_page_vars.append(f"{section_name_var}_overview")
151162

152163
for subsection in section.subsections:
153164
# ! could add a non-integer to ensure it's a valid identifier
@@ -386,6 +397,25 @@ def _generate_sections(self, output_dir: str) -> None:
386397
f"Processing section '{section.id}': '{section.title}' - {len(section.subsections)} subsection(s)"
387398
)
388399

400+
if section.components:
401+
# add an section overview page
402+
section_content, section_imports, _ = self._combine_components(
403+
section.components
404+
)
405+
_filepath_overview = (
406+
Path(output_dir)
407+
/ section_name_var
408+
/ f"0_overview_{section.title.lower()}.py"
409+
# ! tighly coupled to generate_report fct:
410+
# ! check how to pass file names
411+
)
412+
413+
write_python_file(
414+
fpath=_filepath_overview,
415+
imports=section_imports,
416+
contents=section_content,
417+
)
418+
389419
if not section.subsections:
390420
self.report.logger.warning(
391421
f"No subsections found in section: '{section.title}'. "
@@ -394,6 +424,7 @@ def _generate_sections(self, output_dir: str) -> None:
394424
continue
395425

396426
# Iterate through subsections and integrate them into the section file
427+
# subsection should have the subsection_file_path as file_path?
397428
for subsection in section.subsections:
398429
self.report.logger.debug(
399430
f"Processing subsection '{subsection.id}': '{subsection.title} -"

0 commit comments

Comments
 (0)