2020-02-11 17:21:26 +02:00
|
|
|
use crate::documents::{BuildXML, Level};
|
|
|
|
use crate::xml_builder::*;
|
|
|
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct AbstractNumbering {
|
|
|
|
id: usize,
|
2020-02-26 13:26:32 +02:00
|
|
|
style_link: Option<String>,
|
|
|
|
num_style_link: Option<String>,
|
2020-02-11 17:21:26 +02:00
|
|
|
levels: Vec<Level>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AbstractNumbering {
|
|
|
|
pub fn new(id: usize) -> Self {
|
2020-02-26 13:26:32 +02:00
|
|
|
Self {
|
|
|
|
id,
|
|
|
|
style_link: None,
|
|
|
|
num_style_link: None,
|
|
|
|
levels: vec![],
|
|
|
|
}
|
2020-02-11 17:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_level(mut self, level: Level) -> Self {
|
|
|
|
self.levels.push(level);
|
|
|
|
self
|
|
|
|
}
|
2020-02-26 13:26:32 +02:00
|
|
|
|
|
|
|
pub fn num_style_link(mut self, link: impl Into<String>) -> Self {
|
|
|
|
self.num_style_link = Some(link.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn style_link(mut self, link: impl Into<String>) -> Self {
|
|
|
|
self.style_link = Some(link.into());
|
|
|
|
self
|
|
|
|
}
|
2020-02-11 17:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl BuildXML for AbstractNumbering {
|
|
|
|
fn build(&self) -> Vec<u8> {
|
|
|
|
let id = format!("{}", self.id);
|
|
|
|
let mut b = XMLBuilder::new();
|
|
|
|
b = b.open_abstract_num(&id);
|
|
|
|
for l in &self.levels {
|
|
|
|
b = b.add_child(l);
|
|
|
|
}
|
|
|
|
b.close().build()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
#[cfg(test)]
|
|
|
|
use crate::documents::{Level, LevelJc, LevelText, NumberFormat, Start};
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_numbering() {
|
|
|
|
let mut c = AbstractNumbering::new(0);
|
|
|
|
c = c.add_level(Level::new(
|
|
|
|
1,
|
|
|
|
Start::new(1),
|
|
|
|
NumberFormat::new("decimal"),
|
|
|
|
LevelText::new("%4."),
|
|
|
|
LevelJc::new("left"),
|
|
|
|
));
|
|
|
|
let b = c.build();
|
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&b).unwrap(),
|
2020-12-14 04:42:07 +02:00
|
|
|
r#"<w:abstractNum w:abstractNumId="0"><w:lvl w:ilvl="1"><w:start w:val="1" /><w:numFmt w:val="decimal" /><w:lvlText w:val="%4." /><w:lvlJc w:val="left" /><w:pPr><w:rPr /></w:pPr><w:rPr /></w:lvl></w:abstractNum>"#
|
2020-02-11 17:21:26 +02:00
|
|
|
);
|
|
|
|
}
|
2020-02-26 13:26:32 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_numbering_json() {
|
|
|
|
let mut c = AbstractNumbering::new(0);
|
|
|
|
c = c
|
|
|
|
.add_level(Level::new(
|
|
|
|
1,
|
|
|
|
Start::new(1),
|
|
|
|
NumberFormat::new("decimal"),
|
|
|
|
LevelText::new("%4."),
|
|
|
|
LevelJc::new("left"),
|
|
|
|
))
|
|
|
|
.num_style_link("style1");
|
|
|
|
assert_eq!(
|
|
|
|
serde_json::to_string(&c).unwrap(),
|
2021-06-07 13:30:05 +03:00
|
|
|
r#"{"id":0,"styleLink":null,"numStyleLink":"style1","levels":[{"level":1,"start":1,"format":"decimal","text":"%4.","jc":"left","paragraphProperty":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"suffix":"tab","pstyle":null,"levelRestart":null}]}"#,
|
2020-02-26 13:26:32 +02:00
|
|
|
);
|
|
|
|
}
|
2020-02-11 17:21:26 +02:00
|
|
|
}
|