Skip to content

Commit 16dac66

Browse files
authored
Make required folder structure more flexible (#108)
* 🚧♻️ Refactor creating and writing components streamlit files - writing of imports + component code (write python file) - component - fct map for generation - building list of components * 🎨 move static_dir to init, remove some old code * ✨ add components to streamlit home site - first section is home section recording it's compents - needs to be treated separately * ✨ Add section components - add overview page for each section showing components in main section folder * 🎨 pass relative section file paths on using Section dataclasses - Section could be used everywhere, Subsection is not really necessary. If a Section has subsections, the logic changes. Else nothing changes. * 🔥 remove old code (unused) * ♻️ move is_static_report to init for quarto - set based on report type, and this is set on init - avoid to pass on variable to all functions. * 🎨 move static_dir to quarto_report init - same as for streamlit_report to prepare refactoring of components parsing. * ♻️ factor out component creation - very similar to _combine_components in streamlit_report - imports has to be a list of list -> figure this out - added debug message for skipping components in static reports-> should maybe be a warining? * 🎨 remove blank line from logs * ✨ add components from main and section folders * 🎨 align import handling in streamlit and quarto reports * 🐛 single curley-brackets - I removed an empty f-string and this lead to doubled curely brackets... * 🎨 add tabs to overview sections * 🐛 handle single descripton.md files ⚠️ duplicated code - description files are parsed by configuration_manager - skipped for section content. So a section can have content, which is not used - a single description.md file
1 parent e59eec3 commit 16dac66

File tree

5 files changed

+378
-215
lines changed

5 files changed

+378
-215
lines changed

src/vuegen/config_manager.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _create_component_config_fromfile(self, file_path: Path) -> Dict[str, str]:
145145
component_config["component_type"] = r.ComponentType.MARKDOWN.value
146146
else:
147147
self.logger.error(
148-
f"Unsupported file extension: {file_ext}. Skipping file: {file_path}\n"
148+
f"Unsupported file extension: {file_ext}. Skipping file: {file_path}"
149149
)
150150
return None
151151

@@ -227,6 +227,9 @@ def _create_subsect_config_fromdir(
227227
continue
228228
# Add component config to list
229229
components.append(component_config)
230+
# ! if folder go into folder and pull files out?
231+
# nesting level already at point 2
232+
# loop of components in a folder
230233

231234
subsection_config = {
232235
"title": self._create_title_fromdir(subsection_dir_path.name),
@@ -257,14 +260,25 @@ def _create_sect_config_fromdir(
257260
)
258261

259262
subsections = []
263+
components = []
260264
for subsection_dir in sorted_subsections:
261265
if subsection_dir.is_dir():
262266
subsections.append(self._create_subsect_config_fromdir(subsection_dir))
267+
else:
268+
file_in_subsection_dir = (
269+
subsection_dir # ! maybe take more generic names?
270+
)
271+
component_config = self._create_component_config_fromfile(
272+
file_in_subsection_dir
273+
)
274+
if component_config is not None:
275+
components.append(component_config)
263276

264277
section_config = {
265278
"title": self._create_title_fromdir(section_dir_path.name),
266279
"description": self._read_description_file(section_dir_path),
267280
"subsections": subsections,
281+
"components": components,
268282
}
269283
return section_config
270284

@@ -301,12 +315,27 @@ def create_yamlconfig_fromdir(
301315
# Sort sections by their number prefix
302316
sorted_sections = self._sort_paths_by_numprefix(list(base_dir_path.iterdir()))
303317

318+
main_section_config = {
319+
"title": "", # self._create_title_fromdir("home_components"),
320+
"description": "Components added to homepage.",
321+
"components": [],
322+
}
323+
yaml_config["sections"].append(main_section_config)
324+
304325
# Generate sections and subsections config
305326
for section_dir in sorted_sections:
306327
if section_dir.is_dir():
307328
yaml_config["sections"].append(
308329
self._create_sect_config_fromdir(section_dir)
309330
)
331+
# could be single plots?
332+
else:
333+
file_in_main_section_dir = section_dir
334+
component_config = self._create_component_config_fromfile(
335+
file_in_main_section_dir
336+
)
337+
if component_config is not None:
338+
main_section_config["components"].append(component_config)
310339

311340
return yaml_config, base_dir_path
312341

@@ -372,6 +401,10 @@ def _create_section(self, section_data: dict) -> r.Section:
372401
description=section_data.get("description"),
373402
)
374403

404+
for component_data in section_data.get("components", []):
405+
component = self._create_component(component_data)
406+
section.components.append(component)
407+
375408
# Create subsections
376409
for subsection_data in section_data.get("subsections", []):
377410
subsection = self._create_subsection(subsection_data)

0 commit comments

Comments
 (0)