1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use serde::Serialize;

use crate::documents::BuildXML;
use crate::xml_builder::*;

#[derive(Debug, Clone, PartialEq, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct CustomItemRels {
    custom_item_count: usize,
}

impl CustomItemRels {
    pub fn new() -> CustomItemRels {
        Default::default()
    }

    pub fn add_item(mut self) -> Self {
        self.custom_item_count += 1;
        self
    }
}

impl BuildXML for CustomItemRels {
    fn build(&self) -> Vec<u8> {
        let mut b = XMLBuilder::new();
        b = b
            .declaration(Some(true))
            .open_relationships("http://schemas.openxmlformats.org/package/2006/relationships");

        for id in 0..self.custom_item_count {
            let id = id + 1;
            b = b.relationship(
                &format!("rId{}", id),
                "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps",
                &format!("itemProps{}.xml", id),
            )
        }

        b.close().build()
    }
}