Skip to content

Commit 5f98172

Browse files
committed
✨ revert to homepage layout as before, add new section
- use the homepage layout as it was before: title, descrpiton, logo and graphical abstract - if there are components in the main folder, trigger to add section with main folder name if the configuration is built using the directory based method. - a new section with the components is added - if configs are created manually, the first section is treated as every other section
1 parent 4c88031 commit 5f98172

File tree

2 files changed

+8
-46
lines changed

2 files changed

+8
-46
lines changed

src/vuegen/config_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def create_yamlconfig_fromdir(
316316
# Generate the YAML config
317317
yaml_config = {
318318
"report": {
319+
# This will be used for the home section of a report
319320
"title": self._create_title_fromdir(base_dir_path.name),
320321
"description": self._read_description_file(base_dir_path),
321322
"graphical_abstract": "",
@@ -328,10 +329,11 @@ def create_yamlconfig_fromdir(
328329
sorted_sections = self._sort_paths_by_numprefix(list(base_dir_path.iterdir()))
329330

330331
main_section_config = {
331-
"title": "",
332-
"description": "Components added to homepage.",
332+
"title": self._create_title_fromdir(base_dir_path.name),
333+
"description": "Components added to main report folder.",
333334
"components": [],
334335
}
336+
# treat it as any other section.
335337
yaml_config["sections"].append(main_section_config)
336338

337339
# Generate sections and subsections config

src/vuegen/streamlit_reportview.py

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -145,41 +145,14 @@ def generate_report(self, output_dir: str = SECTIONS_DIR) -> None:
145145

146146
# Generate the home page and update the report manager content
147147
# ! top level files (compontents) are added to the home page
148-
home_section = self.report.sections[0]
149148
self._generate_home_section(
150149
output_dir=output_dir,
151150
report_manag_content=report_manag_content,
152-
home_section=home_section,
153151
)
154152
# ! move this into the _generate_home_section method
155153
subsection_page_vars = []
156154

157-
for subsection in home_section.subsections:
158-
# ! could add a non-integer to ensure it's a valid identifier
159-
subsection_name_var = make_valid_identifier(subsection.title)
160-
if not subsection_name_var.isidentifier():
161-
self.report.logger.warning(
162-
f"Subsection name '{subsection_name_var}' is not a valid identifier."
163-
)
164-
raise ValueError(
165-
f"Subsection name is not a valid Python identifier: {subsection_name_var}"
166-
)
167-
subsection_file_path = (
168-
Path("Home") / f"{subsection_name_var}.py"
169-
).as_posix() # Make sure it's Posix Paths
170-
subsection.file_path = subsection_file_path
171-
# Create a Page object for each subsection and add it to the home page content
172-
report_manag_content.append(
173-
f"{subsection_name_var} = st.Page('{subsection_file_path}', title='{subsection.title}')"
174-
)
175-
subsection_page_vars.append(subsection_name_var)
176-
177-
# Add all subsection Page objects to the corresponding section
178-
report_manag_content.append(
179-
f"sections_pages['Home'] = [homepage,{', '.join(subsection_page_vars)}]\n"
180-
)
181-
182-
for section in self.report.sections[1:]: # skip home section components
155+
for section in self.report.sections: # skip home section components
183156
# Create a folder for each section
184157
subsection_page_vars = []
185158
section_name_var = make_valid_identifier(
@@ -376,7 +349,6 @@ def _generate_home_section(
376349
self,
377350
output_dir: str,
378351
report_manag_content: list,
379-
home_section: r.Section,
380352
) -> None:
381353
"""
382354
Generates the homepage for the report and updates the report manager content.
@@ -388,14 +360,7 @@ def _generate_home_section(
388360
report_manag_content : list
389361
A list to store the content that will be written to the report manager file.
390362
"""
391-
self.report.logger.debug("Processing home section.")
392-
all_components = []
393-
subsection_imports = []
394-
if home_section.components:
395-
# some assert on title?
396-
all_components, subsection_imports, _ = self._combine_components(
397-
home_section.components
398-
)
363+
self.report.logger.debug("Processing home section."))
399364

400365
try:
401366
# Create folder for the home page
@@ -410,8 +375,6 @@ def _generate_home_section(
410375
# Create the home page content
411376
home_content = []
412377
home_content.append("import streamlit as st")
413-
if subsection_imports:
414-
home_content.extend(subsection_imports)
415378
if self.report.description:
416379
home_content.append(
417380
self._format_text(text=self.report.description, type="paragraph")
@@ -422,8 +385,6 @@ def _generate_home_section(
422385
)
423386

424387
# add components content to page (if any)
425-
if all_components:
426-
home_content.extend(all_components)
427388

428389
# Define the footer variable and add it to the home page content
429390
home_content.append("footer = '''" + generate_footer() + "'''\n")
@@ -456,12 +417,11 @@ def _generate_sections(self, output_dir: str) -> None:
456417
"""
457418
self.report.logger.info("Starting to generate sections for the report.")
458419
try:
459-
for section_no, section in enumerate(self.report.sections):
420+
for section in self.report.sections:
460421
self.report.logger.debug(
461422
f"Processing section '{section.id}': '{section.title}' - {len(section.subsections)} subsection(s)"
462423
)
463-
# ! skip first section components as it's predefined as homepage
464-
if section_no and section.components:
424+
if section.components:
465425
# add an section overview page
466426
section_content, section_imports, _ = self._combine_components(
467427
section.components

0 commit comments

Comments
 (0)