Remove my custom Image struct

This commit is contained in:
Savanni D'Gerinel 2023-10-25 23:24:41 -04:00
parent 448231739b
commit 9a014af75a
2 changed files with 3 additions and 40 deletions

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(),
),
)