Compare commits
No commits in common. "9a014af75af6c32753a9a3277865c547107cf60a" and "b0027032a47c7d5a01f1a55cf2e7590ff661dcb1" have entirely different histories.
9a014af75a
...
b0027032a4
|
@ -236,3 +236,92 @@ 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()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct UnorderedList {
|
||||||
|
children: Vec<String>,
|
||||||
|
attributes: Attributes,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UnorderedList {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
children: vec![],
|
||||||
|
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 UnorderedList {
|
||||||
|
fn to_html_string(&self) -> String {
|
||||||
|
let children = self
|
||||||
|
.children
|
||||||
|
.iter()
|
||||||
|
.map(|item| format!("<li>{}</li>", item.to_html_string()))
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
format!(
|
||||||
|
"<ul {attrs}>
|
||||||
|
{children}
|
||||||
|
</ul>",
|
||||||
|
attrs = self.attributes.to_string(),
|
||||||
|
children = children.join("\n")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HtmlContainer for UnorderedList {
|
||||||
|
fn add_html<H: Html>(&mut self, html: H) {
|
||||||
|
self.children.push(html.to_html_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -87,16 +87,15 @@ pub fn thumbnail(info: &FileInfo) -> Container {
|
||||||
.with_html(
|
.with_html(
|
||||||
Container::new(ContainerType::Div).with_link(
|
Container::new(ContainerType::Div).with_link(
|
||||||
format!("/{}", *info.id),
|
format!("/{}", *info.id),
|
||||||
Container::default()
|
Image::new(&format!("{}/tn", *info.id))
|
||||||
.with_attributes([("class", "thumbnail")])
|
.with_attributes([("class", "thumbnail__image")])
|
||||||
.with_image(&format!("{}/tn", *info.id), "test data")
|
|
||||||
.to_html_string(),
|
.to_html_string(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.with_html(
|
.with_html(
|
||||||
Container::new(ContainerType::Div)
|
Container::new(ContainerType::Div)
|
||||||
.with_html(
|
.with_html(
|
||||||
Container::new(ContainerType::UnorderedList)
|
UnorderedList::new()
|
||||||
.with_attributes(vec![("class", "thumbnail__metadata")])
|
.with_attributes(vec![("class", "thumbnail__metadata")])
|
||||||
.with_html(info.name.clone())
|
.with_html(info.name.clone())
|
||||||
.with_html(format!("{}", info.created.format("%Y-%m-%d"))),
|
.with_html(format!("{}", info.created.format("%Y-%m-%d"))),
|
||||||
|
|
Loading…
Reference in New Issue