2024-02-19 11:11:07 +02:00
|
|
|
use crate::documents::BuildXML;
|
|
|
|
use crate::{xml_builder::*, ImageIdAndPath};
|
|
|
|
use serde::Serialize;
|
2024-11-05 04:22:32 +02:00
|
|
|
use std::io::Write;
|
2024-02-19 11:11:07 +02:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Default)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct FooterRels {
|
|
|
|
pub images: Vec<(String, String)>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FooterRels {
|
|
|
|
pub fn new() -> FooterRels {
|
|
|
|
Default::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_image(mut self, id: impl Into<String>, path: impl Into<String>) -> Self {
|
|
|
|
self.images.push((id.into(), path.into()));
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn set_images(&mut self, images: Vec<ImageIdAndPath>) {
|
|
|
|
self.images = images;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BuildXML for FooterRels {
|
2024-11-05 04:22:32 +02:00
|
|
|
fn build_to<W: Write>(
|
|
|
|
&self,
|
|
|
|
stream: xml::writer::EventWriter<W>,
|
|
|
|
) -> xml::writer::Result<xml::writer::EventWriter<W>> {
|
|
|
|
XMLBuilder::from(stream)
|
|
|
|
.declaration(None)?
|
|
|
|
.open_relationships("http://schemas.openxmlformats.org/package/2006/relationships")?
|
|
|
|
.apply_each(&self.images, |(id, path), b| {
|
|
|
|
b.relationship(
|
|
|
|
id,
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
|
|
path,
|
|
|
|
)
|
|
|
|
})?
|
|
|
|
.close()?
|
|
|
|
.into_inner()
|
2024-02-19 11:11:07 +02:00
|
|
|
}
|
|
|
|
}
|