Skip to content

Commit 01dd9c5

Browse files
authored
Load home image on the base folder when creating a report from a directory (#152)
* ✨ Add code to look for a home image on the base folder and load it if exist when creating a report from a directory A Enum for ImageFormats was also created on the report.py script * 🐛 Fix: make comment line shorter to follow convention * ✅ Update test report files with the home image addition * Trigger GitHub Actions * Re-trigger GitHub Actions bc of tynitex issue
1 parent 1452c24 commit 01dd9c5

File tree

11 files changed

+60
-3
lines changed

11 files changed

+60
-3
lines changed
270 KB
Loading

src/vuegen/config_manager.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,28 @@ def _read_description_file(self, folder_path: Path) -> str:
215215
return f"{ret}\n"
216216
return ""
217217

218+
def _read_home_image_file(self, folder_path: Path) -> str:
219+
"""
220+
Looks for an image file named 'home_image' with any supported image extension
221+
in the given folder.
222+
223+
Parameters
224+
----------
225+
folder_path : Path
226+
Path to the folder where the 'home_image' file might be located.
227+
228+
Returns
229+
-------
230+
str
231+
Path to the 'home_image' image file as a string if found, otherwise an
232+
empty string.
233+
"""
234+
for image_format in r.ImageFormat:
235+
candidate = folder_path / f"home_image{image_format.value_with_dot}"
236+
if candidate.exists() and candidate.is_file():
237+
return str(candidate)
238+
return ""
239+
218240
def _create_subsect_config_fromdir(
219241
self, subsection_dir_path: Path, level: int = 2
220242
) -> Dict[str, Union[str, List[Dict]]]:
@@ -334,7 +356,7 @@ def create_yamlconfig_fromdir(
334356
# This will be used for the home section of a report
335357
"title": self._create_title_fromdir(base_dir_path.name),
336358
"description": self._read_description_file(base_dir_path),
337-
"graphical_abstract": "",
359+
"graphical_abstract": self._read_home_image_file(base_dir_path),
338360
"logo": "",
339361
},
340362
"sections": [],
@@ -358,8 +380,11 @@ def create_yamlconfig_fromdir(
358380
# could be single plots?
359381
else:
360382
file_in_main_section_dir = section_dir
361-
if file_in_main_section_dir.name.lower() == "description.md":
362-
continue # Skip description files in the main section
383+
if (
384+
file_in_main_section_dir.name.lower() == "description.md"
385+
or "home_image" in file_in_main_section_dir.name.lower()
386+
):
387+
continue # Skip description file and home_image in the main section
363388
component_config = self._create_component_config_fromfile(
364389
file_in_main_section_dir
365390
)

src/vuegen/report.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ def value_with_dot(self):
100100
return f".{self.name.lower()}"
101101

102102

103+
class ImageFormat(StrEnum):
104+
"""Enum representing supported image file formats."""
105+
106+
PNG = auto()
107+
JPG = auto()
108+
JPEG = auto()
109+
SVG = auto()
110+
GIF = auto()
111+
WEBP = auto()
112+
113+
@property
114+
def value_with_dot(self):
115+
"""Return the file extension with the dot."""
116+
return f".{self.name.lower()}"
117+
118+
103119
@dataclass
104120
class Component:
105121
"""

tests/report_examples/Basic_example_vuegen_demo_notebook/docx/quarto_report/quarto_report.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ report_dir = Path().cwd()
2727

2828
A general description of the report.
2929

30+
![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}
31+
3032
# Plots
3133
## Interactive Plots
3234
Optional description for section.

tests/report_examples/Basic_example_vuegen_demo_notebook/html/quarto_report/quarto_report.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ report_dir = Path().cwd()
5353

5454
A general description of the report.
5555

56+
![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}
57+
5658
# Plots
5759
## Interactive Plots
5860
Optional description for section.

tests/report_examples/Basic_example_vuegen_demo_notebook/jupyter/quarto_report/quarto_report.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ report_dir = Path().cwd()
5353

5454
A general description of the report.
5555

56+
![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}
57+
5658
# Plots
5759
## Interactive Plots
5860
Optional description for section.

tests/report_examples/Basic_example_vuegen_demo_notebook/odt/quarto_report/quarto_report.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ report_dir = Path().cwd()
2727

2828
A general description of the report.
2929

30+
![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}
31+
3032
# Plots
3133
## Interactive Plots
3234
Optional description for section.

tests/report_examples/Basic_example_vuegen_demo_notebook/pdf/quarto_report/quarto_report.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ report_dir = Path().cwd()
3939

4040
A general description of the report.
4141

42+
![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}
43+
4244
# Plots
4345
## Interactive Plots
4446
Optional description for section.

tests/report_examples/Basic_example_vuegen_demo_notebook/pptx/quarto_report/quarto_report.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ report_dir = Path().cwd()
2828

2929
A general description of the report.
3030

31+
![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}
32+
3133
# Plots
3234
## Interactive Plots
3335
Optional description for section.

tests/report_examples/Basic_example_vuegen_demo_notebook/revealjs/quarto_report/quarto_report.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ report_dir = Path().cwd()
5454

5555
A general description of the report.
5656

57+
![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}
58+
5759
# Plots
5860
## Interactive Plots
5961
Optional description for section.

0 commit comments

Comments
 (0)