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

69 lines
1.8 KiB
Rust
Raw Normal View History

use serde::Serialize;
2019-11-13 11:50:15 +02:00
use crate::documents::BuildXML;
use crate::xml_builder::*;
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentRels {
pub has_comments: bool,
pub has_numberings: bool,
}
2019-11-13 11:50:15 +02:00
impl DocumentRels {
pub fn new() -> DocumentRels {
Default::default()
}
}
impl Default for DocumentRels {
fn default() -> Self {
Self {
has_comments: false,
has_numberings: false,
}
2019-11-13 11:50:15 +02:00
}
}
impl BuildXML for DocumentRels {
fn build(&self) -> Vec<u8> {
let mut b = XMLBuilder::new();
b = b
.declaration(None)
2019-11-13 11:50:15 +02:00
.open_relationships("http://schemas.openxmlformats.org/package/2006/relationships")
.relationship(
"rId1",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
"styles.xml",
)
.relationship(
"rId2",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
"fontTable.xml",
2019-12-06 12:18:48 +02:00
)
.relationship(
"rId3",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
"settings.xml",
);
if self.has_comments {
b = b.relationship(
"rId4",
2019-12-05 08:44:18 +02:00
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
"comments.xml",
)
}
if self.has_numberings {
b = b.relationship(
2019-12-06 12:18:48 +02:00
"rId5",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
"numbering.xml",
2019-11-13 11:50:15 +02:00
)
}
b.close().build()
2019-11-13 11:50:15 +02:00
}
}