Refactor the HTML and improve the styling #81

Merged
savanni merged 4 commits from file-service/html-refactoring into main 2023-10-26 04:11:33 +00:00
2 changed files with 3 additions and 40 deletions
Showing only changes of commit 9a014af75a - Show all commits

View File

@ -236,41 +236,3 @@ impl Html for Button {
)
}
}
#[derive(Clone, Debug)]
pub struct Image {
path: String,
attributes: Attributes,
}
impl Image {
pub fn new(path: &str) -> Self {
Self {
path: path.to_owned(),
attributes: Attributes::default(),
}
}
pub fn with_attributes<'a>(
mut self,
values: impl IntoIterator<Item = (&'a str, &'a str)>,
) -> Self {
self.attributes = Attributes(
values
.into_iter()
.map(|(a, b)| (a.to_owned(), b.to_owned()))
.collect::<Vec<(String, String)>>(),
);
self
}
}
impl Html for Image {
fn to_html_string(&self) -> String {
format!(
"<img src={path} {attrs} />",
path = self.path,
attrs = self.attributes.to_string()
)
}
}

View File

@ -87,8 +87,9 @@ pub fn thumbnail(info: &FileInfo) -> Container {
.with_html(
Container::new(ContainerType::Div).with_link(
format!("/{}", *info.id),
Image::new(&format!("{}/tn", *info.id))
.with_attributes([("class", "thumbnail__image")])
Container::default()
.with_attributes([("class", "thumbnail")])
.with_image(&format!("{}/tn", *info.id), "test data")
.to_html_string(),
),
)