docx-rs/docx-core/src/documents/rels.rs

61 lines
1.9 KiB
Rust
Raw Normal View History

2019-11-06 05:29:17 +02:00
use crate::documents::BuildXML;
2019-11-05 11:03:23 +02:00
use crate::xml_builder::*;
2019-11-07 11:45:03 +02:00
#[derive(Debug)]
2019-11-05 11:03:23 +02:00
pub struct Rels {}
impl Rels {
pub fn new() -> Rels {
Rels {}
}
2019-11-06 05:29:17 +02:00
}
2019-11-05 11:03:23 +02:00
2019-11-06 05:29:17 +02:00
impl BuildXML for Rels {
fn build(&self) -> Vec<u8> {
2019-11-05 11:03:23 +02:00
let b = XMLBuilder::new();
2019-11-05 12:20:40 +02:00
b.declaration(None)
2019-11-05 11:03:23 +02:00
.open_relationships("http://schemas.openxmlformats.org/package/2006/relationships")
.relationship(
"rId1",
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",
"docProps/core.xml"
)
.relationship(
"rId2",
2019-11-13 11:50:15 +02:00
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties",
2019-11-05 11:03:23 +02:00
"docProps/app.xml"
)
.relationship(
"rId3",
2019-11-13 11:50:15 +02:00
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"word/document.xml"
2019-11-05 11:03:23 +02:00
)
.close()
.build()
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::str;
2019-11-07 06:57:58 +02:00
#[cfg(test)]
use pretty_assertions::assert_eq;
2019-11-05 11:03:23 +02:00
#[test]
fn test_build() {
let c = Rels::new();
let b = c.build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<?xml version="1.0" encoding="UTF-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml" />
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml" />
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml" />
</Relationships>"#
);
}
}