feat: fix core props
parent
fb7cdec1b6
commit
af75b6a41c
|
@ -2,30 +2,30 @@ use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CoreProps {
|
pub struct CoreProps<'a> {
|
||||||
config: CorePropsConfig,
|
config: CorePropsConfig<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CorePropsConfig {
|
pub struct CorePropsConfig<'a> {
|
||||||
created: Option<String>,
|
created: Option<&'a str>,
|
||||||
creator: Option<String>,
|
creator: Option<&'a str>,
|
||||||
description: Option<String>,
|
description: Option<&'a str>,
|
||||||
language: Option<String>,
|
language: Option<&'a str>,
|
||||||
last_modified_by: Option<String>,
|
last_modified_by: Option<&'a str>,
|
||||||
modified: Option<String>,
|
modified: Option<&'a str>,
|
||||||
revision: Option<usize>,
|
revision: Option<usize>,
|
||||||
subject: Option<String>,
|
subject: Option<&'a str>,
|
||||||
title: Option<String>,
|
title: Option<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoreProps {
|
impl<'a> CoreProps<'a> {
|
||||||
pub(crate) fn new(config: CorePropsConfig) -> CoreProps {
|
pub(crate) fn new(config: CorePropsConfig<'a>) -> CoreProps {
|
||||||
CoreProps { config }
|
CoreProps { config }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CorePropsConfig {
|
impl<'a> CorePropsConfig<'a> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
CorePropsConfig {
|
CorePropsConfig {
|
||||||
created: None,
|
created: None,
|
||||||
|
@ -41,7 +41,7 @@ impl CorePropsConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildXML for CoreProps {
|
impl<'a> BuildXML for CoreProps<'a> {
|
||||||
fn build(&self) -> Vec<u8> {
|
fn build(&self) -> Vec<u8> {
|
||||||
let b = XMLBuilder::new();
|
let b = XMLBuilder::new();
|
||||||
let base = b.declaration(Some(true)).open_core_properties(
|
let base = b.declaration(Some(true)).open_core_properties(
|
||||||
|
@ -53,37 +53,39 @@ impl BuildXML for CoreProps {
|
||||||
);
|
);
|
||||||
|
|
||||||
let convert = |v: usize| format!("{}", v);
|
let convert = |v: usize| format!("{}", v);
|
||||||
let default = || "";
|
let mut base = base
|
||||||
|
.dcterms_created(
|
||||||
// base.dcterms_created(
|
"dcterms:W3CDTF",
|
||||||
// "dcterms:W3CDTF",
|
self.config
|
||||||
// c.created.as_ref().map_or_else(default, |v| v),
|
.created
|
||||||
// )
|
.map_or_else(|| "1970-01-01T00:00:00Z", |v| v),
|
||||||
// .dc_creator(c.creator.as_ref().map_or_else(default, |v| v))
|
)
|
||||||
// .dc_description(c.description.as_ref().map_or_else(default, |v| v))
|
.dc_creator(self.config.creator.map_or_else(|| "unknown", |v| v))
|
||||||
// .dc_language(c.language.as_ref().map_or_else(default, |v| v))
|
.cp_last_modified_by(
|
||||||
// .cp_last_modified_by(c.last_modified_by.as_ref().map_or_else(default, |v| v))
|
self.config
|
||||||
// .dcterms_modified(
|
.last_modified_by
|
||||||
// "dcterms:W3CDTF",
|
.map_or_else(|| "unknown", |v| v),
|
||||||
// c.modified.as_ref().map_or_else(default, |v| v),
|
)
|
||||||
// )
|
.dcterms_modified(
|
||||||
// .cp_revision(&c.revision.map_or_else(|| "".to_owned(), convert))
|
"dcterms:W3CDTF",
|
||||||
// .dc_subject(c.subject.as_ref().map_or_else(default, |v| v))
|
self.config
|
||||||
// .dc_title(c.title.as_ref().map_or_else(default, |v| v))
|
.modified
|
||||||
// .close()
|
.map_or_else(|| "1970-01-01T00:00:00Z", |v| v),
|
||||||
// .build()
|
)
|
||||||
|
.cp_revision(&self.config.revision.map_or_else(|| "1".to_owned(), convert));
|
||||||
base.dcterms_created("dcterms:W3CDTF", "2019-09-13T19:25:28Z")
|
if let Some(v) = self.config.description {
|
||||||
.dc_creator("unknown")
|
base = base.dc_description(v);
|
||||||
.dc_description("")
|
}
|
||||||
.dc_language("")
|
if let Some(v) = self.config.language {
|
||||||
.cp_last_modified_by("unknown")
|
base = base.dc_language(v);
|
||||||
.dcterms_modified("dcterms:W3CDTF", "2019-09-13T19:25:28Z")
|
}
|
||||||
.cp_revision("1")
|
if let Some(v) = self.config.subject {
|
||||||
.dc_subject("")
|
base = base.dc_subject(v);
|
||||||
.dc_title("")
|
}
|
||||||
.close()
|
if let Some(v) = self.config.title {
|
||||||
.build()
|
base = base.dc_title(v);
|
||||||
|
}
|
||||||
|
base.close().build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +98,7 @@ mod tests {
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_default_doc_props_core_build() {
|
fn test_default_doc_props_core() {
|
||||||
let c = CoreProps::new(CorePropsConfig {
|
let c = CoreProps::new(CorePropsConfig {
|
||||||
created: None,
|
created: None,
|
||||||
creator: None,
|
creator: None,
|
||||||
|
@ -113,49 +115,43 @@ mod tests {
|
||||||
str::from_utf8(&b).unwrap(),
|
str::from_utf8(&b).unwrap(),
|
||||||
r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<dcterms:created xsi:type="dcterms:W3CDTF">2019-09-13T19:25:28Z</dcterms:created>
|
<dcterms:created xsi:type="dcterms:W3CDTF">1970-01-01T00:00:00Z</dcterms:created>
|
||||||
<dc:creator>unknown</dc:creator>
|
<dc:creator>unknown</dc:creator>
|
||||||
<dc:description></dc:description>
|
|
||||||
<dc:language></dc:language>
|
|
||||||
<cp:lastModifiedBy>unknown</cp:lastModifiedBy>
|
<cp:lastModifiedBy>unknown</cp:lastModifiedBy>
|
||||||
<dcterms:modified xsi:type="dcterms:W3CDTF">2019-09-13T19:25:28Z</dcterms:modified>
|
<dcterms:modified xsi:type="dcterms:W3CDTF">1970-01-01T00:00:00Z</dcterms:modified>
|
||||||
<cp:revision>1</cp:revision>
|
<cp:revision>1</cp:revision>
|
||||||
<dc:subject></dc:subject>
|
|
||||||
<dc:title></dc:title>
|
|
||||||
</cp:coreProperties>"#
|
</cp:coreProperties>"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
#[test]
|
||||||
#[test]
|
fn test_configured_doc_props_core_build() {
|
||||||
fn test_configured_doc_props_core_build() {
|
let c = CoreProps::new(CorePropsConfig {
|
||||||
let c = CoreProps::new(CorePropsConfig {
|
created: Some("2019-01-01"),
|
||||||
created: Some("2019-01-01".to_owned()),
|
creator: Some("foo"),
|
||||||
creator: Some("foo".to_owned()),
|
description: Some("bar"),
|
||||||
description: Some("bar".to_owned()),
|
language: Some("en"),
|
||||||
language: Some("en".to_owned()),
|
last_modified_by: Some("go"),
|
||||||
last_modified_by: Some("go".to_owned()),
|
modified: Some("2019-01-01"),
|
||||||
modified: Some("2019-01-01".to_owned()),
|
revision: Some(1),
|
||||||
revision: Some(1),
|
subject: Some("subject"),
|
||||||
subject: Some("subject".to_owned()),
|
title: Some("title"),
|
||||||
title: Some("title".to_owned()),
|
});
|
||||||
});
|
let b = c.build();
|
||||||
let b = c.build();
|
assert_eq!(
|
||||||
assert_eq!(
|
|
||||||
str::from_utf8(&b).unwrap(),
|
str::from_utf8(&b).unwrap(),
|
||||||
r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<dcterms:created xsi:type="dcterms:W3CDTF">2019-01-01</dcterms:created>
|
<dcterms:created xsi:type="dcterms:W3CDTF">2019-01-01</dcterms:created>
|
||||||
<dc:creator>foo</dc:creator>
|
<dc:creator>foo</dc:creator>
|
||||||
<dc:description>bar</dc:description>
|
<cp:lastModifiedBy>go</cp:lastModifiedBy>
|
||||||
<dc:language>en</dc:language>
|
<dcterms:modified xsi:type="dcterms:W3CDTF">2019-01-01</dcterms:modified>
|
||||||
<cp:lastModifiedBy>go</cp:lastModifiedBy>
|
<cp:revision>1</cp:revision>
|
||||||
<dcterms:modified xsi:type="dcterms:W3CDTF">2019-01-01</dcterms:modified>
|
<dc:description>bar</dc:description>
|
||||||
<cp:revision>1</cp:revision>
|
<dc:language>en</dc:language>
|
||||||
<dc:subject>subject</dc:subject>
|
<dc:subject>subject</dc:subject>
|
||||||
<dc:title>title</dc:title>
|
<dc:title>title</dc:title>
|
||||||
</cp:coreProperties>"#
|
</cp:coreProperties>"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@ pub use self::core::*;
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct DocProps {
|
pub(crate) struct DocProps<'a> {
|
||||||
app: AppProps,
|
app: AppProps,
|
||||||
core: CoreProps,
|
core: CoreProps<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DocProps {
|
impl<'a> DocProps<'a> {
|
||||||
pub(crate) fn new(core_config: CorePropsConfig) -> DocProps {
|
pub(crate) fn new(core_config: CorePropsConfig) -> DocProps {
|
||||||
let app = AppProps::new();
|
let app = AppProps::new();
|
||||||
let core = CoreProps::new(core_config);
|
let core = CoreProps::new(core_config);
|
||||||
|
|
|
@ -24,18 +24,18 @@ pub use styles::*;
|
||||||
pub use xml_docx::*;
|
pub use xml_docx::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Docx {
|
pub struct Docx<'a> {
|
||||||
content_type: ContentTypes,
|
content_type: ContentTypes,
|
||||||
rels: Rels,
|
rels: Rels,
|
||||||
document_rels: DocumentRels,
|
document_rels: DocumentRels,
|
||||||
doc_props: DocProps,
|
doc_props: DocProps<'a>,
|
||||||
styles: Styles,
|
styles: Styles,
|
||||||
document: Document,
|
document: Document,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
font_table: FontTable,
|
font_table: FontTable,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Docx {
|
impl<'a> Default for Docx<'a> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let content_type = ContentTypes::new();
|
let content_type = ContentTypes::new();
|
||||||
let rels = Rels::new();
|
let rels = Rels::new();
|
||||||
|
@ -58,17 +58,17 @@ impl Default for Docx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docx {
|
impl<'a> Docx<'a> {
|
||||||
pub fn new() -> Docx {
|
pub fn new() -> Docx<'a> {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_paragraph(mut self, p: Paragraph) -> Docx {
|
pub fn add_paragraph(mut self, p: Paragraph) -> Docx<'a> {
|
||||||
self.document = self.document.add_paragraph(p);
|
self.document = self.document.add_paragraph(p);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_table(mut self, t: Table) -> Docx {
|
pub fn add_table(mut self, t: Table) -> Docx<'a> {
|
||||||
self.document = self.document.add_table(t);
|
self.document = self.document.add_table(t);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Docx(docx_core::Docx);
|
pub struct Docx(docx_core::Docx<'static>);
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
Loading…
Reference in New Issue