Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 28 additions & 3 deletions src/vuegen/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,28 @@ def _read_description_file(self, folder_path: Path) -> str:
return f"{ret}\n"
return ""

def _read_home_image_file(self, folder_path: Path) -> str:
"""
Looks for an image file named 'home_image' with any supported image extension
in the given folder.

Parameters
----------
folder_path : Path
Path to the folder where the 'home_image' file might be located.

Returns
-------
str
Path to the 'home_image' image file as a string if found, otherwise an
empty string.
"""
for image_format in r.ImageFormat:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this will return the first one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but an Enum is iterable, isn't it? So, inside a for-loop should return all the components, or not?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should got this wrong. So the file will need to called home_image.jpg or alike?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly, bc if we allow any image, it will also add it into the default section created for components at the section level

candidate = folder_path / f"home_image{image_format.value_with_dot}"
if candidate.exists() and candidate.is_file():
return str(candidate)
return ""

def _create_subsect_config_fromdir(
self, subsection_dir_path: Path, level: int = 2
) -> Dict[str, Union[str, List[Dict]]]:
Expand Down Expand Up @@ -334,7 +356,7 @@ def create_yamlconfig_fromdir(
# This will be used for the home section of a report
"title": self._create_title_fromdir(base_dir_path.name),
"description": self._read_description_file(base_dir_path),
"graphical_abstract": "",
"graphical_abstract": self._read_home_image_file(base_dir_path),
"logo": "",
},
"sections": [],
Expand All @@ -358,8 +380,11 @@ def create_yamlconfig_fromdir(
# could be single plots?
else:
file_in_main_section_dir = section_dir
if file_in_main_section_dir.name.lower() == "description.md":
continue # Skip description files in the main section
if (
file_in_main_section_dir.name.lower() == "description.md"
or "home_image" in file_in_main_section_dir.name.lower()
):
continue # Skip description file and home_image in the main section
component_config = self._create_component_config_fromfile(
file_in_main_section_dir
)
Expand Down
16 changes: 16 additions & 0 deletions src/vuegen/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ def value_with_dot(self):
return f".{self.name.lower()}"


class ImageFormat(StrEnum):
"""Enum representing supported image file formats."""

PNG = auto()
JPG = auto()
JPEG = auto()
SVG = auto()
GIF = auto()
WEBP = auto()

@property
def value_with_dot(self):
"""Return the file extension with the dot."""
return f".{self.name.lower()}"


@dataclass
class Component:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ report_dir = Path().cwd()

A general description of the report.

![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}

# Plots
## Interactive Plots
Optional description for section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ report_dir = Path().cwd()

A general description of the report.

![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}

# Plots
## Interactive Plots
Optional description for section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ report_dir = Path().cwd()

A general description of the report.

![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}

# Plots
## Interactive Plots
Optional description for section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ report_dir = Path().cwd()

A general description of the report.

![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}

# Plots
## Interactive Plots
Optional description for section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ report_dir = Path().cwd()

A general description of the report.

![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}

# Plots
## Interactive Plots
Optional description for section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ report_dir = Path().cwd()

A general description of the report.

![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}

# Plots
## Interactive Plots
Optional description for section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ report_dir = Path().cwd()

A general description of the report.

![](../../../../../docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png){fig-alt= width=90%}

# Plots
## Interactive Plots
Optional description for section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
),
unsafe_allow_html=True)


st.image('docs/example_data/Basic_example_vuegen_demo_notebook/home_image.png', use_column_width=True)
footer = '''
<style type="text/css">
.footer {
Expand Down
Loading