Refactor the HTML and improve the styling #81
|
@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue