docx_rs/documents/
footer_rels.rs1use crate::documents::BuildXML;
2use crate::{xml_builder::*, ImageIdAndPath};
3use serde::Serialize;
4use std::io::Write;
5
6#[derive(Debug, Clone, PartialEq, Serialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct FooterRels {
9 pub images: Vec<(String, String)>,
10}
11
12impl FooterRels {
13 pub fn new() -> FooterRels {
14 Default::default()
15 }
16
17 pub fn add_image(mut self, id: impl Into<String>, path: impl Into<String>) -> Self {
18 self.images.push((id.into(), path.into()));
19 self
20 }
21
22 pub(crate) fn set_images(&mut self, images: Vec<ImageIdAndPath>) {
23 self.images = images;
24 }
25}
26
27impl BuildXML for FooterRels {
28 fn build_to<W: Write>(
29 &self,
30 stream: xml::writer::EventWriter<W>,
31 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
32 XMLBuilder::from(stream)
33 .declaration(None)?
34 .open_relationships("http://schemas.openxmlformats.org/package/2006/relationships")?
35 .apply_each(&self.images, |(id, path), b| {
36 b.relationship(
37 id,
38 "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
39 path,
40 )
41 })?
42 .close()?
43 .into_inner()
44 }
45}