-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,607 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use crate::documents::{BuildXML, LevelJc, LevelText, NumberFormat, ParagraphProperty, Start}; | ||
use crate::types::*; | ||
use crate::xml_builder::*; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Level<'a> { | ||
level: usize, | ||
start: Start, | ||
format: NumberFormat<'a>, | ||
text: LevelText<'a>, | ||
jc: LevelJc<'a>, | ||
paragraph_property: ParagraphProperty, | ||
} | ||
|
||
impl<'a> Level<'a> { | ||
pub fn new( | ||
level: usize, | ||
start: Start, | ||
format: NumberFormat<'a>, | ||
text: LevelText<'a>, | ||
jc: LevelJc<'a>, | ||
) -> Level<'a> { | ||
Self { | ||
level, | ||
start, | ||
format, | ||
text, | ||
jc, | ||
paragraph_property: ParagraphProperty::new(), | ||
} | ||
} | ||
|
||
pub fn indent(mut self, left: usize, special_indent: Option<SpecialIndentType>) -> Self { | ||
self.paragraph_property = self.paragraph_property.indent(left, special_indent); | ||
self | ||
} | ||
} | ||
|
||
impl<'a> BuildXML for Level<'a> { | ||
fn build(&self) -> Vec<u8> { | ||
XMLBuilder::new() | ||
.open_level(&format!("{}", self.level)) | ||
.add_child(&self.start) | ||
.add_child(&self.format) | ||
.add_child(&self.text) | ||
.add_child(&self.jc) | ||
.add_child(&self.paragraph_property) | ||
.close() | ||
.build() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
#[cfg(test)] | ||
use pretty_assertions::assert_eq; | ||
use std::str; | ||
|
||
#[test] | ||
fn test_level() { | ||
let b = Level::new( | ||
1, | ||
Start::new(1), | ||
NumberFormat::new("decimal"), | ||
LevelText::new("%4."), | ||
LevelJc::new("left"), | ||
) | ||
.build(); | ||
assert_eq!( | ||
str::from_utf8(&b).unwrap(), | ||
r#"<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:pStyle w:val="Normal" /><w:rPr /></w:pPr></w:lvl>"# | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_level_indent() { | ||
let b = Level::new( | ||
1, | ||
Start::new(1), | ||
NumberFormat::new("decimal"), | ||
LevelText::new("%4."), | ||
LevelJc::new("left"), | ||
) | ||
.indent(320, Some(SpecialIndentType::Hanging(200))) | ||
.build(); | ||
assert_eq!( | ||
str::from_utf8(&b).unwrap(), | ||
r#"<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:pStyle w:val="Normal" /><w:rPr /><w:ind w:left="320" w:hanging="200" /></w:pPr></w:lvl>"# | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::documents::BuildXML; | ||
use crate::xml_builder::*; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct LevelJc<'a> { | ||
val: &'a str, | ||
} | ||
|
||
impl<'a> LevelJc<'a> { | ||
pub fn new(val: &'a str) -> Self { | ||
Self { val } | ||
} | ||
} | ||
|
||
impl<'a> BuildXML for LevelJc<'a> { | ||
fn build(&self) -> Vec<u8> { | ||
let b = XMLBuilder::new(); | ||
b.level_justification(self.val).build() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
#[cfg(test)] | ||
use pretty_assertions::assert_eq; | ||
use std::str; | ||
|
||
#[test] | ||
fn test_level_jc() { | ||
let c = LevelJc::new("left"); | ||
let b = c.build(); | ||
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:lvlJc w:val="left" />"#); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::documents::BuildXML; | ||
use crate::xml_builder::*; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct LevelText<'a> { | ||
val: &'a str, | ||
} | ||
|
||
impl<'a> LevelText<'a> { | ||
pub fn new(val: &'a str) -> Self { | ||
Self { val } | ||
} | ||
} | ||
|
||
impl<'a> BuildXML for LevelText<'a> { | ||
fn build(&self) -> Vec<u8> { | ||
let b = XMLBuilder::new(); | ||
b.level_text(self.val).build() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
#[cfg(test)] | ||
use pretty_assertions::assert_eq; | ||
use std::str; | ||
|
||
#[test] | ||
fn test_level_text() { | ||
let c = LevelText::new("%4."); | ||
let b = c.build(); | ||
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:lvlText w:val="%4." />"#); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::documents::BuildXML; | ||
use crate::xml_builder::*; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct NumberFormat<'a> { | ||
val: &'a str, | ||
} | ||
|
||
impl<'a> NumberFormat<'a> { | ||
pub fn new(val: &'a str) -> Self { | ||
Self { val } | ||
} | ||
} | ||
|
||
impl<'a> BuildXML for NumberFormat<'a> { | ||
fn build(&self) -> Vec<u8> { | ||
let b = XMLBuilder::new(); | ||
b.number_format(self.val).build() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
#[cfg(test)] | ||
use pretty_assertions::assert_eq; | ||
use std::str; | ||
|
||
#[test] | ||
fn test_start() { | ||
let c = NumberFormat::new("decimal"); | ||
let b = c.build(); | ||
assert_eq!( | ||
str::from_utf8(&b).unwrap(), | ||
r#"<w:numFmt w:val="decimal" />"# | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::documents::{BuildXML, Level}; | ||
use crate::xml_builder::*; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Numbering<'a> { | ||
id: &'a str, | ||
levels: Vec<Level<'a>>, | ||
} | ||
|
||
impl<'a> Numbering<'a> { | ||
pub fn new(id: &'a str) -> Self { | ||
Self { id, levels: vec![] } | ||
} | ||
|
||
pub fn add_level(mut self, level: Level<'a>) -> Self { | ||
self.levels.push(level); | ||
self | ||
} | ||
} | ||
|
||
impl<'a> BuildXML for Numbering<'a> { | ||
fn build(&self) -> Vec<u8> { | ||
let mut b = XMLBuilder::new(); | ||
b = b.open_abstract_num(self.id); | ||
for l in &self.levels { | ||
b = b.add_child(l); | ||
} | ||
b.close() | ||
.open_num(self.id) | ||
.abstract_num_id(self.id) | ||
.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 = Numbering::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(), | ||
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:pStyle w:val="Normal" /><w:rPr /></w:pPr></w:lvl></w:abstractNum> | ||
<w:num w:numId="0"> | ||
<w:abstractNumId w:val="0" /> | ||
</w:num>"# | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::documents::BuildXML; | ||
use crate::xml_builder::*; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Start { | ||
val: usize, | ||
} | ||
|
||
impl Start { | ||
pub fn new(val: usize) -> Start { | ||
Start { val } | ||
} | ||
} | ||
|
||
impl BuildXML for Start { | ||
fn build(&self) -> Vec<u8> { | ||
let b = XMLBuilder::new(); | ||
b.start(self.val).build() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
#[cfg(test)] | ||
use pretty_assertions::assert_eq; | ||
use std::str; | ||
|
||
#[test] | ||
fn test_start() { | ||
let c = Start::new(1); | ||
let b = c.build(); | ||
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:start w:val="1" />"#); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.