Skip to content

Commit 209ae0a

Browse files
committed
✨ 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
1 parent d8ecd52 commit 209ae0a

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-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 files 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
"""

0 commit comments

Comments
 (0)